MessageHandler.c 796 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char :4; //bit 4~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. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  444. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  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(uint8_t gun_index)
  679. {
  680. int result = -1;
  681. static time_t lastTime[4];
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime[gun_index])>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[gun_index] = 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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEV")==NULL) && (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "SuspendedEVSE")==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, "org.openchargealliance.costmsg");
  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. }
  2642. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2643. {
  2644. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2645. if((access(filenmae,F_OK))!=-1)
  2646. {
  2647. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2648. sprintf(str,"rm -f %s",filenmae);
  2649. system(str);
  2650. }
  2651. }
  2652. #if 1 // for TempStopTransaction
  2653. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2654. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2655. {
  2656. checkTempStopTransaction(gun_index);
  2657. }
  2658. #endif
  2659. }
  2660. }
  2661. }
  2662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2663. {
  2664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2665. {
  2666. tempIndex = ((gun_index==2) ? 1: 0);
  2667. }
  2668. else
  2669. {
  2670. tempIndex = gun_index;
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2675. {
  2676. 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]*/ )
  2677. {
  2678. // Sent unplug message for California pricing logic
  2679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2680. {
  2681. uint8_t ts[20];
  2682. getNowDatetime(ts);
  2683. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2686. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2687. }
  2688. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2689. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2690. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2691. }
  2692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2693. {
  2694. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2695. if((access(filenmae,F_OK))!=-1)
  2696. {
  2697. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2698. sprintf(str,"rm -f %s",filenmae);
  2699. system(str);
  2700. }
  2701. }
  2702. #if 1 // for TempStopTransaction
  2703. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2704. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2705. {
  2706. checkTempStopTransaction(gun_index);
  2707. }
  2708. #endif
  2709. }
  2710. }
  2711. }
  2712. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2713. {
  2714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2715. {
  2716. tempIndex = ((gun_index==2) ? 1: 0);
  2717. }
  2718. else
  2719. {
  2720. tempIndex = gun_index;
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2725. {
  2726. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2727. {
  2728. // Sent unplug message for California pricing logic
  2729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2730. {
  2731. uint8_t ts[20];
  2732. getNowDatetime(ts);
  2733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2734. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2736. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2737. }
  2738. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2739. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2740. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2741. }
  2742. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2743. {
  2744. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2745. if((access(filenmae,F_OK))!=-1)
  2746. {
  2747. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2748. sprintf(str,"rm -f %s",filenmae);
  2749. system(str);
  2750. }
  2751. }
  2752. #if 1 // for TempStopTransaction
  2753. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2754. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2755. {
  2756. checkTempStopTransaction(gun_index);
  2757. }
  2758. #endif
  2759. }
  2760. }
  2761. }
  2762. else if(gunType[gun_index] == GUN_TYPE_DO)
  2763. {
  2764. tempIndex = gun_index;
  2765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2766. {
  2767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2768. {
  2769. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2770. {
  2771. // Sent unplug message for California pricing logic
  2772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2773. {
  2774. uint8_t ts[20];
  2775. getNowDatetime(ts);
  2776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2777. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2779. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2780. }
  2781. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2782. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2784. }
  2785. 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
  2786. {
  2787. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2788. if((access(filenmae,F_OK))!=-1)
  2789. {
  2790. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2791. sprintf(str,"rm -f %s",filenmae);
  2792. system(str);
  2793. }
  2794. }
  2795. #if 1 // for TempStopTransaction
  2796. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2797. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2798. {
  2799. checkTempStopTransaction(gun_index);
  2800. }
  2801. #endif
  2802. }
  2803. }
  2804. }
  2805. else
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2808. {
  2809. tempIndex = 2;
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < AC_QUANTITY; index++)
  2816. {
  2817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2818. {
  2819. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2820. {
  2821. // Sent unplug message for California pricing logic
  2822. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2823. {
  2824. uint8_t ts[20];
  2825. getNowDatetime(ts);
  2826. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2827. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2828. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2829. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2830. }
  2831. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2832. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2834. }
  2835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2836. {
  2837. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2838. if((access(filenmae,F_OK))!=-1)
  2839. {
  2840. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2841. sprintf(str,"rm -f %s",filenmae);
  2842. system(str);
  2843. }
  2844. }
  2845. #if 1 // for TempStopTransaction
  2846. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2847. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2848. {
  2849. checkTempStopTransaction(gun_index);
  2850. }
  2851. #endif
  2852. }
  2853. }// END
  2854. }
  2855. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2856. (
  2857. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2858. )
  2859. )
  2860. {
  2861. if(SystemInitial > 0)
  2862. SystemInitial -= 1;
  2863. sendStatusNotificationRequest(gun_index);
  2864. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2865. }
  2866. //==============================================
  2867. // Meter report
  2868. //==============================================
  2869. // Trigger MeterValue
  2870. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2871. {
  2872. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2873. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2874. }
  2875. // ClockAlign MeterValue
  2876. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2877. {
  2878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2879. {
  2880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2881. {
  2882. tempIndex = ((gun_index==2) ? 1: 0);
  2883. }
  2884. else
  2885. {
  2886. tempIndex = gun_index;
  2887. }
  2888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2889. {
  2890. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2891. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2892. {
  2893. reqClockAlignMeter[gun_index] = 1;
  2894. }
  2895. }// End for CHAdeMO
  2896. }
  2897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2898. {
  2899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2900. {
  2901. tempIndex = ((gun_index==2) ? 1: 0);
  2902. }
  2903. else
  2904. {
  2905. tempIndex = gun_index;
  2906. }
  2907. for (int index = 0; index < CCS_QUANTITY; index++)
  2908. {
  2909. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2910. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2911. {
  2912. reqClockAlignMeter[gun_index] = 1;
  2913. }
  2914. } // End for CCS
  2915. }
  2916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2917. {
  2918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2919. {
  2920. tempIndex = ((gun_index==2) ? 1: 0);
  2921. }
  2922. else
  2923. {
  2924. tempIndex = gun_index;
  2925. }
  2926. for (int index = 0; index < GB_QUANTITY; index++)
  2927. {
  2928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2930. {
  2931. reqClockAlignMeter[gun_index] = 1;
  2932. }
  2933. }// End for GB
  2934. }
  2935. else if(gunType[gun_index] == GUN_TYPE_DO)
  2936. {
  2937. tempIndex = gun_index;
  2938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2939. {
  2940. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2941. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2942. {
  2943. reqClockAlignMeter[gun_index] = 1;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2950. {
  2951. tempIndex = 2;
  2952. }
  2953. else
  2954. {
  2955. tempIndex = gun_index;
  2956. }
  2957. for (int index = 0; index < AC_QUANTITY; index++)
  2958. {
  2959. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2960. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2961. {
  2962. reqClockAlignMeter[gun_index] = 1;
  2963. }
  2964. }//End for AC
  2965. }
  2966. if(reqClockAlignMeter[gun_index] == 1)
  2967. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2968. }
  2969. // Sample period MeterValue
  2970. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  2971. {
  2972. //check Transaction active
  2973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2974. {
  2975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2976. {
  2977. tempIndex = ((gun_index==2) ? 1: 0);
  2978. }
  2979. else
  2980. {
  2981. tempIndex = gun_index;
  2982. }
  2983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2984. {
  2985. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2986. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2987. {
  2988. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2989. {
  2990. reqSampleMeter[gun_index] = 1;
  2991. }
  2992. }
  2993. }// End for CHAdeMO
  2994. }
  2995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2996. {
  2997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2998. {
  2999. tempIndex = ((gun_index==2) ? 1: 0);
  3000. }
  3001. else
  3002. {
  3003. tempIndex = gun_index;
  3004. }
  3005. for (int index = 0; index < CCS_QUANTITY; index++)
  3006. {
  3007. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3008. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3009. {
  3010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3011. {
  3012. reqSampleMeter[gun_index] = 1;
  3013. }
  3014. }
  3015. } // End for CCS
  3016. }
  3017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3018. {
  3019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3020. {
  3021. tempIndex = ((gun_index==2) ? 1: 0);
  3022. }
  3023. else
  3024. {
  3025. tempIndex = gun_index;
  3026. }
  3027. for (int index = 0; index < GB_QUANTITY; index++)
  3028. {
  3029. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3030. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3033. {
  3034. reqSampleMeter[gun_index] = 1;
  3035. }
  3036. }
  3037. }// End for GB
  3038. }
  3039. else if(gunType[gun_index] == GUN_TYPE_DO)
  3040. {
  3041. tempIndex = gun_index;
  3042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3043. {
  3044. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3045. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3046. {
  3047. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3048. {
  3049. reqSampleMeter[gun_index] = 1;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. else
  3055. {
  3056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3057. {
  3058. tempIndex = 2;
  3059. }
  3060. else
  3061. {
  3062. tempIndex = gun_index;
  3063. }
  3064. for (int index = 0; index < AC_QUANTITY; index++)
  3065. {
  3066. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3067. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3068. {
  3069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3070. {
  3071. reqSampleMeter[gun_index] = 1;
  3072. }
  3073. }
  3074. }//End for AC
  3075. }
  3076. if(reqSampleMeter[gun_index] == 1)
  3077. {
  3078. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3079. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3080. storeTempStopTransaction(gun_index);
  3081. }
  3082. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3083. }
  3084. //==============================================
  3085. // Check Connector reserved
  3086. //==============================================
  3087. //===============================
  3088. // Check if Reserve is expired
  3089. //===============================
  3090. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3091. {
  3092. double diff_t;
  3093. struct tm tp;
  3094. // current time
  3095. time_t t = time(NULL);
  3096. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3097. tp.tm_isdst = -1;
  3098. time_t utc = mktime(&tp);
  3099. diff_t = difftime(utc, t);
  3100. if(diff_t <= 0)
  3101. {
  3102. DEBUG_INFO("reserve expired.\n");
  3103. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3104. }
  3105. }//END OF Check if Reserve is expired
  3106. //==========================================
  3107. // csu trigger FirmwareStatusNotificationReq
  3108. //==========================================
  3109. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3110. {
  3111. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3112. }
  3113. //==========================================
  3114. // csu trigger DiagnosticsStatusNotificationReq
  3115. //==========================================
  3116. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3117. {
  3118. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3119. }
  3120. //==========================================
  3121. // csu trigger CancelReservationConf
  3122. //==========================================
  3123. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3124. {
  3125. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3126. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3127. }
  3128. //==========================================
  3129. // csu trigger ChangeAvailabilityConf
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3132. {
  3133. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3134. }
  3135. //==========================================
  3136. // csu trigger UnlockConnectorConf
  3137. //==========================================
  3138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3139. {
  3140. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3141. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3142. }
  3143. //==========================================
  3144. // csu trigger ReserveNowConf
  3145. //==========================================
  3146. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3147. {
  3148. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3149. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3150. }
  3151. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3152. {
  3153. sendSignCertificateRequest();
  3154. }
  3155. }
  3156. }
  3157. //==========================================
  3158. // send request routine
  3159. //==========================================
  3160. int sendAuthorizeRequest(int gun_index)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[100]={0};
  3165. char guid[37];
  3166. char tempdata[65]={0};
  3167. DEBUG_INFO("sendAuthorizeRequest...\n");
  3168. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3169. //Local Authorize
  3170. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3171. {
  3172. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3173. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3174. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3175. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3176. result = PASS;
  3177. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3178. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3179. authorizeRetryTimes = 0;
  3180. return result;
  3181. }
  3182. 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))||
  3183. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3184. {
  3185. // Query from cache
  3186. DEBUG_INFO("Authorize from cache.\n");
  3187. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3188. // Query from list
  3189. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3190. {
  3191. DEBUG_INFO("Authorize from list.\n");
  3192. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3193. }
  3194. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3195. {
  3196. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3197. {
  3198. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3199. }
  3200. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3201. {
  3202. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3203. }
  3204. if(!GetOcppConnStatus())
  3205. {
  3206. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3207. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3208. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3209. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3210. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3211. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3212. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3213. authorizeRetryTimes = 0;
  3214. return result;
  3215. }
  3216. }
  3217. else
  3218. {
  3219. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3220. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3221. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3222. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3223. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3224. else
  3225. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3226. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3227. result = PASS;
  3228. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3229. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3230. authorizeRetryTimes = 0;
  3231. return result;
  3232. }
  3233. }
  3234. //initialize struct Authorize
  3235. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3236. //get data from shared memory
  3237. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3238. random_uuid(guid);
  3239. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3240. LWS_Send(message);
  3241. sprintf(tempdata, "Authorize,%d", gun_index);
  3242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3243. {
  3244. result = PASS;
  3245. DEBUG_INFO("Authorize mapItem pass\n");
  3246. }
  3247. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3248. return result;
  3249. }
  3250. int sendBootNotificationRequest(void)
  3251. {
  3252. mtrace();
  3253. int result = FAIL;
  3254. char message[500]={0}, payload[700]={0};
  3255. char guid[37]={0};
  3256. char tempdata[65]={0};
  3257. // Fill BootNotification fields
  3258. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3259. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3260. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3261. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3262. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3263. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3264. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3265. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3266. ShmOCPP16Data->ChargeBoxId
  3267. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3268. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3269. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3270. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3271. ,ShmOCPP16Data->BootNotification.CpIccid
  3272. ,ShmOCPP16Data->BootNotification.CpImsi);
  3273. random_uuid(guid);
  3274. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3275. LWS_Send(message);
  3276. sprintf(tempdata, "BootNotification,0");
  3277. 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*/)
  3278. {
  3279. result = PASS;
  3280. }
  3281. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3282. strcpy(queuedata,message);
  3283. return result;
  3284. }
  3285. int sendDataTransferRequest(int gun_index)
  3286. {
  3287. mtrace();
  3288. char message[1000]={0};
  3289. char guid[37]={0};
  3290. char tempdata[65]={0};
  3291. int result = FAIL;
  3292. random_uuid(guid);
  3293. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3294. MESSAGE_TYPE_CALL,
  3295. guid,
  3296. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3297. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3298. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3299. LWS_Send(message);
  3300. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3301. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3302. {
  3303. result = PASS;
  3304. DEBUG_INFO("DataTransfer mapItem pass\n");
  3305. }
  3306. return result;
  3307. }
  3308. int sendDiagnosticsStatusNotificationRequest(char *status)
  3309. {
  3310. mtrace();
  3311. int result = FAIL;
  3312. char message[110]={0};
  3313. char guid[37]={0};
  3314. char tempdata[65]={0};
  3315. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3316. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3317. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3318. random_uuid(guid);
  3319. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3320. LWS_SendNow(message);
  3321. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3322. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3323. {
  3324. result = PASS;
  3325. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3326. }
  3327. //#ifdef SystemLogMessage
  3328. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3329. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3330. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3331. //#endif
  3332. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3333. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3334. //record status
  3335. if(strcmp(status,"Idle")==0)
  3336. {
  3337. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3338. }
  3339. else if(strcmp(status,"Uploaded")==0)
  3340. {
  3341. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3342. }
  3343. else if(strcmp(status,"UploadFailed")==0)
  3344. {
  3345. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3346. }
  3347. else if(strcmp(status,"Uploading")==0)
  3348. {
  3349. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3350. }
  3351. return result;
  3352. }
  3353. int sendFirmwareStatusNotificationRequest(char *status)
  3354. {
  3355. mtrace();
  3356. int result = FAIL;
  3357. char message[110]={0};
  3358. char guid[37]={0};
  3359. char tempdata[65]={0};
  3360. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3361. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3362. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3363. random_uuid(guid);
  3364. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3365. LWS_SendNow(message);
  3366. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3367. 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*/)
  3368. {
  3369. result = PASS;
  3370. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3371. }
  3372. //#ifdef SystemLogMessage
  3373. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3374. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3375. //#endif
  3376. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3377. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3378. //record status
  3379. if(strcmp(status,"Downloaded")==0)
  3380. {
  3381. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3382. }
  3383. else if(strcmp(status,"DownloadFailed")==0)
  3384. {
  3385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3386. }
  3387. else if(strcmp(status,"Downloading")==0)
  3388. {
  3389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3390. }
  3391. else if(strcmp(status,"Idle")==0)
  3392. {
  3393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3394. }
  3395. else if(strcmp(status,"InstallationFailed")==0)
  3396. {
  3397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3398. }
  3399. else if(strcmp(status,"Installing")==0)
  3400. {
  3401. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3402. }
  3403. else if(strcmp(status,"Installed")==0)
  3404. {
  3405. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3406. }
  3407. return result;
  3408. }
  3409. int sendHeartbeatRequest(int gun_index)
  3410. {
  3411. mtrace();
  3412. int result = FAIL;
  3413. char message[80]={0};
  3414. char guid[37]={0};
  3415. char tempdata[65]={0};
  3416. random_uuid(guid);
  3417. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3418. , MESSAGE_TYPE_CALL
  3419. , guid );
  3420. LWS_Send(message);
  3421. sprintf(tempdata, "Heartbeat,%d", 0);
  3422. 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*/)
  3423. {
  3424. result = PASS;
  3425. }
  3426. return result;
  3427. }
  3428. int sendStartTransactionRequest(int gun_index)
  3429. {
  3430. mtrace();
  3431. int result = FAIL;
  3432. char message[250]={0};
  3433. char guid[37]={0};
  3434. struct timeval tmnow;
  3435. struct tm *tm;
  3436. char buf[28];//, usec_buf[6];
  3437. char tempdata[65]={0};
  3438. int tempIndex = 0;
  3439. DEBUG_INFO("sendStartTransactionRequest...\n");
  3440. gettimeofday(&tmnow, NULL);
  3441. time_t t;
  3442. t = time(NULL);
  3443. /*UTC time and date*/
  3444. tm = gmtime(&t);
  3445. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3446. #if 0 // remove temporally
  3447. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3448. strcat(buf,".");
  3449. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3450. strcat(buf,usec_buf);
  3451. #endif
  3452. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3453. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3454. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3455. // clear StartTransaction Response
  3456. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3457. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3458. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3459. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3460. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3475. {
  3476. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3477. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3478. }
  3479. }
  3480. }
  3481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < CCS_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3494. {
  3495. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3496. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3497. }
  3498. }
  3499. }
  3500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3503. {
  3504. tempIndex = ((gun_index==2) ? 1: 0);
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < GB_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3513. {
  3514. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3515. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3516. }
  3517. }
  3518. }
  3519. else if(gunType[gun_index] == GUN_TYPE_DO)
  3520. {
  3521. tempIndex = gun_index;
  3522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3523. {
  3524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3525. {
  3526. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3527. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3528. }
  3529. }
  3530. }
  3531. else
  3532. {
  3533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3534. {
  3535. tempIndex = 2;
  3536. }
  3537. else
  3538. {
  3539. tempIndex = gun_index;
  3540. }
  3541. for (int index = 0; index < AC_QUANTITY; index++)
  3542. {
  3543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3544. {
  3545. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3546. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3547. }
  3548. }
  3549. }
  3550. random_uuid(guid);
  3551. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3552. {
  3553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3554. , gun_index +1
  3555. , MESSAGE_TYPE_CALL
  3556. , guid
  3557. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3558. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3559. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3560. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3561. }
  3562. else
  3563. {
  3564. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3565. , gun_index +1
  3566. , MESSAGE_TYPE_CALL
  3567. , guid
  3568. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3569. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3570. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3571. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3572. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3573. }
  3574. #if 1
  3575. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3576. 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*/)
  3577. {
  3578. result = PASS;
  3579. }
  3580. #endif
  3581. strcpy(queuedata, message);
  3582. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3583. OCPP_insert_transaction_msg(YES, queuedata);
  3584. return result;
  3585. }
  3586. int sendStatusNotificationRequest(int gun_index)
  3587. {
  3588. mtrace();
  3589. int result = FAIL;
  3590. char message[600]={0};
  3591. char guid[37];
  3592. int currentStatus = 0;
  3593. struct timeval tmnow;
  3594. struct tm *tm;
  3595. char buf[28];//, usec_buf[6];
  3596. char tempdata[65]={0};
  3597. int tempIndex = 0;
  3598. uint8_t isStateChanged = TRUE;
  3599. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3600. gettimeofday(&tmnow, NULL);
  3601. time_t t;
  3602. t = time(NULL);
  3603. /*UTC time and date*/
  3604. tm = gmtime(&t);
  3605. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3606. #if 0 // remove temporally
  3607. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3608. strcat(buf,".");
  3609. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3610. strcat(buf,usec_buf);
  3611. #endif
  3612. printf("%s",buf);
  3613. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3614. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3615. // it's option
  3616. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3617. /*
  3618. enum _SYSTEM_STATUS
  3619. {
  3620. S_BOOTING = 0,
  3621. S_IDLE, = 1
  3622. S_AUTHORIZING, =2
  3623. S_REASSIGN_CHECK, =3
  3624. S_REASSIGN, =4
  3625. S_PRECHARGE, =5
  3626. S_PREPARING_FOR_EV, =6
  3627. S_PREPARING_FOR_EVSE, =7
  3628. S_CHARGING, =8
  3629. S_TERMINATING, =9
  3630. S_COMPLETE, =10
  3631. S_ALARM, =11
  3632. S_FAULT =12
  3633. }
  3634. */
  3635. //check Transaction active
  3636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3638. {
  3639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3640. {
  3641. tempIndex = ((gun_index==2) ? 1: 0);
  3642. }
  3643. else
  3644. {
  3645. tempIndex = gun_index;
  3646. }
  3647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3648. {
  3649. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3650. {
  3651. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3652. {
  3653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3654. {
  3655. currentStatus = Preparing; //OCPP Status: Preparing
  3656. }
  3657. else
  3658. {
  3659. currentStatus = Available; //OCPP Status: Available
  3660. }
  3661. }
  3662. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3663. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3664. ) //S_PRECHARGE
  3665. {
  3666. currentStatus = Preparing; //OCPP Status: Preparing
  3667. }
  3668. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3669. {
  3670. currentStatus = Charging; //OCPP Status: Charging
  3671. }
  3672. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3673. {
  3674. currentStatus = Finishing; //OCPP Status: Finishing
  3675. }
  3676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3677. {
  3678. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3679. }
  3680. 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
  3681. {
  3682. currentStatus = Unavailable; //OCPP Status: Unavailable
  3683. }
  3684. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3685. {
  3686. currentStatus = Faulted; //OCPP Status: Faulted
  3687. }
  3688. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3689. {
  3690. currentStatus = Reserved; //OCPP Status: Reserved
  3691. }
  3692. } //end of the same index
  3693. }//end of for CHAdeMO_QUANTITY
  3694. }
  3695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. for (int index = 0; index < CCS_QUANTITY; index++)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3710. {
  3711. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3712. {
  3713. currentStatus = Preparing; //OCPP Status: Preparing
  3714. }
  3715. else
  3716. {
  3717. currentStatus = Available; //OCPP Status: Available
  3718. }
  3719. }
  3720. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3721. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3722. ) //S_PRECHARGE
  3723. {
  3724. currentStatus = Preparing; //OCPP Status: Preparing
  3725. }
  3726. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3727. {
  3728. currentStatus = Charging; //OCPP Status: Charging
  3729. }
  3730. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3731. {
  3732. currentStatus = Finishing; //OCPP Status: Finishing
  3733. }
  3734. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3735. {
  3736. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3737. }
  3738. 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
  3739. {
  3740. currentStatus = Unavailable; //OCPP Status : Unavailable
  3741. }
  3742. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3743. {
  3744. currentStatus = Faulted; //OCPP Status: Faulted
  3745. }
  3746. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3747. {
  3748. currentStatus = Reserved; //OCPP Status: Reserved
  3749. }
  3750. } //end of the same index
  3751. } // end of for CCS_QUANTITY
  3752. }
  3753. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3756. {
  3757. tempIndex = ((gun_index==2) ? 1: 0);
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < GB_QUANTITY; index++)
  3764. {
  3765. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3766. {
  3767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3768. {
  3769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3770. {
  3771. currentStatus = Preparing; //OCPP Status: Preparing
  3772. }
  3773. else
  3774. {
  3775. currentStatus = Available; //OCPP Status: Available
  3776. }
  3777. }
  3778. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3779. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3780. ) //S_PRECHARGE
  3781. {
  3782. currentStatus = Preparing; //OCPP Status: Preparing
  3783. }
  3784. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3785. {
  3786. currentStatus = Charging; //OCPP Status: Charging
  3787. }
  3788. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3789. {
  3790. currentStatus = Finishing; //OCPP Status: Finishing
  3791. }
  3792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3793. {
  3794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3795. }
  3796. 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
  3797. {
  3798. currentStatus = Unavailable; //OCPP Status: Unavailable
  3799. }
  3800. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3801. {
  3802. currentStatus = Faulted; //OCPP Status: Faulted
  3803. }
  3804. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3805. {
  3806. currentStatus = Reserved; //OCPP Status: Reserved
  3807. }
  3808. } //end of the same index
  3809. } // end of for GB_QUANTITY
  3810. }
  3811. else if(gunType[gun_index] == GUN_TYPE_DO)
  3812. {
  3813. tempIndex = gun_index;
  3814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3815. {
  3816. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3817. {
  3818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3819. {
  3820. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3821. {
  3822. currentStatus = Preparing; //OCPP Status: Preparing
  3823. }
  3824. else
  3825. {
  3826. currentStatus = Available; //OCPP Status: Available
  3827. }
  3828. }
  3829. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3830. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3831. ) //S_PRECHARGE
  3832. {
  3833. currentStatus = Preparing; //OCPP Status: Preparing
  3834. }
  3835. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3836. {
  3837. currentStatus = Charging; //OCPP Status: Charging
  3838. }
  3839. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3840. {
  3841. currentStatus = Finishing; //OCPP Status: Finishing
  3842. }
  3843. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3844. {
  3845. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3846. }
  3847. 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
  3848. {
  3849. currentStatus = Unavailable; //OCPP Status: Unavailable
  3850. }
  3851. 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
  3852. {
  3853. currentStatus = Faulted; //OCPP Status: Faulted
  3854. }
  3855. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3856. {
  3857. currentStatus = Reserved; //OCPP Status: Reserved
  3858. }
  3859. } //end of the same index
  3860. }
  3861. }
  3862. else
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3865. {
  3866. tempIndex = 2;
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < AC_QUANTITY; index++)
  3873. {
  3874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3875. {
  3876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3877. {
  3878. 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))
  3879. {
  3880. currentStatus = Preparing; //OCPP Status: Preparing
  3881. }
  3882. else
  3883. {
  3884. currentStatus = Available; //OCPP Status: Available
  3885. }
  3886. }
  3887. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3888. {
  3889. currentStatus = Preparing; //OCPP Status: Preparing
  3890. }
  3891. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3892. {
  3893. currentStatus = Charging; //OCPP Status: Charging
  3894. }
  3895. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3896. {
  3897. currentStatus = Finishing; //OCPP Status: Finishing
  3898. }
  3899. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3900. {
  3901. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3902. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3903. else
  3904. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3905. }
  3906. 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
  3907. {
  3908. currentStatus = Unavailable; //OCPP Status: Unavailable
  3909. }
  3910. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3911. {
  3912. currentStatus = Faulted; //OCPP Status: Faulted
  3913. }
  3914. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3915. {
  3916. currentStatus = Reserved; //OCPP Status: Reserved
  3917. }
  3918. }//end of the same index
  3919. }//end of for AC_QUANTITY
  3920. }
  3921. //it's option
  3922. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3923. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3924. {
  3925. isStateChanged = FALSE;
  3926. }
  3927. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3928. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3929. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3930. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3931. random_uuid(guid);
  3932. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3933. , MESSAGE_TYPE_CALL
  3934. , guid
  3935. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3936. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3937. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3938. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3939. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3940. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3941. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3942. if((server_sign == TRUE) && isStateChanged)
  3943. {
  3944. LWS_Send(message);
  3945. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3946. 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*/)
  3947. {
  3948. //DEBUG_ERROR("statusNotification mapitem pass");
  3949. result = PASS;
  3950. }
  3951. }
  3952. else
  3953. {
  3954. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3955. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3956. result = PASS;
  3957. }
  3958. return result;
  3959. }
  3960. int sendStopTransactionRequest(int gun_index)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. //char message[1500]={0};
  3965. char guid[37]={0};
  3966. char tempdata[65]={0};
  3967. int tempIndex = 0;
  3968. char TempStopTransaction[256];
  3969. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3970. //int idx_sample=0;
  3971. DEBUG_INFO("sendStopTransactionRequest \n");
  3972. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3973. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3974. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3975. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3976. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3987. {
  3988. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3989. {
  3990. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3991. }
  3992. }// END OF CHAdeMO_QUANTITY
  3993. }
  3994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CCS_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4007. {
  4008. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4009. }
  4010. }// END OF CCS_QUANTITY
  4011. }
  4012. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < GB_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4025. {
  4026. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4027. }
  4028. }// END OF GB_QUANTITY
  4029. }
  4030. else if(gunType[gun_index] == GUN_TYPE_DO)
  4031. {
  4032. tempIndex = gun_index;
  4033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4036. {
  4037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4038. }
  4039. }// END OF GB_QUANTITY
  4040. }
  4041. else
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4044. {
  4045. tempIndex = 2;
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < AC_QUANTITY; index++)
  4052. {
  4053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4054. {
  4055. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4056. }
  4057. }// END OF AC_QUANTITY
  4058. }
  4059. //====================================== Stop Transaction Time =====================================================
  4060. struct timeval tmnow;
  4061. struct tm *tm;
  4062. char buf[28];//, usec_buf[6];
  4063. gettimeofday(&tmnow, NULL);
  4064. time_t t;
  4065. t = time(NULL);
  4066. /*UTC time and date*/
  4067. tm = gmtime(&t);
  4068. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4070. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4071. random_uuid(guid);
  4072. /***********************************transactionData******************************************************/
  4073. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4075. //=================================
  4076. // Transaction_Begin
  4077. //=================================
  4078. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4079. {
  4080. //============================================ Energy.Active.Import.Interval ================================
  4081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4084. 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*/]);
  4085. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4086. 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))
  4087. {
  4088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4089. }
  4090. else
  4091. {
  4092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4093. }
  4094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4096. }
  4097. //=================================
  4098. // Transaction_End
  4099. //=================================
  4100. // ================================= Current.Import L1 ===============================================
  4101. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4102. {
  4103. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4104. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4119. }
  4120. }// End of for CHAdeMO_QUANTITY
  4121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CCS_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4138. }
  4139. }// End of for CCS_QUANTITY
  4140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < GB_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4157. }
  4158. }// End of for GB_QUANTITY
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_DO)
  4162. {
  4163. tempIndex = gun_index;
  4164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4165. {
  4166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4167. {
  4168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4169. }
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4172. }
  4173. else
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4176. {
  4177. tempIndex = 2;
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < AC_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4186. {
  4187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4188. }
  4189. }// End of for AC_QUANTITY
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4191. }
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4197. }
  4198. // ================================= Energy.Active.Import.Interval ==============================================
  4199. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4200. {
  4201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4205. {
  4206. tempIndex = ((gun_index==2) ? 1: 0);
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4217. }
  4218. }// END OF CHAdeMO_QUANTITY
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4220. }
  4221. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CCS_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4236. }
  4237. }// END OF CCS_QUANTITY
  4238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4239. }
  4240. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < GB_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4255. }
  4256. }// END OF GB_QUANTITY
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_DO)
  4260. {
  4261. tempIndex = gun_index;
  4262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4263. {
  4264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4265. {
  4266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4267. }
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4270. }
  4271. else
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4274. {
  4275. tempIndex = 2;
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < AC_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4284. {
  4285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4286. }
  4287. }// END OF AC_QUANTITY
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4289. }
  4290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4295. }
  4296. //=================================== Power.Active.Import ==================================================
  4297. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4298. {
  4299. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4300. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4315. }
  4316. } // End for CHAdeMO_QUANTITY
  4317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CCS_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4334. }
  4335. } // END for CCS_QUANTITY
  4336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < GB_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4353. }
  4354. }// END for GB_QUANTITY
  4355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_DO)
  4358. {
  4359. tempIndex = gun_index;
  4360. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4365. }
  4366. }
  4367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4368. }
  4369. else
  4370. {
  4371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4372. {
  4373. tempIndex = 2;
  4374. }
  4375. else
  4376. {
  4377. tempIndex = gun_index;
  4378. }
  4379. for (int index = 0; index < AC_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4384. }
  4385. } // END for AC_QUANTITY
  4386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4393. }
  4394. //============================ Voltage L1 ====================================
  4395. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4396. {
  4397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4398. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4399. {
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4401. {
  4402. tempIndex = ((gun_index==2) ? 1: 0);
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4409. {
  4410. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4411. {
  4412. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4413. }
  4414. } // END OF FOR CHAdeMO_QUANTITY
  4415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4416. }
  4417. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CCS_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4432. }
  4433. } // END OF FOR CCS_QUANTITY
  4434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < GB_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4451. }
  4452. } // END OF FOR GB_QUANTITY
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_DO)
  4456. {
  4457. tempIndex = gun_index;
  4458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4461. {
  4462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4463. }
  4464. }
  4465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4466. }
  4467. else
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4470. {
  4471. tempIndex = 2;
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < AC_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4480. {
  4481. 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
  4482. }
  4483. } // END OF FOR AC_QUANTITY
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4491. }
  4492. //====================== End SoC ================================
  4493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4494. {
  4495. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4496. 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))
  4497. {
  4498. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4499. {
  4500. tempIndex = ((gun_index==2) ? 1: 0);
  4501. }
  4502. else
  4503. {
  4504. tempIndex = gun_index;
  4505. }
  4506. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4507. {
  4508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4513. }
  4514. }
  4515. }
  4516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4517. {
  4518. for (int index = 0; index < CCS_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4521. {
  4522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4523. }
  4524. }
  4525. }
  4526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4527. {
  4528. for (int index = 0; index < GB_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4531. {
  4532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4533. }
  4534. }
  4535. }
  4536. else if(gunType[gun_index] == GUN_TYPE_DO)
  4537. {
  4538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4543. }
  4544. }
  4545. }
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4552. } // END FOR DC CASE
  4553. }
  4554. // ================================= Current.Import L2 ===============================================
  4555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4556. {
  4557. // AC 3 phse L2 current
  4558. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4573. }
  4574. }// End of for AC_QUANTITY
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4582. }
  4583. // ================================= Current.Import L3 ===============================================
  4584. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4585. {
  4586. // AC 3 phse L3 current
  4587. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4590. {
  4591. tempIndex = 2;
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < AC_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4600. {
  4601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4602. }
  4603. }// End of for AC_QUANTITY
  4604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4605. }
  4606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4611. }
  4612. //============================ Voltage L2 ====================================
  4613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4614. {
  4615. // AC 3 phse L2 voltage
  4616. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4617. {
  4618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4619. {
  4620. tempIndex = 2;
  4621. }
  4622. else
  4623. {
  4624. tempIndex = gun_index;
  4625. }
  4626. for (int index = 0; index < AC_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4629. {
  4630. 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
  4631. }
  4632. } // END OF FOR AC_QUANTITY
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4634. }
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4640. }
  4641. //============================ Voltage L3 ====================================
  4642. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4643. {
  4644. // AC 3 phse L3 voltage
  4645. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. 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
  4660. }
  4661. } // END OF FOR AC_QUANTITY
  4662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4669. }
  4670. //====================== Start SoC ================================
  4671. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4672. {
  4673. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4674. 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))
  4675. {
  4676. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4677. {
  4678. tempIndex = ((gun_index==2) ? 1: 0);
  4679. }
  4680. else
  4681. {
  4682. tempIndex = gun_index;
  4683. }
  4684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4685. {
  4686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4687. {
  4688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4689. {
  4690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4691. }
  4692. }
  4693. }
  4694. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4695. {
  4696. for (int index = 0; index < CCS_QUANTITY; index++)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4699. {
  4700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4701. }
  4702. }
  4703. }
  4704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4705. {
  4706. for (int index = 0; index < GB_QUANTITY; index++)
  4707. {
  4708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4709. {
  4710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4711. }
  4712. }
  4713. }
  4714. else if(gunType[gun_index] == GUN_TYPE_DO)
  4715. {
  4716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4717. {
  4718. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4719. {
  4720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4721. }
  4722. }
  4723. }
  4724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4730. } // END FOR DC CASE
  4731. }
  4732. //================================================ Message create ====================================================
  4733. json_object *StopTransaction = json_object_new_object();
  4734. json_object *transactionDatas = json_object_new_array();
  4735. json_object *sampledValues = json_object_new_array();
  4736. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4737. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4738. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4739. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4740. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4742. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4743. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4744. {
  4745. json_object *transactionData = json_object_new_object();
  4746. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4747. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4748. {
  4749. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4750. {
  4751. json_object *sampledValue = json_object_new_object();
  4752. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4753. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4754. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4755. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4756. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4758. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4759. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4760. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4761. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4762. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4763. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4764. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4765. json_object_array_add(sampledValues, sampledValue);
  4766. }
  4767. }
  4768. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4769. json_object_array_add(transactionDatas, transactionData);
  4770. }
  4771. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4772. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4773. ,MESSAGE_TYPE_CALL
  4774. ,guid
  4775. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4776. json_object_put(StopTransaction);
  4777. #if 1 // for TempStopTransaction
  4778. //Delete TempStopTransaction
  4779. if((access(TempStopTransaction,F_OK))!=-1)
  4780. {
  4781. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4782. }
  4783. #endif
  4784. #if 1
  4785. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4787. {
  4788. result = PASS;
  4789. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4790. }
  4791. #endif
  4792. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4793. OCPP_insert_transaction_msg(NO, queuedata);
  4794. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4795. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4796. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4797. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4798. {
  4799. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4800. }
  4801. //for test
  4802. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4803. return result;
  4804. }
  4805. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4806. {
  4807. mtrace();
  4808. int result = FAIL;
  4809. char guid[37]={0};
  4810. char tempdata[65]={0};
  4811. int tempIndex = 0;
  4812. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4813. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4814. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4815. //set value
  4816. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4817. 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) )?
  4818. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4819. -1);
  4820. random_uuid(guid);
  4821. //UTC Date time
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. gettimeofday(&tmnow, NULL);
  4826. time_t t;
  4827. t = time(NULL);
  4828. /*UTC time and date*/
  4829. tm = gmtime(&t);
  4830. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4832. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4833. //********************************(1)Current.Import L1************************************************/
  4834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4836. (dataType == ReadingContext_Trigger))
  4837. {
  4838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4842. {
  4843. tempIndex = ((gun_index==2) ? 1: 0);
  4844. }
  4845. else
  4846. {
  4847. tempIndex = gun_index;
  4848. }
  4849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4850. {
  4851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4852. {
  4853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4854. }
  4855. }
  4856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4857. }
  4858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < CCS_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < GB_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4890. {
  4891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4892. }
  4893. }
  4894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_DO)
  4897. {
  4898. tempIndex = gun_index;
  4899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4904. }
  4905. }
  4906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4907. }
  4908. else
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4911. {
  4912. tempIndex = 2;
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < AC_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4923. }
  4924. }
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4926. }
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4932. }
  4933. //********************************(2)Energy.Active.Import.Register ************************************************/
  4934. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4935. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4936. (dataType == ReadingContext_Trigger))
  4937. {
  4938. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4940. {
  4941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4942. {
  4943. tempIndex = ((gun_index==2) ? 1: 0);
  4944. }
  4945. else
  4946. {
  4947. tempIndex = gun_index;
  4948. }
  4949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4954. }
  4955. }
  4956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4957. }
  4958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4961. {
  4962. tempIndex = ((gun_index==2) ? 1: 0);
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < CCS_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4980. {
  4981. tempIndex = ((gun_index==2) ? 1: 0);
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < GB_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4995. }
  4996. else if(gunType[gun_index] == GUN_TYPE_DO)
  4997. {
  4998. tempIndex = gun_index;
  4999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5007. }
  5008. else
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5011. {
  5012. tempIndex = 2;
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < AC_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5023. }
  5024. }
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5026. }
  5027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5032. }
  5033. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5034. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5035. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5036. (dataType == ReadingContext_Trigger))
  5037. {
  5038. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5040. {
  5041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5042. {
  5043. tempIndex = ((gun_index==2) ? 1: 0);
  5044. }
  5045. else
  5046. {
  5047. tempIndex = gun_index;
  5048. }
  5049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5050. {
  5051. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5052. {
  5053. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5054. }
  5055. } // END OF FOR CHAdeMO_QUANTITY
  5056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5057. }
  5058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CCS_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5073. }
  5074. } // END OF CCS_QUANTITY
  5075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < GB_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5092. }
  5093. } // END OF GB_QUANTITY
  5094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_DO)
  5097. {
  5098. tempIndex = gun_index;
  5099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5100. {
  5101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5102. {
  5103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5104. }
  5105. }
  5106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5107. }
  5108. else
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5111. {
  5112. tempIndex = 2;
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < AC_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5123. }
  5124. }
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5132. }
  5133. //********************************(4)Power.Active.Import************************************************/
  5134. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5135. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5136. (dataType == ReadingContext_Trigger))
  5137. {
  5138. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5139. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5140. {
  5141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5142. {
  5143. tempIndex = ((gun_index==2) ? 1: 0);
  5144. }
  5145. else
  5146. {
  5147. tempIndex = gun_index;
  5148. }
  5149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5152. {
  5153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5154. }
  5155. } // END OF FOR
  5156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5157. }
  5158. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CCS_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5173. }
  5174. }
  5175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < GB_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5190. {
  5191. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5192. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5193. }
  5194. }
  5195. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5196. }
  5197. else if(gunType[gun_index] == GUN_TYPE_DO)
  5198. {
  5199. tempIndex = gun_index;
  5200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5201. {
  5202. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5203. {
  5204. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5206. }
  5207. }
  5208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5209. }
  5210. else
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5213. {
  5214. tempIndex = 2;
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < AC_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5223. {
  5224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5225. }
  5226. }
  5227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5228. }
  5229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5234. }
  5235. //***********************************************(5)VOLTAGE L1******************************************************/
  5236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5238. (dataType == ReadingContext_Trigger))
  5239. {
  5240. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5241. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5242. {
  5243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5244. {
  5245. tempIndex = ((gun_index==2) ? 1: 0);
  5246. }
  5247. else
  5248. {
  5249. tempIndex = gun_index;
  5250. }
  5251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5254. {
  5255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5256. }
  5257. }
  5258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5259. }
  5260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5275. }
  5276. }
  5277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5282. {
  5283. tempIndex = ((gun_index==2) ? 1: 0);
  5284. }
  5285. else
  5286. {
  5287. tempIndex = gun_index;
  5288. }
  5289. for (int index = 0; index < GB_QUANTITY; index++)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5292. {
  5293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5294. }
  5295. }
  5296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5297. }
  5298. else if(gunType[gun_index] == GUN_TYPE_DO)
  5299. {
  5300. tempIndex = gun_index;
  5301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5306. }
  5307. }
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5309. }
  5310. else
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. tempIndex = 2;
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < AC_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5325. }
  5326. }
  5327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5328. }
  5329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5334. }
  5335. //***********************************************(6)SOC******************************************************/
  5336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5338. (dataType == ReadingContext_Trigger))
  5339. {
  5340. 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))
  5341. {
  5342. //idx_sample=5;
  5343. //sampledValue = NULL;
  5344. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5345. {
  5346. tempIndex = ((gun_index==2) ? 1: 0);
  5347. }
  5348. else
  5349. {
  5350. tempIndex = gun_index;
  5351. }
  5352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5353. {
  5354. //tempIndex = ((gun_index==2) ? 1: 0);
  5355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5358. {
  5359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5360. }
  5361. }
  5362. }
  5363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5364. {
  5365. //tempIndex = ((gun_index==2) ? 1: 0);
  5366. for (int index = 0; index < CCS_QUANTITY; index++)
  5367. {
  5368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5369. {
  5370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5371. }
  5372. }
  5373. }
  5374. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5375. {
  5376. //tempIndex = ((gun_index==2) ? 1: 0);
  5377. for (int index = 0; index < GB_QUANTITY; index++)
  5378. {
  5379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5380. {
  5381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5382. }
  5383. }
  5384. }
  5385. else if(gunType[gun_index] == GUN_TYPE_DO)
  5386. {
  5387. //tempIndex = ((gun_index==2) ? 1: 0);
  5388. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5389. {
  5390. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5391. {
  5392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5393. }
  5394. }
  5395. }
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5402. }
  5403. }
  5404. //********************************(7)Current.Import L2************************************************/
  5405. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5406. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5407. (dataType == ReadingContext_Trigger))
  5408. {
  5409. // Only for AC 3 phase
  5410. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5413. {
  5414. tempIndex = 2;
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < AC_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5425. }
  5426. }
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5428. }
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5434. }
  5435. //********************************(8)Current.Import L3************************************************/
  5436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5438. (dataType == ReadingContext_Trigger))
  5439. {
  5440. // Only for AC 3 phase
  5441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5444. {
  5445. tempIndex = 2;
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < AC_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5454. {
  5455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5456. }
  5457. }
  5458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5465. }
  5466. //***********************************************(9)VOLTAGE L2******************************************************/
  5467. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5468. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5469. (dataType == ReadingContext_Trigger))
  5470. {
  5471. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5474. {
  5475. tempIndex = 2;
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < AC_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5486. }
  5487. }
  5488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5489. }
  5490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5495. }
  5496. //***********************************************(10)VOLTAGE L3******************************************************/
  5497. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5498. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5499. (dataType == ReadingContext_Trigger))
  5500. {
  5501. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5502. {
  5503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5504. {
  5505. tempIndex = 2;
  5506. }
  5507. else
  5508. {
  5509. tempIndex = gun_index;
  5510. }
  5511. for (int index = 0; index < AC_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5514. {
  5515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5516. }
  5517. }
  5518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5519. }
  5520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5525. }
  5526. // Message create ====================================================================================================
  5527. if(TRUE)
  5528. {
  5529. json_object *MeterValueReq = json_object_new_object();
  5530. json_object *MeterValues = json_object_new_array();
  5531. json_object *sampledValues = json_object_new_array();
  5532. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5533. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5534. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5535. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5536. {
  5537. json_object *MeterValue = json_object_new_object();
  5538. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5539. {
  5540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5541. {
  5542. json_object *sampledValue = json_object_new_object();
  5543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5544. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5546. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5548. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5550. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5552. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5554. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5556. json_object_array_add(sampledValues, sampledValue);
  5557. }
  5558. }
  5559. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5560. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5561. json_object_array_add(MeterValues, MeterValue);
  5562. }
  5563. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5564. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5565. ,gun_index + 1
  5566. ,MESSAGE_TYPE_CALL
  5567. ,guid
  5568. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5569. json_object_put(MeterValueReq);
  5570. }
  5571. // Put request guid to hash map
  5572. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5573. 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*/)
  5574. {
  5575. result = PASS;
  5576. //DEBUG_INFO("MeterValues mapitem pass\n");
  5577. }
  5578. if((dataType != ReadingContext_Trigger) &&
  5579. (dataType != ReadingContext_Sample_Clock) &&
  5580. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5581. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5582. else
  5583. {
  5584. if(FirstHeartBeat)
  5585. LWS_Send(queuedata +2);
  5586. }
  5587. return result;
  5588. }
  5589. int sendLogStatusNotificationRequest(char *status)
  5590. {
  5591. mtrace();
  5592. int result = PASS;
  5593. char message[4096]={0};
  5594. char guid[37]={0};
  5595. char tempdata[128]={0};
  5596. json_object *LogStatusNotification = json_object_new_object();
  5597. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5598. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5599. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5600. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5601. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5602. random_uuid(guid);
  5603. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5604. json_object_put(LogStatusNotification);
  5605. LWS_Send(message);
  5606. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5607. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5608. {
  5609. result = PASS;
  5610. }
  5611. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5612. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5613. return result;
  5614. }
  5615. int sendSecurityEventNotificationRequest()
  5616. {
  5617. mtrace();
  5618. int result = PASS;
  5619. char message[4096]={0};
  5620. char guid[37]={0};
  5621. char tempdata[128]={0};
  5622. json_object *SecurityEventNotification = json_object_new_object();
  5623. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5624. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5625. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5626. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5627. random_uuid(guid);
  5628. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5629. json_object_put(SecurityEventNotification);
  5630. LWS_Send(message);
  5631. sprintf(tempdata, "SecurityEventNotification,0");
  5632. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5633. {
  5634. result = PASS;
  5635. }
  5636. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5637. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5638. return result;
  5639. }
  5640. int sendSignCertificateRequest()
  5641. {
  5642. mtrace();
  5643. int result = PASS;
  5644. char message[4096]={0};
  5645. char guid[37]={0};
  5646. char tempdata[128]={0};
  5647. json_object *SignCertificate = json_object_new_object();
  5648. DEBUG_INFO("sendSignCertificateRequest...\n");
  5649. // Read csr file content
  5650. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5651. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5652. char *line = NULL;
  5653. size_t len = 0;
  5654. while(getline(&line, &len, fp) != -1)
  5655. {
  5656. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5657. {
  5658. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5659. }
  5660. }
  5661. fclose(fp);
  5662. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5663. random_uuid(guid);
  5664. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5665. json_object_put(SignCertificate);
  5666. LWS_Send(message);
  5667. sprintf(tempdata, "SignCertificate,0");
  5668. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5669. {
  5670. result = PASS;
  5671. }
  5672. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5673. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5674. return result;
  5675. }
  5676. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5677. {
  5678. mtrace();
  5679. int result = PASS;
  5680. char message[110]={0};
  5681. char guid[37]={0};
  5682. char tempdata[65]={0};
  5683. json_object *FirmwareStatusNotification = json_object_new_object();
  5684. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5685. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5686. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5687. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5688. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5689. random_uuid(guid);
  5690. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5691. json_object_put(FirmwareStatusNotification);
  5692. LWS_Send(message);
  5693. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5694. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5695. {
  5696. result = PASS;
  5697. }
  5698. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5699. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5700. return result;
  5701. }
  5702. //==========================================
  5703. // send confirm routine
  5704. //==========================================
  5705. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5706. {
  5707. mtrace();
  5708. int result = FAIL;
  5709. char message[100]={0};
  5710. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5712. LWS_Send(message);
  5713. result = TRUE;
  5714. return result;
  5715. }
  5716. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5717. {
  5718. mtrace();
  5719. int result = FAIL;
  5720. char message[100]={0};
  5721. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5723. LWS_Send(message);
  5724. result = TRUE;
  5725. return result;
  5726. }
  5727. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. char message[100]={0};
  5732. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5734. LWS_Send(message);
  5735. result = TRUE;
  5736. return result;
  5737. }
  5738. int sendClearCacheConfirmation(char *uuid,char *payload)
  5739. {
  5740. mtrace();
  5741. int result = FAIL;
  5742. char message[500]={0};
  5743. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5744. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5745. LWS_Send(message);
  5746. return result;
  5747. }
  5748. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5749. {
  5750. mtrace();
  5751. int result = FAIL;
  5752. char message[500]={0};
  5753. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5754. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5755. LWS_Send(message);
  5756. return result;
  5757. }
  5758. int sendDataTransferConfirmation(char *uuid,char *payload)
  5759. {
  5760. mtrace();
  5761. char statusStr[20]={0};
  5762. char dataStr[10]={0};
  5763. char sstr[20]={0};
  5764. int c = 0;
  5765. char *loc;
  5766. int result = FAIL;
  5767. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5768. /**********************status**************************/
  5769. loc = strstr(payload, "status");
  5770. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5771. c = 0;
  5772. while (loc[3+strlen("status")+c] != '\"')
  5773. {
  5774. sstr[c] = loc[3+strlen("status")+c];
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. strcpy(statusStr, sstr);
  5779. /**********************data**************************/
  5780. loc = strstr(payload, "data");
  5781. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5782. c = 0;
  5783. while (loc[3+strlen("data")+c] != '\"')
  5784. {
  5785. sstr[c] = loc[3+strlen("data")+c];
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. strcpy(dataStr, sstr);
  5790. return result;
  5791. }
  5792. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5793. {
  5794. mtrace();
  5795. int result = FAIL;
  5796. char message[1000]={0};
  5797. int CompositeScheduleIndex = 0;
  5798. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5799. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5800. if(nPeriod == 0)
  5801. {
  5802. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5803. {
  5804. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5805. ,MESSAGE_TYPE_CALLRESULT
  5806. ,uuid
  5807. ,payload
  5808. ,connectorIdInt);
  5809. }
  5810. else
  5811. {
  5812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5813. ,MESSAGE_TYPE_CALLRESULT
  5814. ,uuid
  5815. ,payload
  5816. ,connectorIdInt
  5817. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5818. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5821. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5822. }
  5823. }
  5824. else
  5825. {
  5826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5827. ,MESSAGE_TYPE_CALLRESULT
  5828. ,uuid
  5829. ,payload
  5830. ,connectorIdInt
  5831. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5832. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5833. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5834. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5835. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5836. {
  5837. if (idx_sample == 0)
  5838. {
  5839. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5840. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5841. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5842. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5843. }
  5844. else
  5845. {
  5846. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5847. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5848. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5849. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5850. }
  5851. }
  5852. sprintf(message + strlen(message), "]}}]");
  5853. }
  5854. LWS_Send(message);
  5855. result = TRUE;
  5856. return result;
  5857. }
  5858. int sendGetConfigurationConfirmation(char *uuid)
  5859. {
  5860. mtrace();
  5861. int result = FAIL;
  5862. int MaxKeySupported = 0;
  5863. int sentConfigurationNumber= 0;
  5864. int sentunConfigurationNumber= 0;
  5865. char message[4000]={0};
  5866. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5867. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5868. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5869. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5870. ,MESSAGE_TYPE_CALLRESULT
  5871. ,uuid );
  5872. //configuration key
  5873. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5874. {
  5875. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5876. {
  5877. if (sentConfigurationNumber == 0)
  5878. {
  5879. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5880. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5881. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5882. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5883. }
  5884. else
  5885. {
  5886. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5887. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5888. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5889. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5890. }
  5891. sentConfigurationNumber = sentConfigurationNumber + 1;
  5892. }
  5893. }
  5894. sprintf(message + strlen(message), "]");
  5895. if(UnknownKeynum != 0)
  5896. {
  5897. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5898. //unkown key
  5899. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5900. {
  5901. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5902. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5903. if(sentunConfigurationNumber == 0)
  5904. {
  5905. sprintf(message + strlen(message), "\"%s\""
  5906. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5907. }
  5908. else
  5909. {
  5910. sprintf(message + strlen(message), ",\"%s\""
  5911. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5912. }
  5913. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5914. }
  5915. sprintf(message + strlen(message), "]");
  5916. }
  5917. sprintf(message + strlen(message), "}]");
  5918. LWS_Send(message);
  5919. return result;
  5920. }
  5921. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5922. {
  5923. mtrace();
  5924. int result = FAIL;
  5925. char message[400]={0};
  5926. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5927. if(strcmp(payload,"")==0)
  5928. {
  5929. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5930. }
  5931. else
  5932. {
  5933. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5934. }
  5935. LWS_Send(message);
  5936. result = TRUE;
  5937. return result;
  5938. }
  5939. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5940. {
  5941. mtrace();
  5942. int result = FAIL;
  5943. char message[80]={0};
  5944. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5945. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5946. LWS_Send(message);
  5947. result = TRUE;
  5948. return result;
  5949. }
  5950. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5951. {
  5952. mtrace();
  5953. int result = FAIL;
  5954. char message[80]={0};
  5955. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5957. LWS_Send(message);
  5958. result = TRUE;
  5959. return result;
  5960. }
  5961. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5962. {
  5963. mtrace();
  5964. int result = FAIL;
  5965. char message[80]={0};
  5966. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5968. LWS_Send(message);
  5969. result = TRUE;
  5970. return result;
  5971. }
  5972. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5973. {
  5974. mtrace();
  5975. int result = FAIL;
  5976. char message[80]={0};
  5977. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5978. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5980. LWS_Send(message);
  5981. result = TRUE;
  5982. return result;
  5983. }
  5984. int sendResetConfirmation(char *uuid,char *payload)
  5985. {
  5986. mtrace();
  5987. int result = FAIL;
  5988. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5989. char message[80]={0};
  5990. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5992. LWS_Send(message);
  5993. result = TRUE;
  5994. return result;
  5995. }
  5996. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char message[500]={0};
  6001. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6002. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6003. LWS_Send(message);
  6004. result = TRUE;
  6005. return result;
  6006. }
  6007. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6008. {
  6009. mtrace();
  6010. int result = FAIL;
  6011. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6012. char message[80]={0};
  6013. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6015. LWS_Send(message);
  6016. result = TRUE;
  6017. return result;
  6018. }
  6019. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6020. {
  6021. mtrace();
  6022. int result = FAIL;
  6023. char message[80]={0};
  6024. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6026. LWS_Send(message);
  6027. result = TRUE;
  6028. return result;
  6029. }
  6030. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. char message[80]={0};
  6035. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6036. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6037. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6038. LWS_Send(message);
  6039. result = TRUE;
  6040. return result;
  6041. }
  6042. int sendUpdateFirmwareConfirmation(char *uuid)
  6043. {
  6044. mtrace();
  6045. int result = FAIL;
  6046. char message[60]={0};
  6047. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6048. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6049. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6050. LWS_Send(message);
  6051. result = TRUE;
  6052. return result;
  6053. }
  6054. int sendCertificateSignedConfirmation(char *uuid)
  6055. {
  6056. mtrace();
  6057. int result = PASS;
  6058. char message[4096]={0};
  6059. json_object *CertificateSigned = json_object_new_object();
  6060. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6061. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6062. sprintf(message,"[%d,\"%s\",%s]"
  6063. ,MESSAGE_TYPE_CALLRESULT
  6064. ,uuid
  6065. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6066. json_object_put(CertificateSigned);
  6067. LWS_Send(message);
  6068. return result;
  6069. }
  6070. int sendDeleteCertificateConfirmation(char *uuid)
  6071. {
  6072. mtrace();
  6073. int result = PASS;
  6074. char message[4096]={0};
  6075. json_object *DeleteCertificate = json_object_new_object();
  6076. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6077. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6078. sprintf(message,"[%d,\"%s\",%s]"
  6079. ,MESSAGE_TYPE_CALLRESULT
  6080. ,uuid
  6081. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6082. json_object_put(DeleteCertificate);
  6083. LWS_Send(message);
  6084. return result;
  6085. }
  6086. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6087. {
  6088. mtrace();
  6089. int result = PASS;
  6090. char message[4096]={0};
  6091. json_object *ExtendedTriggerMessage = json_object_new_object();
  6092. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6093. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6094. sprintf(message,"[%d,\"%s\",%s]"
  6095. ,MESSAGE_TYPE_CALLRESULT
  6096. ,uuid
  6097. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6098. json_object_put(ExtendedTriggerMessage);
  6099. LWS_Send(message);
  6100. return result;
  6101. }
  6102. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6103. {
  6104. mtrace();
  6105. int result = PASS;
  6106. char message[4096]={0};
  6107. json_object *GetInstalledCertificateIds = json_object_new_object();
  6108. json_object *certificateHashDataDatas = json_object_new_array();
  6109. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6110. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6111. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6112. {
  6113. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6114. {
  6115. json_object *certificateHashData = json_object_new_object();
  6116. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6117. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6118. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6119. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6120. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6121. }
  6122. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6123. }
  6124. else
  6125. {
  6126. json_object_put(certificateHashDataDatas);
  6127. }
  6128. sprintf(message,"[%d,\"%s\",%s]"
  6129. ,MESSAGE_TYPE_CALLRESULT
  6130. ,uuid
  6131. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6132. json_object_put(GetInstalledCertificateIds);
  6133. LWS_Send(message);
  6134. return result;
  6135. }
  6136. int sendGetLogConfirmation(char *uuid)
  6137. {
  6138. mtrace();
  6139. int result = PASS;
  6140. char message[4096]={0};
  6141. json_object *GetLog = json_object_new_object();
  6142. DEBUG_INFO("sendGetLogConfirmation...\n");
  6143. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6144. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6145. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6146. sprintf(message,"[%d,\"%s\",%s]"
  6147. ,MESSAGE_TYPE_CALLRESULT
  6148. ,uuid
  6149. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6150. json_object_put(GetLog);
  6151. LWS_Send(message);
  6152. return result;
  6153. }
  6154. int sendInstallCertificateConfirmation(char *uuid)
  6155. {
  6156. mtrace();
  6157. int result = PASS;
  6158. char message[4096]={0};
  6159. json_object *InstallCertificate = json_object_new_object();
  6160. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6161. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6162. sprintf(message,"[%d,\"%s\",%s]"
  6163. ,MESSAGE_TYPE_CALLRESULT
  6164. ,uuid
  6165. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6166. json_object_put(InstallCertificate);
  6167. LWS_Send(message);
  6168. return result;
  6169. }
  6170. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6171. {
  6172. mtrace();
  6173. int result = PASS;
  6174. char message[4096]={0};
  6175. json_object *SignedUpdateFirmware = json_object_new_object();
  6176. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6177. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6178. sprintf(message,"[%d,\"%s\",%s]"
  6179. ,MESSAGE_TYPE_CALLRESULT
  6180. ,uuid
  6181. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6182. json_object_put(SignedUpdateFirmware);
  6183. LWS_Send(message);
  6184. return result;
  6185. }
  6186. int sendUnknownConfirmation(char *uuid)
  6187. {
  6188. mtrace();
  6189. int result = PASS;
  6190. char message[256]={0};
  6191. DEBUG_INFO("sendUnknownConfirmation...\n");
  6192. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6193. LWS_Send(message);
  6194. return result;
  6195. }
  6196. //==========================================
  6197. // Handle server request routine Start
  6198. //==========================================
  6199. int handleCancelReservationRequest(char *uuid, char *payload)
  6200. {
  6201. mtrace();
  6202. int result = FAIL;
  6203. int gunNO = 0;
  6204. int reservationIdInt = -1;
  6205. char comfirmstr[20];
  6206. DEBUG_INFO("handleCancelReservationRequest...\n");
  6207. json_object *CancelReservation;
  6208. CancelReservation = json_tokener_parse(payload);
  6209. if(!is_error(CancelReservation))
  6210. {
  6211. // Required data
  6212. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6213. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6214. }
  6215. json_object_put(CancelReservation);
  6216. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6217. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6218. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6219. if(reservationIdInt != -1)
  6220. {
  6221. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6222. //check Transaction active
  6223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6227. {
  6228. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6229. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6230. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6231. {
  6232. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6233. }
  6234. else
  6235. {
  6236. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6237. }
  6238. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6239. goto end;
  6240. }
  6241. }
  6242. for (int index = 0; index < CCS_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6245. {
  6246. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6247. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6248. if(gunType[2] == GUN_TYPE_CCS)
  6249. {
  6250. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6251. }
  6252. else
  6253. {
  6254. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6255. }
  6256. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6257. goto end;
  6258. }
  6259. }
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6263. {
  6264. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6265. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6266. if(gunType[2] == GUN_TYPE_GBT)
  6267. {
  6268. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6269. }
  6270. else
  6271. {
  6272. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6273. }
  6274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6275. goto end;
  6276. }
  6277. }
  6278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6281. {
  6282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6284. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6285. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6286. goto end;
  6287. }
  6288. }
  6289. for (int index = 0; index < AC_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6292. {
  6293. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6294. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6296. {
  6297. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6298. }
  6299. else
  6300. {
  6301. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6302. }
  6303. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6304. goto end;
  6305. }
  6306. }
  6307. }
  6308. //The reservationId does NOT match the reservationId
  6309. sendCancelReservationConfirmation(uuid, comfirmstr);
  6310. end:
  6311. // Fill in ocpp packet uuid
  6312. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6313. return result;
  6314. }
  6315. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6316. {
  6317. mtrace();
  6318. int result = FAIL;
  6319. int gunIndex = 0;
  6320. char typeStr[16]={0};
  6321. char comfirmstr[20];
  6322. int specificId = FALSE;
  6323. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6324. json_object *ChangeAvailability;
  6325. ChangeAvailability = json_tokener_parse(payload);
  6326. if(!is_error(ChangeAvailability))
  6327. {
  6328. // Required data
  6329. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6330. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6331. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6332. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6333. }
  6334. json_object_put(ChangeAvailability);
  6335. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6336. {
  6337. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6338. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6339. }
  6340. else if(gunIndex == 0)
  6341. {
  6342. for(int i=0; i < gunTotalNumber; i++)
  6343. {
  6344. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6345. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6346. }
  6347. }
  6348. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6350. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6351. {
  6352. specificId = TRUE;
  6353. }
  6354. if(specificId == FALSE)
  6355. goto end;
  6356. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6357. {
  6358. //----------------------gunIndex is 0 ------------------------------------------------//
  6359. if(gunIndex == 0)
  6360. {
  6361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6362. {
  6363. for(int i=0; i < gunTotalNumber; i++)
  6364. {
  6365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6366. {
  6367. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6370. {
  6371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6372. goto end;
  6373. }
  6374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6379. {
  6380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6381. goto end;
  6382. }
  6383. }
  6384. }//END FOR CHAdeMO_QUANTITY
  6385. for (int index = 0; index < CCS_QUANTITY; index++)
  6386. {
  6387. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6388. {
  6389. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6390. {
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6392. goto end;
  6393. }
  6394. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6398. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6399. {
  6400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6401. goto end;
  6402. }
  6403. }
  6404. }//END FOR CCS_QUANTITY
  6405. for (int index = 0; index < GB_QUANTITY; index++)
  6406. {
  6407. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6408. {
  6409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6410. {
  6411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6412. goto end;
  6413. }
  6414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6419. {
  6420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6421. goto end;
  6422. }
  6423. }
  6424. }// END FOR GB_QUANTITY
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6430. {
  6431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6432. goto end;
  6433. }
  6434. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6439. {
  6440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6441. goto end;
  6442. }
  6443. }
  6444. }// END FOR GENERAL_GUN_QUANTITY
  6445. for (int index = 0; index < AC_QUANTITY; index++)
  6446. {
  6447. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6448. {
  6449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6450. {
  6451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6452. goto end;
  6453. }
  6454. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6459. {
  6460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6461. goto end;
  6462. }
  6463. }
  6464. }//END FOR AC_QUANTITY
  6465. }// END FOR gunTotalNumber
  6466. }
  6467. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6468. {
  6469. for(int i=0; i < gunTotalNumber; i++)
  6470. {
  6471. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6472. {
  6473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6474. goto end;
  6475. }
  6476. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6478. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6481. {
  6482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6483. goto end;
  6484. }
  6485. }
  6486. }
  6487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6488. goto end;
  6489. }
  6490. //----------------------gunIndex is not 0 ------------------------------------------------//
  6491. //check Transaction active
  6492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6493. {
  6494. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6495. {
  6496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6497. {
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6499. goto end;
  6500. }
  6501. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6502. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6505. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6506. {
  6507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6508. goto end;
  6509. }
  6510. else
  6511. {
  6512. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6514. goto end;
  6515. }
  6516. }
  6517. }//END FOR CHAdeMO_QUANTITY
  6518. for (int index = 0; index < CCS_QUANTITY; index++)
  6519. {
  6520. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6523. {
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6525. goto end;
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6530. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6532. {
  6533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6534. goto end;
  6535. }
  6536. else
  6537. {
  6538. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6540. goto end;
  6541. }
  6542. }
  6543. }//END FOR CCS_QUANTITY
  6544. for (int index = 0; index < GB_QUANTITY; index++)
  6545. {
  6546. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6547. {
  6548. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6549. {
  6550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6551. goto end;
  6552. }
  6553. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6556. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6557. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6558. {
  6559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6560. goto end;
  6561. }
  6562. else
  6563. {
  6564. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6566. goto end;
  6567. }
  6568. }
  6569. }// END FOR GB_QUANTITY
  6570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6571. {
  6572. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6575. {
  6576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6577. goto end;
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6583. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6584. {
  6585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6586. goto end;
  6587. }
  6588. else
  6589. {
  6590. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6592. goto end;
  6593. }
  6594. }
  6595. }// END FOR GENERAL_GUN_QUANTITY
  6596. for (int index = 0; index < AC_QUANTITY; index++)
  6597. {
  6598. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6599. {
  6600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6601. {
  6602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6603. goto end;
  6604. }
  6605. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6608. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6609. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6610. {
  6611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6612. goto end;
  6613. }
  6614. else
  6615. {
  6616. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6618. goto end;
  6619. }
  6620. }
  6621. }//END FOR AC_QUANTITY
  6622. }//END FOR AvailabilityTypeStr[Inoperative]
  6623. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6624. {
  6625. //----------------------gunIndex is 0 ------------------------------------------------//
  6626. if(gunIndex == 0)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6629. {
  6630. for(int i=0; i < gunTotalNumber; i++)
  6631. {
  6632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6633. {
  6634. 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
  6635. {
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6637. goto end;
  6638. }
  6639. }//END FOR CHAdeMO_QUANTITY
  6640. for (int index = 0; index < CCS_QUANTITY; index++)
  6641. {
  6642. 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
  6643. {
  6644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6645. goto end;
  6646. }
  6647. }//END FOR CCS_QUANTITY
  6648. for (int index = 0; index < GB_QUANTITY; index++)
  6649. {
  6650. 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
  6651. {
  6652. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6654. goto end;
  6655. }
  6656. }// END FOR GB_QUANTITY
  6657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6658. {
  6659. 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
  6660. {
  6661. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6663. goto end;
  6664. }
  6665. }// END FOR GENERAL_GUN_QUANTITY
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. 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
  6669. {
  6670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6671. goto end;
  6672. }
  6673. }//END FOR CHAdeMO_QUANTITY
  6674. }// END FOR gunTotalNumber
  6675. }
  6676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6677. {
  6678. for(int i=0; i < gunTotalNumber; i++)
  6679. {
  6680. for (int index = 0; index < AC_QUANTITY; index++)
  6681. {
  6682. 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
  6683. {
  6684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6685. goto end;
  6686. }
  6687. }//END FOR CHAdeMO_QUANTITY
  6688. } // END FOR gunTotalNumber
  6689. }
  6690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6691. goto end;
  6692. }
  6693. //----------------------gunIndex is not 0 ------------------------------------------------//
  6694. //check Transaction active
  6695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6696. {
  6697. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6698. {
  6699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6700. goto end;
  6701. }
  6702. }//END FOR CHAdeMO_QUANTITY
  6703. for (int index = 0; index < CCS_QUANTITY; index++)
  6704. {
  6705. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6706. {
  6707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6708. goto end;
  6709. }
  6710. }//END FOR CCS_QUANTITY
  6711. for (int index = 0; index < GB_QUANTITY; index++)
  6712. {
  6713. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6714. {
  6715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6716. goto end;
  6717. }
  6718. }// END FOR GB_QUANTITY
  6719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6720. {
  6721. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6722. {
  6723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6724. goto end;
  6725. }
  6726. }// END FOR GENERAL_GUN_QUANTITY
  6727. for (int index = 0; index < AC_QUANTITY; index++)
  6728. {
  6729. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6730. {
  6731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6732. goto end;
  6733. }
  6734. }//END FOR AC_QUANTITY
  6735. }//END FOR AvailabilityTypeStr[Operative]
  6736. end:
  6737. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6740. }
  6741. else
  6742. {
  6743. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6744. }
  6745. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6746. {
  6747. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6748. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6749. }
  6750. else if(gunIndex == 0)
  6751. {
  6752. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6753. {
  6754. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6755. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6756. }
  6757. }
  6758. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6760. return result;
  6761. }
  6762. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. char keystr[40]={0};
  6767. char valuestr[256]={0};
  6768. char comfirmstr[20]={0};
  6769. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6770. json_object *ChangeConfiguration;
  6771. ChangeConfiguration = json_tokener_parse(payload);
  6772. if(!is_error(ChangeConfiguration))
  6773. {
  6774. // Required data
  6775. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6776. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6777. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6778. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6779. }
  6780. json_object_put(ChangeConfiguration);
  6781. if((uuid==NULL) || (payload ==NULL) )
  6782. {
  6783. DEBUG_ERROR("Payload is null\n");
  6784. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6785. }
  6786. else
  6787. {
  6788. int status = setKeyValue(keystr, valuestr);
  6789. switch(status)
  6790. {
  6791. case ConfigurationStatus_Accepted:
  6792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6793. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6794. StoreConfigurationTable();
  6795. break;
  6796. case RebootRequired:
  6797. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6798. StoreConfigurationTable();
  6799. break;
  6800. case NotSupported:
  6801. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6802. break;
  6803. case ConfigurationStatus_Rejected:
  6804. default:
  6805. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6806. break;
  6807. }
  6808. }
  6809. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6810. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6811. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6812. {
  6813. ChageWebSocketPingInterval(atoi(valuestr));
  6814. }
  6815. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6816. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6817. {
  6818. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6819. SetOcppConnStatus(FALSE);
  6820. }
  6821. return result;
  6822. }
  6823. int handleClearCacheRequest(char *uuid, char *payload)
  6824. {
  6825. mtrace();
  6826. int result = FAIL;
  6827. char comfirmstr[20];
  6828. char rmFileCmd[100]={0};
  6829. struct stat stats;
  6830. DEBUG_INFO("handleClearCacheRequest...\n");
  6831. stat("/Storage/OCPP", &stats);
  6832. // Check for directory existence
  6833. if (S_ISDIR(stats.st_mode) == 1)
  6834. {}
  6835. else
  6836. {
  6837. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6838. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6839. system(rmFileCmd);
  6840. }
  6841. if(OCPP_cleanLocalCache())
  6842. {
  6843. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6844. }
  6845. else
  6846. {
  6847. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6848. }
  6849. sendClearCacheConfirmation(uuid, comfirmstr);
  6850. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6851. return result;
  6852. }
  6853. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6854. {
  6855. mtrace();
  6856. int result = FAIL;
  6857. int resultRename;
  6858. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6859. char chargingProfilePurposeStr[26]={0};
  6860. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6861. char tempchargingProfilePurposeStr[26]={0};
  6862. char str[100]={0};
  6863. char fname[200]={0};
  6864. char comfirmstr[20]={0};
  6865. char word[1600]={0};
  6866. int clearflag = FALSE;
  6867. int chargingProfileIdIsNULL = FALSE;
  6868. int connectorIsNULL = FALSE;
  6869. int chargingProfilePurposeIsNULL = FALSE;
  6870. int stackLevelIsNULL = FALSE;
  6871. //int GotoEnd = FALSE;
  6872. FILE *fptr1, *fptr2;
  6873. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6874. int n_chargingProfile=0;
  6875. int isEmptyFile = FALSE;
  6876. char sLineWord[1600]={0};
  6877. char chargingProfiles[10][100]={0};
  6878. int ChargeProfileCount = 0;
  6879. int ch;
  6880. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6881. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6882. json_object *ClearChargingProfile;
  6883. ClearChargingProfile = json_tokener_parse(payload);
  6884. if(!is_error(ClearChargingProfile))
  6885. {
  6886. // Optional data
  6887. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6888. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6889. else
  6890. chargingProfileIdIsNULL = TRUE;
  6891. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6892. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6893. else
  6894. connectorIsNULL = TRUE;
  6895. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6896. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6897. else
  6898. chargingProfilePurposeIsNULL = TRUE;
  6899. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6900. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6901. else
  6902. stackLevelIsNULL = TRUE;
  6903. }
  6904. json_object_put(ClearChargingProfile);
  6905. if(connectorIsNULL == FALSE)
  6906. {
  6907. switch(connectorIdInt)
  6908. {
  6909. case 0:
  6910. if(chargingProfilePurposeIsNULL == TRUE)
  6911. {
  6912. int l = 0;
  6913. strcpy(fname, ChargePointMaxProfile_JSON);
  6914. if((access(fname,F_OK))!=-1)
  6915. {
  6916. strcpy(chargingProfiles[l], fname);
  6917. l = l + 1;
  6918. }
  6919. strcpy(fname, TxDefaultProfile_0_JSON);
  6920. if((access(fname,F_OK))!=-1)
  6921. {
  6922. strcpy(chargingProfiles[l], fname);
  6923. l = l + 1;
  6924. }
  6925. ChargeProfileCount = l;
  6926. }
  6927. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6928. {
  6929. strcpy(fname, ChargePointMaxProfile_JSON);
  6930. if((access(fname,F_OK))!=-1)
  6931. {
  6932. strcpy(chargingProfiles[0], fname);
  6933. ChargeProfileCount = 1;
  6934. }
  6935. }
  6936. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6937. {
  6938. strcpy(fname, TxDefaultProfile_0_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[0], fname);
  6942. ChargeProfileCount = 1;
  6943. }
  6944. }
  6945. break;
  6946. default:
  6947. if(chargingProfilePurposeIsNULL == TRUE)
  6948. {
  6949. int m = 0;
  6950. memset(fname, 0, ARRAY_SIZE(fname));
  6951. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6952. if((access(fname,F_OK))!=-1)
  6953. {
  6954. strcpy(chargingProfiles[m], fname);
  6955. m = m + 1;
  6956. }
  6957. memset(fname, 0, ARRAY_SIZE(fname));
  6958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6959. if((access(fname,F_OK))!=-1)
  6960. {
  6961. strcpy(chargingProfiles[m], fname);
  6962. m = m + 1;
  6963. }
  6964. ChargeProfileCount = m;
  6965. }
  6966. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6967. {
  6968. //strcpy(fname, TxDefaultProfile_1_JSON);
  6969. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6970. if((access(fname,F_OK))!=-1)
  6971. {
  6972. strcpy(chargingProfiles[0], fname);
  6973. ChargeProfileCount = 1;
  6974. }
  6975. }
  6976. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6977. {
  6978. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6979. if((access(fname,F_OK))!=-1)
  6980. {
  6981. strcpy(chargingProfiles[0], fname);
  6982. ChargeProfileCount = 1;
  6983. }
  6984. //strcpy(fname, TxProfile_1_JSON);
  6985. }
  6986. //strcpy(fname, ChargePointMaxProfile_JSON );
  6987. break;
  6988. }
  6989. }
  6990. else // Check all Charging Profiles
  6991. {
  6992. int i = 0;
  6993. char fnametemp[200]={0};
  6994. ChargeProfileCount = 0;
  6995. //Check ChargePointMaxProfile.json exit
  6996. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6997. {
  6998. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6999. i = i + 1;
  7000. }
  7001. //Check TxDefaultProfile_0.json exit
  7002. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7003. {
  7004. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7005. i = i + 1;
  7006. }
  7007. //Check TxDefaultProfile_%d.json
  7008. for(int j=1; j <= gunTotalNumber; j++)
  7009. {
  7010. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7011. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7012. if((access(fnametemp,F_OK))!=-1)
  7013. {
  7014. strcpy(chargingProfiles[i], fnametemp);
  7015. i = i + 1;
  7016. }
  7017. }
  7018. //Check TxProfile_%d.json
  7019. for(int j=1; j <= gunTotalNumber; j++)
  7020. {
  7021. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7022. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7023. if((access(fnametemp,F_OK))!=-1)
  7024. {
  7025. strcpy(chargingProfiles[i], fnametemp);
  7026. i = i + 1;
  7027. }
  7028. }
  7029. ChargeProfileCount = i;
  7030. }// End connectorIsNULL is TRUE
  7031. if(ChargeProfileCount == 0)
  7032. {
  7033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7034. goto end;
  7035. }
  7036. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7037. {
  7038. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7039. goto end;
  7040. }
  7041. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7042. {
  7043. memset(str, 0, ARRAY_SIZE(str));
  7044. // clear temp file
  7045. sprintf(str,"rm -f %s",temp);
  7046. system(str);
  7047. for(int k=0; k < ChargeProfileCount; k++)
  7048. {
  7049. memset(str, 0, ARRAY_SIZE(str));
  7050. //clear file in C
  7051. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7052. system(str);
  7053. }
  7054. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7055. goto end;
  7056. }
  7057. else if(connectorIsNULL == TRUE)
  7058. {
  7059. for(int k=0; k < ChargeProfileCount; k++)
  7060. {
  7061. fptr1 = fopen(chargingProfiles[k], "r");
  7062. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7063. //Check Charging Profile Count
  7064. while(fscanf(fptr1, "%s", word) != EOF)
  7065. {
  7066. //DEBUG_INFO("word=%s\n",word);
  7067. if(strstr(word, "chargingProfileId")!= NULL)
  7068. {
  7069. //DEBUG_INFO("test chargingProfileId \n");
  7070. n_chargingProfile = n_chargingProfile + 1;
  7071. //DEBUG_INFO("chargingProfileId Found\n");
  7072. }
  7073. }
  7074. rewind(fptr1);
  7075. //search Charging Profile Element
  7076. //int i= 0;
  7077. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7078. {
  7079. json_object *tmpProfilee;
  7080. tmpProfilee = json_tokener_parse(sLineWord);
  7081. if(!is_error(tmpProfilee))
  7082. {
  7083. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7084. {
  7085. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7086. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7087. }
  7088. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7089. {
  7090. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7091. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7092. }
  7093. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7094. {
  7095. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7096. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7097. }
  7098. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7099. {
  7100. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7101. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7102. }
  7103. }
  7104. json_object_put(tmpProfilee);
  7105. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7106. {
  7107. //------- not write to fptr2-------//
  7108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7109. //clearflag = TRUE;
  7110. }
  7111. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7112. {
  7113. //------- not write to fptr2-------//
  7114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7115. }
  7116. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7117. {
  7118. //------- not write to fptr2-------//
  7119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7120. }
  7121. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7122. {
  7123. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7124. }
  7125. else
  7126. {
  7127. fprintf(fptr2, sLineWord);//writing data into file
  7128. }
  7129. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7130. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7131. if(clearflag == TRUE)
  7132. {
  7133. fclose(fptr1);
  7134. fclose(fptr2);
  7135. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7136. system(str);
  7137. // clear temp file
  7138. sprintf(str,"rm -f %s",temp);
  7139. system(str);
  7140. }
  7141. else
  7142. {
  7143. fclose(fptr1);
  7144. fclose(fptr2);
  7145. memset(str, 0, ARRAY_SIZE(str));
  7146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7147. system(str);
  7148. resultRename = rename(temp, chargingProfiles[k]);
  7149. if(resultRename == 0)
  7150. {
  7151. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7152. }
  7153. else
  7154. {
  7155. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7156. }
  7157. if(comfirmstr[0]== 0)
  7158. {
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7160. }
  7161. //Check chargingProfile is empty file
  7162. /*------ Read the file ----------------*/
  7163. fptr1=fopen(chargingProfiles[k],"r");
  7164. ch=fgetc(fptr1);
  7165. rewind(fptr1);
  7166. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7167. if(ch!=EOF)
  7168. {
  7169. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7170. {
  7171. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7172. if(sLineWord[0]=='\0')
  7173. {
  7174. isEmptyFile = TRUE;
  7175. break;
  7176. }
  7177. else
  7178. {
  7179. isEmptyFile = FALSE;
  7180. break;
  7181. }
  7182. }
  7183. }
  7184. else
  7185. isEmptyFile = TRUE;
  7186. fclose(fptr1);
  7187. if(isEmptyFile == TRUE)
  7188. {
  7189. memset(str, 0, ARRAY_SIZE(str));
  7190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7191. system(str);
  7192. }
  7193. }
  7194. }// End of while(int k=0; k < ChargePointCount; k++)
  7195. }
  7196. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7197. {
  7198. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7199. for(int k=0; k < ChargeProfileCount; k++)
  7200. {
  7201. fptr1 = fopen(chargingProfiles[k], "r");
  7202. fptr2 = fopen(temp, "w+");
  7203. //Check Charging Profile Count
  7204. while(fscanf(fptr1, "%s", word) != EOF)
  7205. {
  7206. //DEBUG_INFO("word=%s\n",word);
  7207. if(strstr(word, "chargingProfileId")!= NULL)
  7208. {
  7209. n_chargingProfile = n_chargingProfile + 1;
  7210. }
  7211. }
  7212. rewind(fptr1);
  7213. //search Charging Profile Element
  7214. //int i= 0;
  7215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7216. {
  7217. json_object *tmpProfilee;
  7218. tmpProfilee = json_tokener_parse(sLineWord);
  7219. if(!is_error(tmpProfilee))
  7220. {
  7221. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7222. {
  7223. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7224. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7225. }
  7226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7227. {
  7228. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7229. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7230. }
  7231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7232. {
  7233. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7234. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7235. }
  7236. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7237. {
  7238. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7239. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7240. }
  7241. }
  7242. json_object_put(tmpProfilee);
  7243. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7244. {
  7245. //------- not write to fptr2-------//
  7246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7247. //clearflag = TRUE;
  7248. }
  7249. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7250. {
  7251. //------- not write to fptr2-------//
  7252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7253. }
  7254. else if(stackLevelIsNULL == TRUE)
  7255. {
  7256. //Clear Whole File
  7257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7258. clearflag = TRUE;
  7259. break;
  7260. }
  7261. else
  7262. {
  7263. fprintf(fptr2, sLineWord);//writing data into file
  7264. }
  7265. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7266. }
  7267. if(clearflag == TRUE)
  7268. {
  7269. fclose(fptr1);
  7270. fclose(fptr2);
  7271. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7272. system(str);
  7273. // clear temp file
  7274. sprintf(str,"rm -f %s",temp);
  7275. system(str);
  7276. }
  7277. else
  7278. {
  7279. fclose(fptr1);
  7280. fclose(fptr2);
  7281. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7282. system(str);
  7283. resultRename = rename(temp, chargingProfiles[k]);
  7284. if(resultRename == 0)
  7285. {
  7286. DEBUG_INFO("File ChargingProfile renamed successfully");
  7287. }
  7288. else
  7289. {
  7290. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7291. }
  7292. if(comfirmstr[0]== 0)
  7293. {
  7294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7295. }
  7296. //Check chargingProfile is empty file
  7297. /*------ Read the file ----------------*/
  7298. fptr1=fopen(chargingProfiles[k],"r");
  7299. ch=fgetc(fptr1);
  7300. rewind(fptr1);
  7301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7302. if(ch!=EOF)
  7303. {
  7304. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7305. {
  7306. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7307. if(sLineWord[0]=='\0')
  7308. {
  7309. isEmptyFile = TRUE;
  7310. break;
  7311. }
  7312. else
  7313. {
  7314. isEmptyFile = FALSE;
  7315. break;
  7316. }
  7317. }
  7318. }
  7319. else
  7320. isEmptyFile = TRUE;
  7321. fclose(fptr1);
  7322. if(isEmptyFile == TRUE)
  7323. {
  7324. memset(str, 0, ARRAY_SIZE(str));
  7325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7326. system(str);
  7327. }
  7328. /*------- End of reading ---------------*/
  7329. }
  7330. } // while(int k=0; k < ChargeProfileCount; k++)
  7331. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7332. end:
  7333. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7334. {
  7335. if(connectorIdInt == 0)
  7336. {
  7337. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7338. {
  7339. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7340. }
  7341. }
  7342. else
  7343. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7344. }
  7345. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7346. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7347. return result;
  7348. }
  7349. void createFirmwareVersionByDataTransfer(void)
  7350. {
  7351. json_object *FirmwareDataTransfer = json_object_new_object();
  7352. // AC & DC model
  7353. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7354. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7355. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7356. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7357. // DC model
  7358. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7359. {
  7360. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7361. {
  7362. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7363. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7364. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7365. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7366. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7367. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7368. }
  7369. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7370. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7371. {
  7372. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7373. }
  7374. }
  7375. else
  7376. {
  7377. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7381. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7390. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7391. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7392. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7393. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7394. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7395. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7396. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7397. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7398. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7399. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7400. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7401. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7402. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7403. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7404. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7405. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7406. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7407. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7408. }
  7409. // 4G model
  7410. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7411. {
  7412. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7413. }
  7414. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7415. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7416. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7417. json_object_put(FirmwareDataTransfer);
  7418. }
  7419. int handleDataTransferRequest(char *uuid, char *payload)
  7420. {
  7421. mtrace();
  7422. json_object *response = json_object_new_object();
  7423. int result = FAIL;
  7424. char tempvendorId[255]={0};
  7425. char tempmessageId[50]={0};
  7426. char tempdata[512]={0};
  7427. char message[2048]={0};
  7428. DEBUG_INFO("handleDataTransferRequest...\n");
  7429. if((uuid != NULL) && (payload != NULL))
  7430. {
  7431. json_object *DataTransfer;
  7432. DataTransfer = json_tokener_parse(payload);
  7433. if(!is_error(DataTransfer))
  7434. {
  7435. // Required data
  7436. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7437. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7438. // Optional data
  7439. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7440. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7441. if(json_object_object_get(DataTransfer, "data") != NULL)
  7442. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7443. result = PASS;
  7444. }
  7445. json_object_put(DataTransfer);
  7446. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7447. {
  7448. // Send all moudle firmware version on EVSE
  7449. createFirmwareVersionByDataTransfer();
  7450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7451. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7452. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7453. json_object_put(response);
  7454. }
  7455. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7456. {
  7457. system("/usr/bin/run_tmate_restart.sh &");
  7458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7459. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(response);
  7461. }
  7462. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7463. {
  7464. json_object *data;
  7465. data = json_tokener_parse(tempdata);
  7466. if(!is_error(data))
  7467. {
  7468. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7469. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7470. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7471. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7472. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7473. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7474. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7475. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7479. }
  7480. else
  7481. {
  7482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7484. }
  7485. json_object_put(data);
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7490. {
  7491. json_object *data;
  7492. data = json_tokener_parse(tempdata);
  7493. if(!is_error(data))
  7494. {
  7495. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7496. if(json_object_object_get(data, "idToken") != NULL)
  7497. {
  7498. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7499. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7500. }
  7501. if(json_object_object_get(data, "price") != NULL)
  7502. {
  7503. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7504. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7505. }
  7506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7507. }
  7508. else
  7509. {
  7510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7512. }
  7513. json_object_put(data);
  7514. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7515. json_object_put(response);
  7516. }
  7517. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7518. {
  7519. json_object *data;
  7520. data = json_tokener_parse(tempdata);
  7521. if(!is_error(data))
  7522. {
  7523. if(json_object_object_get(data, "txId") != NULL)
  7524. {
  7525. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7526. for(int idx = 0;idx<gunTotalNumber;idx++)
  7527. {
  7528. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7529. {
  7530. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  7531. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7532. if(json_object_object_get(data, "description") != NULL)
  7533. {
  7534. // California pricing V1.0
  7535. DEBUG_INFO("California pricing V1.0\n");
  7536. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7537. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7538. }
  7539. else
  7540. {
  7541. // California pricing V1.1
  7542. DEBUG_INFO("California pricing V1.1\n");
  7543. if(json_object_object_get(data, "timestamp") != NULL)
  7544. {
  7545. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  7546. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  7547. }
  7548. if(json_object_object_get(data, "meterValue") != NULL)
  7549. {
  7550. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  7551. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  7552. }
  7553. if(json_object_object_get(data, "cost") != NULL)
  7554. {
  7555. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  7556. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  7557. }
  7558. if(json_object_object_get(data, "state") != NULL)
  7559. {
  7560. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  7561. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  7562. }
  7563. if(json_object_object_get(data, "chargingPrice") != NULL)
  7564. {
  7565. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  7566. {
  7567. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  7568. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  7569. }
  7570. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  7571. {
  7572. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  7573. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  7574. }
  7575. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  7576. {
  7577. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  7578. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  7579. }
  7580. }
  7581. if(json_object_object_get(data, "idlePrice") != NULL)
  7582. {
  7583. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  7584. {
  7585. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  7586. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  7587. }
  7588. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  7589. {
  7590. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  7591. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  7592. }
  7593. }
  7594. if(json_object_object_get(data, "nextPeriod") != NULL)
  7595. {
  7596. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  7597. {
  7598. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7599. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7600. }
  7601. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  7602. {
  7603. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  7604. {
  7605. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  7606. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  7607. }
  7608. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  7609. {
  7610. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  7611. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  7612. }
  7613. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  7614. {
  7615. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  7616. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  7617. }
  7618. }
  7619. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  7620. {
  7621. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  7622. {
  7623. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  7624. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  7625. }
  7626. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  7627. {
  7628. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  7629. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  7630. }
  7631. }
  7632. }
  7633. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  7634. {
  7635. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  7636. {
  7637. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7638. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7639. }
  7640. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  7641. {
  7642. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  7643. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  7644. }
  7645. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  7646. {
  7647. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  7648. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  7649. }
  7650. }
  7651. }
  7652. }
  7653. }
  7654. }
  7655. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7656. }
  7657. else
  7658. {
  7659. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7660. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7661. }
  7662. json_object_put(data);
  7663. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7664. json_object_put(response);
  7665. }
  7666. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7667. {
  7668. json_object *data;
  7669. data = json_tokener_parse(tempdata);
  7670. if(!is_error(data))
  7671. {
  7672. if(json_object_object_get(data, "txId") != NULL)
  7673. {
  7674. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7675. for(int idx = 0;idx<gunTotalNumber;idx++)
  7676. {
  7677. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7678. {
  7679. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  7680. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7681. if(json_object_object_get(data, "description") != NULL)
  7682. {
  7683. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7684. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7685. }
  7686. }
  7687. }
  7688. }
  7689. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7690. }
  7691. else
  7692. {
  7693. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7694. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7695. }
  7696. json_object_put(data);
  7697. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7698. json_object_put(response);
  7699. }
  7700. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7701. {
  7702. json_object *data;
  7703. data = json_tokener_parse(tempdata);
  7704. if(!is_error(data))
  7705. {
  7706. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7707. if(json_object_object_get(data, "Content_Type") != NULL)
  7708. {
  7709. 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))
  7710. {
  7711. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7712. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7713. {
  7714. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7715. }
  7716. }
  7717. else
  7718. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7719. }
  7720. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7721. }
  7722. else
  7723. {
  7724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7725. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7726. }
  7727. json_object_put(data);
  7728. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7729. json_object_put(response);
  7730. }
  7731. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7732. {
  7733. json_object *data;
  7734. data = json_tokener_parse(tempdata);
  7735. if(!is_error(data))
  7736. {
  7737. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7738. if(json_object_object_get(data, "Page_Index") != NULL)
  7739. {
  7740. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7741. }
  7742. if(json_object_object_get(data, "Duration") != NULL)
  7743. {
  7744. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7745. }
  7746. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7747. }
  7748. else
  7749. {
  7750. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7751. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7752. }
  7753. json_object_put(data);
  7754. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7755. json_object_put(response);
  7756. }
  7757. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7758. {
  7759. json_object *data;
  7760. data = json_tokener_parse(tempdata);
  7761. if(!is_error(data))
  7762. {
  7763. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7764. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7765. {
  7766. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7767. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7768. else
  7769. {
  7770. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7771. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7772. }
  7773. }
  7774. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7775. {
  7776. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7777. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7778. else
  7779. {
  7780. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7781. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7782. }
  7783. }
  7784. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7785. {
  7786. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7787. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7788. else
  7789. {
  7790. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7791. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7792. }
  7793. }
  7794. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7795. {
  7796. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7797. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7798. else
  7799. {
  7800. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7801. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7802. }
  7803. }
  7804. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7805. {
  7806. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7807. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7808. else
  7809. {
  7810. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7811. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7812. }
  7813. }
  7814. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7815. {
  7816. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7817. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7818. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7819. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7820. else
  7821. {
  7822. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7823. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7824. }
  7825. }
  7826. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7827. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7828. }
  7829. else
  7830. {
  7831. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7832. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7833. }
  7834. json_object_put(data);
  7835. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7836. json_object_put(response);
  7837. }
  7838. else
  7839. {
  7840. // Can not find valid message id
  7841. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7842. }
  7843. }
  7844. else
  7845. {
  7846. // Payload is null
  7847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7848. }
  7849. LWS_Send(message);
  7850. return result;
  7851. }
  7852. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7853. {
  7854. mtrace();
  7855. int result = FAIL;
  7856. int connectorIdInt, durationInt;
  7857. char chargingRateUnitStr[4]={0};
  7858. char comfirmstr[20];
  7859. int confirmPeriods = 0;
  7860. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7861. json_object *GetCompositeSchedule;
  7862. GetCompositeSchedule = json_tokener_parse(payload);
  7863. if(!is_error(GetCompositeSchedule))
  7864. {
  7865. // Required data
  7866. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7867. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7868. else
  7869. connectorIdInt = -1;
  7870. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7871. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7872. else
  7873. durationInt = 86400;
  7874. // Optional data
  7875. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7876. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7877. }
  7878. json_object_put(GetCompositeSchedule);
  7879. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7880. if((connectorIdInt == 0) ||
  7881. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7882. {
  7883. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7884. struct StructChargingProfile tmpProfile[1];
  7885. if(strstr(chargingRateUnitStr, "W") != NULL)
  7886. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7887. else
  7888. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7889. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7890. {
  7891. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7892. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7893. }
  7894. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7895. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7896. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7897. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7898. {
  7899. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7900. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7901. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7902. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7903. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7904. {
  7905. confirmPeriods = idx;
  7906. break;
  7907. }
  7908. }
  7909. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7910. {
  7911. confirmPeriods += 1;
  7912. }
  7913. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7914. }
  7915. else
  7916. {
  7917. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7918. }
  7919. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7920. return result;
  7921. }
  7922. int handleGetConfigurationRequest(char *uuid, char *payload)
  7923. {
  7924. mtrace();
  7925. int result = FAIL;
  7926. int MaxKeySupported = 0;
  7927. int n_keys = 0;
  7928. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7929. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7930. json_object *GetConfiguration;
  7931. GetConfiguration = json_tokener_parse(payload);
  7932. if(!is_error(GetConfiguration))
  7933. {
  7934. // Optional data
  7935. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7936. {
  7937. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7938. {
  7939. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7940. n_keys = idx + 1;
  7941. }
  7942. }
  7943. }
  7944. json_object_put(GetConfiguration);
  7945. UnknownKeynum = 0;
  7946. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7947. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7948. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7949. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7950. if(n_keys != 0)
  7951. {
  7952. for(int i=0;i<n_keys;i++)
  7953. {
  7954. getKeyValue(requestKey[i]);
  7955. }
  7956. }
  7957. else
  7958. {
  7959. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7960. getKeyValue("");
  7961. }
  7962. processUnkownKey();
  7963. sendGetConfigurationConfirmation(uuid);
  7964. return result;
  7965. }
  7966. static char fnamePlusPath[100]={0};
  7967. static char fnamePWithNoPath[60]={0};
  7968. void checkUploadLog(void)
  7969. {
  7970. FILE *fp;
  7971. /* Open the command for reading. */
  7972. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7973. if (fp == NULL) {
  7974. printf("Failed to run command\n" );
  7975. exit(1);
  7976. }
  7977. int ftppathlen = 0;
  7978. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7979. int i = 0;
  7980. /* Read the output a line at a time - output it. */
  7981. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7982. if(i==0)
  7983. {
  7984. ftppathlen = strlen(fnamePlusPath);
  7985. printf("%s\n", fnamePlusPath);
  7986. fnamePlusPath[ftppathlen]='\0';
  7987. break;
  7988. }
  7989. i= i+1;
  7990. }
  7991. /* close */
  7992. pclose(fp);
  7993. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7994. {
  7995. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7996. {
  7997. fnamePlusPath[k]='\0';
  7998. }
  7999. }
  8000. i=1;
  8001. //char fname[60]={0};
  8002. while(i < ftppathlen)
  8003. {
  8004. int len=ftppathlen-i;
  8005. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8006. {
  8007. printf("compare '/' all right\n");
  8008. break;
  8009. }
  8010. i=i+1;
  8011. }
  8012. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8013. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8014. fnamePWithNoPath[i+1] = '\0';
  8015. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8016. {
  8017. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8018. {
  8019. fnamePWithNoPath[j]='\0';
  8020. }
  8021. }
  8022. FILE* fp1 = fopen(fnamePlusPath, "r");
  8023. if (fp1)
  8024. {
  8025. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8026. // file exists
  8027. fclose(fp1);
  8028. }
  8029. else
  8030. {
  8031. // file doesn't exist
  8032. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8033. }
  8034. }
  8035. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8036. {
  8037. mtrace();
  8038. int result = FAIL;
  8039. time_t CurrentTime;
  8040. struct tm *tm;
  8041. pthread_t th_Status;
  8042. CurrentTime = time(NULL);
  8043. tm = localtime(&CurrentTime);
  8044. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8045. 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);
  8046. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8047. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8048. return result;
  8049. }
  8050. void* GetDiagnosticsProcess(void* data)
  8051. {
  8052. pthread_detach(pthread_self());
  8053. mtrace();
  8054. int retriesInt=0, retryIntervalInt=0;
  8055. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8056. 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};
  8057. int port=0;
  8058. int isSuccess = FALSE;
  8059. char cmdBuf[2048];
  8060. struct tm *tmNow;
  8061. time_t CurrentTime;
  8062. struct tm tmStart;
  8063. struct tm tmStop;
  8064. CurrentTime = time(NULL);
  8065. tmNow=localtime(&CurrentTime);
  8066. uint16_t targetYear, targetMonth;
  8067. json_object *GetDiagnostics;
  8068. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8069. GetDiagnostics = json_tokener_parse(data);
  8070. if(!is_error(GetDiagnostics))
  8071. {
  8072. // Required data
  8073. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8074. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8075. // Optional data
  8076. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8077. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8078. else
  8079. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8080. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8081. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8082. else
  8083. retryIntervalInt = 30;
  8084. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8085. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8086. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8087. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8088. }
  8089. json_object_put(GetDiagnostics);
  8090. // Pack log to compress file
  8091. 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) &&
  8092. (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))
  8093. {
  8094. // Pack system log
  8095. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8096. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8097. targetYear = tmStart.tm_year;
  8098. targetMonth = tmStart.tm_mon;
  8099. do
  8100. {
  8101. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8102. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8103. if(targetMonth+1>=13)
  8104. {
  8105. targetYear += 1;
  8106. targetMonth = 1;
  8107. }
  8108. else
  8109. {
  8110. targetMonth += 1;
  8111. }
  8112. }while((targetYear < (tmNow->tm_year+1900)) ||
  8113. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8114. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8115. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8116. system(cmdBuf);
  8117. // Pack charging & event log
  8118. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8119. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8120. targetYear = tmStart.tm_year;
  8121. targetMonth = tmStart.tm_mon;
  8122. do
  8123. {
  8124. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8125. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8126. if(targetMonth+1>=13)
  8127. {
  8128. targetYear += 1;
  8129. targetMonth = 1;
  8130. }
  8131. else
  8132. {
  8133. targetMonth += 1;
  8134. }
  8135. }while((targetYear < (tmNow->tm_year+1900)) ||
  8136. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8137. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8138. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8139. system(cmdBuf);
  8140. // Combine log file
  8141. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8142. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8143. }
  8144. else
  8145. {
  8146. system("exec /root/logPackTools 'log' 6");
  8147. }
  8148. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8149. system(cmdBuf);
  8150. checkUploadLog();
  8151. //****************location*******************/
  8152. if(strcmp(locationstr,"")==0)
  8153. {
  8154. DEBUG_INFO("location is <Empty>!\n");
  8155. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8156. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8157. goto end;
  8158. }
  8159. memset(protocol, 0, ARRAY_SIZE(protocol));
  8160. memset(user, 0, ARRAY_SIZE(user) );
  8161. memset(password, 0, ARRAY_SIZE(password));
  8162. memset(host, 0, ARRAY_SIZE(host));
  8163. memset(path, 0, ARRAY_SIZE(path));
  8164. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8165. memset(host1, 0, ARRAY_SIZE(host1));
  8166. memset(path1, 0, ARRAY_SIZE(path1));
  8167. /*location: ftp://user:password@host:port/path*/
  8168. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8169. if((access(fnamePlusPath,F_OK))!=-1)
  8170. {
  8171. DEBUG_INFO("fnamePlusPath exist.\n");
  8172. }
  8173. else
  8174. {
  8175. DEBUG_INFO("fnamePlusPath not exist!\n");
  8176. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8177. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8178. goto end;
  8179. }
  8180. if(strchr(locationstr,'@')==NULL)
  8181. {
  8182. sscanf(locationstr,
  8183. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8184. protocol, host, &port, path);
  8185. strcpy(user,"anonymous");
  8186. strcpy(password,"");
  8187. }
  8188. else
  8189. {
  8190. //DEBUG_INFO("pch=%s\n", pch);
  8191. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8192. protocol, user, password, host, &port, path);
  8193. }
  8194. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8195. {
  8196. DEBUG_INFO("protocol is not ftp/http ! \n");
  8197. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8198. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8199. goto end;
  8200. }
  8201. if(strncmp(locationstr,"http", 4) == 0)
  8202. {
  8203. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8204. sprintf(ftppath,"/%s", path);
  8205. do
  8206. {
  8207. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8208. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8209. sleep(3);
  8210. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8211. if(!isSuccess)
  8212. {
  8213. DEBUG_INFO("Diagnostics fail.\n");
  8214. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8216. sleep(retryIntervalInt);
  8217. }
  8218. else
  8219. {
  8220. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8221. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8222. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8223. }
  8224. retriesInt--;
  8225. }while((isSuccess == 0)&&(retriesInt >= 0));
  8226. }
  8227. else
  8228. {
  8229. sscanf(host,"%[^/]%s",host1, path1);
  8230. if(strlen(path) > 0)
  8231. sprintf(ftppath,"/%s", path);
  8232. else
  8233. sprintf(ftppath,"/%s", path1);
  8234. int ftppathlen=strlen(ftppath);
  8235. int i=1;
  8236. char filenametemp[50];
  8237. while(i < ftppathlen)
  8238. {
  8239. int len=ftppathlen-i;
  8240. if(ftppath[len]== 47) // '/' ascll code: 47
  8241. {
  8242. DEBUG_INFO("find '/' all right\n");
  8243. break;
  8244. }
  8245. i=i+1;
  8246. }
  8247. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8248. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8249. filenametemp[i+1] = 0;
  8250. if(port == 0)
  8251. port = 21;
  8252. do
  8253. {
  8254. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8255. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8256. sleep(3);
  8257. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8258. if(!isSuccess)
  8259. {
  8260. DEBUG_INFO("Diagnostics fail.\n");
  8261. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8262. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8263. sleep(retryIntervalInt);
  8264. }
  8265. else
  8266. {
  8267. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8268. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8269. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8270. }
  8271. retriesInt--;
  8272. }while((!isSuccess)&&(retriesInt >= 0));
  8273. }
  8274. end:
  8275. system("rm -f /mnt/*");
  8276. sleep(5);
  8277. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8278. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8279. pthread_exit(NULL);
  8280. }
  8281. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8282. {
  8283. mtrace();
  8284. int result = FAIL;
  8285. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8286. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8287. {
  8288. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8289. locallistVersion = -1;
  8290. }
  8291. else
  8292. {
  8293. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8294. OCPP_getListVerion();
  8295. }
  8296. //from db.OCPP_getListVerion
  8297. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8298. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8299. sendGetLocalListVersionConfirmation(uuid,"");
  8300. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8301. return result;
  8302. }
  8303. int handleRemoteStartRequest(char *uuid, char *payload)
  8304. {
  8305. mtrace();
  8306. int result = FAIL;
  8307. int connectorIdInt=0;
  8308. int tempIndex = 0;
  8309. int connectorIdIsNULL, chargingProfileIsNULL;
  8310. char comfirmstr[20]={0};
  8311. char cmdBuf[512];
  8312. json_object *RemoteStartTransaction;
  8313. FILE *fp;
  8314. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8315. if(server_pending == TRUE)
  8316. {
  8317. return 0;
  8318. }
  8319. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8320. RemoteStartTransaction = json_tokener_parse(payload);
  8321. if(!is_error(RemoteStartTransaction))
  8322. {
  8323. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8324. {
  8325. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8326. if(connectorIdInt <= gunTotalNumber)
  8327. {
  8328. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8329. // Required data
  8330. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8331. // Optional data
  8332. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8333. {
  8334. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8335. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8336. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8337. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8338. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8339. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8340. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8341. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8342. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8343. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8344. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8345. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8346. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8347. {
  8348. 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")));
  8349. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8350. 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"));
  8351. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8352. 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"));
  8353. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8354. 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")));
  8355. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8356. {
  8357. 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++)
  8358. {
  8359. 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"));
  8360. 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"));
  8361. 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)
  8362. 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"));
  8363. }
  8364. }
  8365. }
  8366. }
  8367. else
  8368. chargingProfileIsNULL = TRUE;
  8369. }
  8370. }
  8371. else
  8372. connectorIdIsNULL = TRUE;
  8373. }
  8374. else
  8375. connectorIdIsNULL = TRUE;
  8376. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8377. {
  8378. DEBUG_WARN("Connector id is NULL\n.");
  8379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8380. goto end;
  8381. }
  8382. /*
  8383. enum _SYSTEM_STATUS
  8384. {
  8385. S_BOOTING = 0,
  8386. S_IDLE, = 1
  8387. S_AUTHORIZING, = 2
  8388. S_REASSIGN_CHECK, = 3
  8389. S_REASSIGN, = 4
  8390. S_PRECHARGE, = 5
  8391. S_PREPARING_FOR_EV, = 6
  8392. S_PREPARING_FOR_EVSE, = 7
  8393. S_CHARGING, = 8
  8394. S_TERMINATING, = 9
  8395. S_COMPLETE, = 10
  8396. S_ALARM, = 11
  8397. S_FAULT = 12
  8398. }
  8399. */
  8400. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8401. {
  8402. //check Transaction active
  8403. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8404. {
  8405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8406. {
  8407. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8408. }
  8409. else
  8410. {
  8411. tempIndex = connectorIdInt -1;
  8412. }
  8413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8414. {
  8415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8416. {
  8417. 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))
  8418. {
  8419. //Reserved
  8420. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8421. }
  8422. 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))
  8423. {
  8424. //Reserved
  8425. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8426. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8427. goto end;
  8428. }
  8429. else
  8430. {
  8431. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8432. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8433. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8434. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8435. {
  8436. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8438. goto end;
  8439. }
  8440. }//END FOR ELSE
  8441. }
  8442. }// END FOR CHAdeMO_QUANTITY
  8443. }
  8444. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8445. {
  8446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8447. {
  8448. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8449. }
  8450. else
  8451. {
  8452. tempIndex = connectorIdInt -1;
  8453. }
  8454. for (int index = 0; index < CCS_QUANTITY; index++)
  8455. {
  8456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8457. {
  8458. 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))
  8459. {
  8460. //Reserved
  8461. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8462. }
  8463. 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))
  8464. {
  8465. //Reserved
  8466. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8467. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8468. goto end;
  8469. }
  8470. else
  8471. {
  8472. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8473. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8474. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8475. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8476. {
  8477. DEBUG_WARN("CCS connector not allow start\n.");
  8478. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8479. goto end;
  8480. }
  8481. }// END FOR ELSE
  8482. }
  8483. }// END FOR CCS_QUANTITY
  8484. }
  8485. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8486. {
  8487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8488. {
  8489. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8490. }
  8491. else
  8492. {
  8493. tempIndex = connectorIdInt -1;
  8494. }
  8495. for (int index = 0; index < GB_QUANTITY; index++)
  8496. {
  8497. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8498. {
  8499. 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))
  8500. {
  8501. //Reserved
  8502. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8503. }
  8504. 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))
  8505. {
  8506. //Reserved
  8507. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8509. goto end;
  8510. }
  8511. else
  8512. {
  8513. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8514. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8515. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8516. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8517. {
  8518. DEBUG_WARN("GB connector not allow start\n.");
  8519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8520. goto end;
  8521. }
  8522. }// END FOR ELSE
  8523. }
  8524. } // END FOR GB_QUANTITY
  8525. }
  8526. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8527. {
  8528. tempIndex = connectorIdInt -1;
  8529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8530. {
  8531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8532. {
  8533. 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))
  8534. {
  8535. //Reserved
  8536. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8537. }
  8538. 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))
  8539. {
  8540. //Reserved
  8541. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8543. goto end;
  8544. }
  8545. else
  8546. {
  8547. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8548. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8549. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8550. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8551. {
  8552. DEBUG_WARN("GB connector not allow start\n.");
  8553. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8554. goto end;
  8555. }
  8556. }// END FOR ELSE
  8557. }
  8558. } // END FOR GB_QUANTITY
  8559. }
  8560. else
  8561. {
  8562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8563. {
  8564. tempIndex = 2;
  8565. }
  8566. else
  8567. {
  8568. tempIndex = connectorIdInt -1;
  8569. }
  8570. for (int index = 0; index < AC_QUANTITY; index++)
  8571. {
  8572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8573. {
  8574. 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))
  8575. {
  8576. //Reserved
  8577. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8578. }
  8579. 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))
  8580. {
  8581. //Reserved
  8582. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8584. goto end;
  8585. }
  8586. else
  8587. {
  8588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8589. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8590. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8591. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8592. {
  8593. DEBUG_WARN("AC connector not allow start\n.");
  8594. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8595. goto end;
  8596. }
  8597. }//END FOR ELSE
  8598. }
  8599. }// END FOR AC_QUANTITY
  8600. }
  8601. if(chargingProfileIsNULL == FALSE)
  8602. {
  8603. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8604. {
  8605. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8606. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8607. //memset idTag
  8608. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8609. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8610. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8611. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8612. // Save profile to file
  8613. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8614. system(cmdBuf);
  8615. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8616. fp = fopen(cmdBuf, "w");
  8617. 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));
  8618. fclose(fp);
  8619. }
  8620. else
  8621. {
  8622. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8623. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8624. }
  8625. }
  8626. else
  8627. {
  8628. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8630. //memset idTag
  8631. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8632. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8633. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8634. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8635. }
  8636. }
  8637. else
  8638. {
  8639. DEBUG_WARN("Connector id over\n.");
  8640. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8641. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8642. }
  8643. end:
  8644. json_object_put(RemoteStartTransaction);
  8645. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8646. {
  8647. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8648. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8649. }
  8650. //OCPP send RemoteStartConfirmation by first.
  8651. sendRemoteStartConfirmation(uuid, comfirmstr);
  8652. return result;
  8653. }
  8654. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8655. {
  8656. mtrace();
  8657. int result = FAIL;
  8658. int match = FALSE;
  8659. int GunNO = 0;
  8660. int tempIndex = 0;
  8661. int transactionIdInt=0;
  8662. int transactionIdIsNULL= TRUE;
  8663. char comfirmstr[20];
  8664. json_object *RemoteStopTransaction;
  8665. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8666. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8667. if(server_pending == TRUE)
  8668. {
  8669. return 0;
  8670. }
  8671. RemoteStopTransaction = json_tokener_parse(payload);
  8672. if(!is_error(RemoteStopTransaction))
  8673. {
  8674. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8675. {
  8676. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8677. transactionIdIsNULL = FALSE;
  8678. }
  8679. }
  8680. json_object_put(RemoteStopTransaction);
  8681. if(transactionIdIsNULL == FALSE)
  8682. {
  8683. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8684. {
  8685. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8686. {
  8687. //check Transaction active
  8688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8689. {
  8690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8691. {
  8692. tempIndex = ((gun_index==2) ? 1: 0);
  8693. }
  8694. else
  8695. {
  8696. tempIndex = gun_index;
  8697. }
  8698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8699. {
  8700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8701. {
  8702. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8703. {
  8704. match = TRUE;
  8705. GunNO = gun_index;
  8706. }
  8707. }
  8708. }// END FOR CHAdeMO_QUANTITY
  8709. }
  8710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8711. {
  8712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8713. {
  8714. tempIndex = ((gun_index==2) ? 1: 0);
  8715. }
  8716. else
  8717. {
  8718. tempIndex = gun_index;
  8719. }
  8720. for (int index = 0; index < CCS_QUANTITY; index++)
  8721. {
  8722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8723. {
  8724. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8725. {
  8726. match = TRUE;
  8727. GunNO = gun_index;
  8728. }
  8729. }
  8730. }// END FOR CCS_QUANTITY
  8731. }
  8732. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8733. {
  8734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8735. {
  8736. tempIndex = ((gun_index==2) ? 1: 0);
  8737. }
  8738. else
  8739. {
  8740. tempIndex = gun_index;
  8741. }
  8742. for (int index = 0; index < GB_QUANTITY; index++)
  8743. {
  8744. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8745. {
  8746. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8747. {
  8748. match = TRUE;
  8749. GunNO = gun_index;
  8750. }
  8751. }
  8752. }// END FOR GB_QUANTITY
  8753. }
  8754. else if(gunType[gun_index] == GUN_TYPE_DO)
  8755. {
  8756. tempIndex = gun_index;
  8757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8758. {
  8759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8760. {
  8761. 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
  8762. {
  8763. match = TRUE;
  8764. GunNO = gun_index;
  8765. }
  8766. }
  8767. }// END FOR GB_QUANTITY
  8768. }
  8769. else
  8770. {
  8771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8772. {
  8773. tempIndex = 2;
  8774. }
  8775. else
  8776. {
  8777. tempIndex = gun_index;
  8778. }
  8779. for (int index = 0; index < AC_QUANTITY; index++)
  8780. {
  8781. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8782. {
  8783. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8784. {
  8785. match = TRUE;
  8786. GunNO = gun_index;
  8787. }
  8788. }
  8789. }// END FOR CHAdeMO_QUANTITY
  8790. } // END FOR AC ELSE
  8791. }// CHECK IF ResponseTransactionId == transactionIdInt
  8792. }//END FOR
  8793. if( match == TRUE)
  8794. {
  8795. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8796. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8797. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8798. }
  8799. else
  8800. {
  8801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8802. }
  8803. }
  8804. else
  8805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8806. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8807. return result;
  8808. }
  8809. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8810. {
  8811. mtrace();
  8812. int result = FAIL;
  8813. int connectorIdInt=0, reservationIdInt=0;
  8814. int tempIndex = 0;
  8815. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8816. char comfirmstr[20]={0};
  8817. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8818. int c = 0;
  8819. char *loc;
  8820. //char *ptr;
  8821. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8822. strcpy(sstrtemp, stringtrimspace(payload));
  8823. //***(1)connectorId ****/
  8824. c=0;
  8825. loc = strstr(sstrtemp, "connectorId");
  8826. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8827. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8828. {
  8829. sstr[c] = loc[strlen("connectorId")+2+c];
  8830. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8831. c++;
  8832. }
  8833. sstr[c] = '\0';
  8834. connectorIdInt = atoi(sstr);
  8835. //***(2)expiryDate ****/
  8836. loc = strstr(sstrtemp, "expiryDate");
  8837. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8838. c = 0;
  8839. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8840. {
  8841. sstr[c] = loc[3+strlen("expiryDate")+c];
  8842. c++;
  8843. }
  8844. sstr[c] = '\0';
  8845. strcpy(expiryDatestr, sstr);
  8846. //***(3)idTag ****/
  8847. loc = strstr(sstrtemp, "idTag");
  8848. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8849. c = 0;
  8850. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8851. {
  8852. sstr[c] = loc[3+strlen("idTag")+c];
  8853. c++;
  8854. }
  8855. sstr[c] = '\0';
  8856. strcpy(idTagstr, sstr);
  8857. //***(4)parentIdTag ****/
  8858. loc = strstr(sstrtemp, "parentIdTag");
  8859. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8860. c = 0;
  8861. if(loc == NULL)
  8862. {
  8863. strcpy(parentIdTagstr, "");
  8864. }
  8865. else
  8866. {
  8867. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8868. {
  8869. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8870. c++;
  8871. }
  8872. sstr[c] = '\0';
  8873. strcpy(parentIdTagstr, sstr);
  8874. }
  8875. //***(5)reservationId ****/
  8876. c=0;
  8877. loc = strstr(sstrtemp, "reservationId");
  8878. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8879. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8880. {
  8881. sstr[c] = loc[strlen("reservationId")+2+c];
  8882. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8883. c++;
  8884. }
  8885. sstr[c] = '\0';
  8886. reservationIdInt = atoi(sstr);
  8887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8888. /*
  8889. enum SYSTEM_STATUS
  8890. {
  8891. SYS_MODE_BOOTING = 0,
  8892. SYS_MODE_IDLE = 1,
  8893. SYS_MODE_AUTHORIZING = 2,
  8894. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8895. SYS_MODE_REASSIGN = 4,
  8896. SYS_MODE_PREPARING = 5,
  8897. SYS_MODE_PREPARE_FOR_EV = 6,
  8898. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8899. SYS_MODE_CHARGING = 8,
  8900. SYS_MODE_TERMINATING = 9,
  8901. SYS_MODE_COMPLETE = 10,
  8902. SYS_MODE_ALARM = 11,
  8903. SYS_MODE_FAULT = 12,
  8904. SYS_MODE_RESERVATION = 13,
  8905. SYS_MODE_BOOKING = 14,
  8906. SYS_MODE_MAINTAIN = 15,
  8907. SYS_MODE_DEBUG = 16,
  8908. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8909. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8910. SYS_MODE_UPDATE = 19
  8911. };
  8912. */
  8913. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8914. {
  8915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8916. goto end;
  8917. }
  8918. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8919. {
  8920. //check Transaction active
  8921. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8922. {
  8923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8924. {
  8925. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8926. }
  8927. else
  8928. {
  8929. tempIndex = connectorIdInt -1;
  8930. }
  8931. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8932. {
  8933. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8934. {
  8935. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8936. {
  8937. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8938. {
  8939. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8940. {
  8941. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8943. }
  8944. 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'))
  8945. {
  8946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8947. }
  8948. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8949. {
  8950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8951. }
  8952. else
  8953. {
  8954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8955. }
  8956. }
  8957. 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
  8958. {
  8959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8960. }
  8961. }
  8962. else
  8963. {
  8964. //replace reservation
  8965. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8967. }
  8968. }
  8969. } // END FOR CHAdeMO_QUANTITY
  8970. }
  8971. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8972. {
  8973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8974. {
  8975. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8976. }
  8977. else
  8978. {
  8979. tempIndex = connectorIdInt -1;
  8980. }
  8981. for (int index = 0; index < CCS_QUANTITY; index++)
  8982. {
  8983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8984. {
  8985. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8986. {
  8987. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8988. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8989. {
  8990. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8991. {
  8992. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8994. }
  8995. 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'))
  8996. {
  8997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8998. }
  8999. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9000. {
  9001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9002. }
  9003. else
  9004. {
  9005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9006. }
  9007. }
  9008. 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
  9009. {
  9010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9011. }
  9012. }
  9013. else
  9014. {
  9015. //replace reservation
  9016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9018. }
  9019. }
  9020. } // END FOR CCS_QUANTITY
  9021. }
  9022. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9023. {
  9024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9025. {
  9026. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9027. }
  9028. else
  9029. {
  9030. tempIndex = connectorIdInt -1;
  9031. }
  9032. for (int index = 0; index < GB_QUANTITY; index++)
  9033. {
  9034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9035. {
  9036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9037. {
  9038. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9039. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9040. {
  9041. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9042. {
  9043. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9045. }
  9046. 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'))
  9047. {
  9048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9049. }
  9050. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9051. {
  9052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9053. }
  9054. else
  9055. {
  9056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9057. }
  9058. }
  9059. 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
  9060. {
  9061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9062. }
  9063. }
  9064. else
  9065. {
  9066. //replace reservation
  9067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9069. }
  9070. }
  9071. }// END FOR GB_QUANTITY
  9072. }
  9073. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9074. {
  9075. tempIndex = connectorIdInt -1;
  9076. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9077. {
  9078. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9079. {
  9080. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9081. {
  9082. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9083. 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
  9084. {
  9085. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9086. {
  9087. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9089. }
  9090. 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'))
  9091. {
  9092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9093. }
  9094. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9095. {
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9097. }
  9098. else
  9099. {
  9100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9101. }
  9102. }
  9103. 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
  9104. {
  9105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9106. }
  9107. }
  9108. else
  9109. {
  9110. //replace reservation
  9111. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9113. }
  9114. }
  9115. }// END FOR GB_QUANTITY
  9116. }
  9117. else
  9118. {
  9119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9120. {
  9121. tempIndex = 2;
  9122. }
  9123. else
  9124. {
  9125. tempIndex = (connectorIdInt -1);
  9126. }
  9127. for (int index = 0; index < AC_QUANTITY; index++)
  9128. {
  9129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9130. {
  9131. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9132. {
  9133. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9134. {
  9135. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9136. {
  9137. 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))
  9138. {
  9139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9140. }
  9141. else
  9142. {
  9143. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9145. }
  9146. }
  9147. 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'))
  9148. {
  9149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9150. }
  9151. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9152. {
  9153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9154. }
  9155. else
  9156. {
  9157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9158. }
  9159. }
  9160. 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
  9161. {
  9162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9163. }
  9164. }
  9165. else
  9166. {
  9167. //replace reservation
  9168. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9170. }
  9171. }
  9172. } // END FOR AC_QUANTITY
  9173. }
  9174. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9175. }
  9176. else if(connectorIdInt == 0)
  9177. {
  9178. //check Transaction active
  9179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9180. {
  9181. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9182. {
  9183. 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'))
  9184. {
  9185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9186. goto end;
  9187. }
  9188. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9189. {
  9190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9191. goto end;
  9192. }
  9193. 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
  9194. {
  9195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9196. goto end;
  9197. }
  9198. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9199. {
  9200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9201. goto end;
  9202. }
  9203. }
  9204. }// END FOR CHAdeMO_QUANTITY
  9205. for (int index = 0; index < CCS_QUANTITY; index++)
  9206. {
  9207. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9208. {
  9209. 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'))
  9210. {
  9211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9212. goto end;
  9213. }
  9214. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9215. {
  9216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9217. goto end;
  9218. }
  9219. 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
  9220. {
  9221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9222. goto end;
  9223. }
  9224. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9225. {
  9226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9227. goto end;
  9228. }
  9229. }
  9230. } // END FOR CCS_QUANTITY
  9231. for (int index = 0; index < GB_QUANTITY; index++)
  9232. {
  9233. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9234. {
  9235. 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'))
  9236. {
  9237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9238. goto end;
  9239. }
  9240. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9241. {
  9242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9243. goto end;
  9244. }
  9245. 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
  9246. {
  9247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9248. goto end;
  9249. }
  9250. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9251. {
  9252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9253. goto end;
  9254. }
  9255. }
  9256. } // END FOR GB_QUANTITY
  9257. for (int index = 0; index < AC_QUANTITY; index++)
  9258. {
  9259. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9260. {
  9261. 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'))
  9262. {
  9263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9264. goto end;
  9265. }
  9266. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9267. {
  9268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9269. goto end;
  9270. }
  9271. 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
  9272. {
  9273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9274. goto end;
  9275. }
  9276. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9277. {
  9278. 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))
  9279. {
  9280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9281. goto end;
  9282. }
  9283. }
  9284. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9285. {
  9286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9287. goto end;
  9288. }
  9289. }
  9290. }// END FOR AC_QUANTITY
  9291. //The connectorId is 0
  9292. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9294. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9295. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9296. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9297. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9298. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9299. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9300. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9301. result = TRUE;
  9302. return result;
  9303. }
  9304. else
  9305. {
  9306. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9307. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9308. }
  9309. if(strcmp(comfirmstr,"Accepted") == 0)
  9310. {
  9311. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9312. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9313. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9314. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9315. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9316. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9317. result = TRUE;
  9318. return result;
  9319. }
  9320. end:
  9321. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9322. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9323. return result;
  9324. }
  9325. int handleResetRequest(char *uuid, char *payload)
  9326. {
  9327. mtrace();
  9328. int result = FAIL;
  9329. char sstr[10]={0},sstrtemp[30]={ 0 };
  9330. char typestr[10]={0};
  9331. char comfirmstr[20]={0};
  9332. int c = 0;
  9333. char *loc;
  9334. DEBUG_INFO("handleResetRequest...\n");
  9335. strcpy(sstrtemp, stringtrimspace(payload));
  9336. loc = strstr(sstrtemp, "type");
  9337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9338. c = 0;
  9339. while (loc[3+strlen("type")+c] != '\"')
  9340. {
  9341. sstr[c] = loc[3+strlen("type")+c];
  9342. c++;
  9343. }
  9344. sstr[c] = '\0';
  9345. strcpy(typestr,sstr);
  9346. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9347. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9348. {
  9349. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9350. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9351. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9352. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9353. }
  9354. else
  9355. {
  9356. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9357. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9358. result = PASS;
  9359. }
  9360. sendResetConfirmation(uuid, comfirmstr);
  9361. return result;
  9362. }
  9363. int handleSendLocalListRequest(char *uuid, char *payload)
  9364. {
  9365. mtrace();
  9366. int result = FAIL;
  9367. char comfirmstr[20];
  9368. int checkState_Faulted = FALSE;
  9369. json_object *SendLocalList;
  9370. DEBUG_INFO("handleSendLocalListRequest...\n");
  9371. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9372. {
  9373. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9374. goto end;
  9375. }
  9376. //check Charge Point state
  9377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9378. {
  9379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9380. {
  9381. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9382. }
  9383. }
  9384. for (int index = 0; index < CCS_QUANTITY; index++)
  9385. {
  9386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9387. {
  9388. checkState_Faulted = TRUE; //OCPP Status
  9389. }
  9390. }
  9391. for (int index = 0; index < GB_QUANTITY; index++)
  9392. {
  9393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9394. {
  9395. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9396. }
  9397. }
  9398. //check Charge Point state
  9399. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9400. {
  9401. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9402. {
  9403. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9404. }
  9405. }
  9406. //check Charge Point state
  9407. for (int index = 0; index < AC_QUANTITY; index++)
  9408. {
  9409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9410. {
  9411. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9412. }
  9413. }
  9414. if(checkState_Faulted == TRUE)
  9415. {
  9416. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9417. goto end;
  9418. }
  9419. // Parsing payload
  9420. SendLocalList = json_tokener_parse(payload);
  9421. if(!is_error(SendLocalList))
  9422. {
  9423. // Required data
  9424. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9425. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9426. // Optional data
  9427. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9428. {
  9429. //Check UpdateType
  9430. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9431. {
  9432. //Local list full update
  9433. DEBUG_INFO("Local list full update.\n");
  9434. OCPP_getListVerion();
  9435. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9436. {
  9437. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9438. goto end;
  9439. }
  9440. OCPP_cleanLocalList();
  9441. }
  9442. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9443. {
  9444. //Local list different update
  9445. DEBUG_INFO("Local list different update.\n");
  9446. OCPP_getListVerion();
  9447. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9448. {
  9449. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9450. goto end;
  9451. }
  9452. }
  9453. else
  9454. {
  9455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9456. goto end;
  9457. }
  9458. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9459. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9460. {
  9461. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9462. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9463. {
  9464. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9465. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9466. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9467. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9468. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9469. }
  9470. // Add to db
  9471. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9472. {
  9473. //Local list full update
  9474. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9475. idx,
  9476. ShmOCPP16Data->SendLocalList.ListVersion,
  9477. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9478. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9479. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9480. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9481. // update list
  9482. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9483. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9484. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9485. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9486. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9487. }
  9488. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9489. {
  9490. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9491. idx,
  9492. ShmOCPP16Data->SendLocalList.ListVersion,
  9493. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9494. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9495. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9496. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9497. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9498. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9499. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9500. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9501. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9502. }
  9503. }
  9504. }
  9505. else
  9506. {
  9507. //Check UpdateType
  9508. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9509. {
  9510. //Local list full update
  9511. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9512. OCPP_cleanLocalList();
  9513. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9514. goto end;
  9515. }
  9516. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9517. {
  9518. //Local list different update
  9519. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9520. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9521. goto end;
  9522. }
  9523. }
  9524. result = PASS;
  9525. }
  9526. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9527. end:
  9528. json_object_put(SendLocalList);
  9529. sendSendLocalListConfirmation(uuid, comfirmstr);
  9530. return result;
  9531. }
  9532. #define MAX 200
  9533. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9534. {
  9535. mtrace();
  9536. int result = FAIL;
  9537. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9538. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9539. char chargingProfilePurposeStr[30]={0};
  9540. char chargingProfileKindStr[16]={0};
  9541. char recurrencyKindStr[10]={0};
  9542. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9543. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9544. int chargingSchedulePeriodCount = 0;
  9545. char comfirmstr[20]={0};
  9546. int meet= FALSE;
  9547. FILE *fptr1;
  9548. char filename[MAX]={0};
  9549. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9550. char rmFileCmd[50]={0};
  9551. char tempchargingProfilePurposeStr[30]={0};
  9552. char word[1600]={0};
  9553. int n_chargingProfile = 0;
  9554. json_object *SetChargingProfile;
  9555. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9556. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9557. SetChargingProfile = json_tokener_parse(payload);
  9558. if(!is_error(SetChargingProfile))
  9559. {
  9560. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9561. {
  9562. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9563. if(connectorIdInt == 0)
  9564. {
  9565. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9566. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9567. }
  9568. else
  9569. {
  9570. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9571. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9572. }
  9573. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9574. }
  9575. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9576. {
  9577. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9578. {
  9579. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9580. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9581. {
  9582. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9583. }
  9584. else
  9585. {
  9586. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9587. }
  9588. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9589. }
  9590. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9591. {
  9592. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9593. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9594. {
  9595. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9596. }
  9597. else
  9598. {
  9599. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9600. }
  9601. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9602. }
  9603. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9604. {
  9605. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9606. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9607. {
  9608. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9609. }
  9610. else
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9613. }
  9614. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9615. }
  9616. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9617. {
  9618. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9619. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9620. {
  9621. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9622. }
  9623. else
  9624. {
  9625. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9626. }
  9627. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9628. }
  9629. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9630. {
  9631. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9632. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9633. {
  9634. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9635. }
  9636. else
  9637. {
  9638. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9639. }
  9640. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9641. }
  9642. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9643. {
  9644. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9645. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9646. {
  9647. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9648. }
  9649. else
  9650. {
  9651. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9652. }
  9653. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9654. }
  9655. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9656. {
  9657. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9658. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9659. {
  9660. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9661. }
  9662. else
  9663. {
  9664. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9665. }
  9666. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9667. }
  9668. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9669. {
  9670. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9671. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9672. {
  9673. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9674. }
  9675. else
  9676. {
  9677. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9678. }
  9679. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9680. }
  9681. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9682. {
  9683. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9684. {
  9685. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9689. }
  9690. else
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9693. }
  9694. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9695. }
  9696. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9697. {
  9698. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9699. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9700. {
  9701. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9702. }
  9703. else
  9704. {
  9705. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9706. }
  9707. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9708. }
  9709. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9710. {
  9711. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9712. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9713. {
  9714. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9715. }
  9716. else
  9717. {
  9718. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9719. }
  9720. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9721. }
  9722. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9723. {
  9724. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9725. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9726. {
  9727. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9728. }
  9729. else
  9730. {
  9731. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9732. }
  9733. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9734. }
  9735. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9736. {
  9737. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9738. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9739. if(chargingSchedulePeriodCount <= 10)
  9740. {
  9741. 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++)
  9742. {
  9743. 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)
  9744. {
  9745. 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"));
  9746. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9747. {
  9748. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9749. }
  9750. else
  9751. {
  9752. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9753. }
  9754. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9755. }
  9756. 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)
  9757. {
  9758. 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"));
  9759. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9760. {
  9761. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9762. }
  9763. else
  9764. {
  9765. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9766. }
  9767. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9768. }
  9769. 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)
  9770. {
  9771. 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"));
  9772. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9773. {
  9774. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9775. }
  9776. else
  9777. {
  9778. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9779. }
  9780. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9781. }
  9782. }
  9783. }
  9784. }
  9785. }
  9786. }
  9787. }
  9788. json_object_put(SetChargingProfile);
  9789. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9790. {
  9791. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9792. goto end;
  9793. }
  9794. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9795. {
  9796. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9797. if(connectorIdInt != 0)
  9798. {
  9799. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9800. goto end;
  9801. }
  9802. strcpy(filename, ChargePointMaxProfile_JSON );
  9803. fptr1 = fopen(filename, "r");
  9804. if (!fptr1)
  9805. {
  9806. //file not exist
  9807. DEBUG_INFO("Unable to open the input file!!\n");
  9808. fptr1 = fopen(filename, "w+");
  9809. }
  9810. else
  9811. {
  9812. //Check Charging Profile Count
  9813. while(fscanf(fptr1, "%s", word) != EOF)
  9814. {
  9815. //DEBUG_INFO("word=%s\n",word);
  9816. if(strstr(word, "chargingProfileId")!= NULL)
  9817. {
  9818. //DEBUG_INFO("test chargingProfileId \n");
  9819. n_chargingProfile = n_chargingProfile + 1;
  9820. //DEBUG_INFO("chargingProfileId Found\n");
  9821. }
  9822. }
  9823. }
  9824. fclose(fptr1);
  9825. }
  9826. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9827. {
  9828. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9829. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9830. {
  9831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9832. goto end;
  9833. }
  9834. memset(filename, 0, ARRAY_SIZE(filename));
  9835. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9836. fptr1 = fopen(filename, "r");
  9837. if (!fptr1)
  9838. {
  9839. //file not exist
  9840. //DEBUG_INFO("Unable to open the input file!!\n");
  9841. fptr1 = fopen(filename, "w+");
  9842. }
  9843. else
  9844. {
  9845. //Check Charging Profile Count
  9846. while(fscanf(fptr1, "%s", word) != EOF)
  9847. {
  9848. //DEBUG_INFO("word=%s\n",word);
  9849. if(strstr(word, "chargingProfileId")!= NULL)
  9850. {
  9851. //DEBUG_INFO("test chargingProfileId \n");
  9852. n_chargingProfile = n_chargingProfile + 1;
  9853. //DEBUG_INFO("chargingProfileId Found\n");
  9854. }
  9855. }
  9856. }
  9857. fclose(fptr1);
  9858. }
  9859. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9860. {
  9861. //printf("set chargingProfile 1-4\n");
  9862. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9863. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9864. if(connectorIdInt == 0)
  9865. {
  9866. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9867. goto end;
  9868. }
  9869. int tempIndex = 0;
  9870. //check Transaction active
  9871. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9872. {
  9873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9874. {
  9875. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9876. }
  9877. else
  9878. {
  9879. tempIndex = connectorIdInt -1;
  9880. }
  9881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9882. {
  9883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9884. {
  9885. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9886. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9887. {
  9888. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9889. {
  9890. meet = TRUE;
  9891. break;
  9892. }
  9893. }
  9894. }
  9895. }
  9896. }
  9897. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9898. {
  9899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9900. {
  9901. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9902. }
  9903. else
  9904. {
  9905. tempIndex = connectorIdInt -1;
  9906. }
  9907. for (int index = 0; index < CCS_QUANTITY; index++)
  9908. {
  9909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9910. {
  9911. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9912. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9913. {
  9914. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9915. {
  9916. meet = TRUE;
  9917. break;
  9918. }
  9919. }
  9920. }
  9921. }
  9922. }
  9923. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9924. {
  9925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9926. {
  9927. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9928. }
  9929. else
  9930. {
  9931. tempIndex = connectorIdInt -1;
  9932. }
  9933. for (int index = 0; index < GB_QUANTITY; index++)
  9934. {
  9935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9936. {
  9937. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9938. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9939. {
  9940. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9941. {
  9942. meet = TRUE;
  9943. break;
  9944. }
  9945. }
  9946. }
  9947. }
  9948. }
  9949. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9950. {
  9951. tempIndex = connectorIdInt -1;
  9952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9953. {
  9954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9955. {
  9956. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9957. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9958. {
  9959. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9960. {
  9961. meet = TRUE;
  9962. break;
  9963. }
  9964. }
  9965. }
  9966. }
  9967. }
  9968. else
  9969. {
  9970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9971. {
  9972. tempIndex = 2;
  9973. }
  9974. else
  9975. {
  9976. tempIndex = (connectorIdInt -1);
  9977. }
  9978. for (int index = 0; index < AC_QUANTITY; index++)
  9979. {
  9980. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9981. {
  9982. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9983. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9984. {
  9985. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9986. {
  9987. meet = TRUE;
  9988. break;
  9989. }
  9990. }
  9991. }
  9992. }
  9993. }
  9994. //check Transaction active
  9995. if(meet == FALSE)
  9996. {
  9997. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9998. goto end;
  9999. }
  10000. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10001. {
  10002. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10003. goto end;
  10004. }
  10005. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10006. fptr1 = fopen(filename, "r");
  10007. if (!fptr1)
  10008. {
  10009. //file not exist
  10010. DEBUG_INFO("Unable to open the input file!!\n");
  10011. fptr1 = fopen(filename, "w+");
  10012. }
  10013. else
  10014. {
  10015. //Check Charging Profile Count
  10016. while(fscanf(fptr1, "%s", word) != EOF)
  10017. {
  10018. //DEBUG_INFO("word=%s\n",word);
  10019. if(strstr(word, "chargingProfileId")!= NULL)
  10020. {
  10021. //DEBUG_INFO("test chargingProfileId \n");
  10022. n_chargingProfile = n_chargingProfile + 1;
  10023. //DEBUG_INFO("chargingProfileId Found\n");
  10024. }
  10025. }
  10026. }
  10027. fclose(fptr1);
  10028. }
  10029. // Check ChargeProfileMaxStackLevel
  10030. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10031. {
  10032. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10033. goto end;
  10034. }
  10035. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10036. {
  10037. int i = 0;
  10038. char fnametemp[200]={0};
  10039. n_chargingProfile = 0;
  10040. //Check ChargePointMaxProfile.json exit
  10041. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10042. {
  10043. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10044. //Check Charging Profile Count
  10045. while(fscanf(fptr1, "%s", word) != EOF)
  10046. {
  10047. //DEBUG_INFO("word=%s\n",word);
  10048. if(strstr(word, "chargingProfileId")!= NULL)
  10049. {
  10050. //DEBUG_INFO("test chargingProfileId \n");
  10051. n_chargingProfile = n_chargingProfile + 1;
  10052. i = i + 1;
  10053. //DEBUG_INFO("chargingProfileId Found\n");
  10054. }
  10055. memset(word, 0, ARRAY_SIZE(word));
  10056. }
  10057. fclose(fptr1);
  10058. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10059. }
  10060. //Check TxDefaultProfile_0.json exit
  10061. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10062. {
  10063. i = 0;
  10064. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10065. //Check Charging Profile Count
  10066. while(fscanf(fptr1, "%s", word) != EOF)
  10067. {
  10068. //DEBUG_INFO("word=%s\n",word);
  10069. if(strstr(word, "chargingProfileId")!= NULL)
  10070. {
  10071. //DEBUG_INFO("test chargingProfileId \n");
  10072. n_chargingProfile = n_chargingProfile + 1;
  10073. i = i + 1;
  10074. //DEBUG_INFO("chargingProfileId Found\n");
  10075. }
  10076. memset(word, 0, ARRAY_SIZE(word));
  10077. }
  10078. fclose(fptr1);
  10079. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10080. }
  10081. //Check TxDefaultProfile_%d.json
  10082. for(int j=1; j <= gunTotalNumber; j++)
  10083. {
  10084. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10085. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10086. if((access(fnametemp,F_OK))!=-1)
  10087. {
  10088. i = 0;
  10089. fptr1 = fopen(fnametemp, "r");
  10090. //Check Charging Profile Count
  10091. while(fscanf(fptr1, "%s", word) != EOF)
  10092. {
  10093. //DEBUG_INFO("word=%s\n",word);
  10094. if(strstr(word, "chargingProfileId")!= NULL)
  10095. {
  10096. //DEBUG_INFO("test chargingProfileId \n");
  10097. n_chargingProfile = n_chargingProfile + 1;
  10098. i = i + 1;
  10099. //DEBUG_INFO("chargingProfileId Found\n");
  10100. }
  10101. memset(word, 0, ARRAY_SIZE(word));
  10102. }
  10103. fclose(fptr1);
  10104. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10105. }
  10106. }
  10107. //Check TxProfile_%d.json
  10108. for(int j=1; j <= gunTotalNumber; j++)
  10109. {
  10110. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10111. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10112. if((access(fnametemp,F_OK))!=-1)
  10113. {
  10114. i = 0;
  10115. fptr1 = fopen(fnametemp, "r");
  10116. //Check Charging Profile Count
  10117. while(fscanf(fptr1, "%s", word) != EOF)
  10118. {
  10119. //DEBUG_INFO("word=%s\n",word);
  10120. if(strstr(word, "chargingProfileId")!= NULL)
  10121. {
  10122. //DEBUG_INFO("test chargingProfileId \n");
  10123. n_chargingProfile = n_chargingProfile + 1;
  10124. i = i + 1;
  10125. //DEBUG_INFO("chargingProfileId Found\n");
  10126. }
  10127. memset(word, 0, ARRAY_SIZE(word));
  10128. }
  10129. fclose(fptr1);
  10130. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10131. }
  10132. }
  10133. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10134. {
  10135. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10136. goto end;
  10137. }
  10138. }
  10139. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10140. //**********************************Write to File********************************************************/
  10141. FILE *infile;
  10142. FILE *outfile;
  10143. infile = fopen (filename, "r");
  10144. outfile = fopen (tempfile, "w");
  10145. int d =0;
  10146. d = fgetc(infile);
  10147. rewind(infile);
  10148. if(d == EOF)
  10149. {
  10150. // Profile is empty
  10151. fprintf(outfile,"%s\n",payload);
  10152. fclose(infile);
  10153. fclose(outfile);
  10154. sprintf(rmFileCmd,"rm -f %s",filename);
  10155. system(rmFileCmd);
  10156. rename(tempfile, filename);
  10157. }
  10158. else
  10159. {
  10160. // Profile is not empty
  10161. char buf[2048]={0};
  10162. int ChargingProfileAdded = FALSE;
  10163. while (fgets(buf, sizeof(buf), infile) != NULL)
  10164. {
  10165. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10166. json_object *tmpChargingProfile;
  10167. tmpChargingProfile = json_tokener_parse(buf);
  10168. if(!is_error(SetChargingProfile))
  10169. {
  10170. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10171. {
  10172. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10173. }
  10174. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10175. {
  10176. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10177. {
  10178. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10179. }
  10180. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10181. {
  10182. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10183. }
  10184. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10185. {
  10186. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10187. }
  10188. }
  10189. }
  10190. json_object_put(tmpChargingProfile);
  10191. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10192. {
  10193. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10194. {
  10195. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10196. if(ChargingProfileAdded == FALSE)
  10197. {
  10198. fprintf(outfile,"%s\n",payload);
  10199. ChargingProfileAdded = TRUE;
  10200. }
  10201. }
  10202. else
  10203. {
  10204. if(tempstackLevelInt < stackLevelInt)
  10205. {
  10206. if(ChargingProfileAdded == FALSE)
  10207. {
  10208. fprintf(outfile,"%s\n",buf);
  10209. fprintf(outfile,"%s\n",payload);
  10210. ChargingProfileAdded = TRUE;
  10211. }
  10212. else
  10213. {
  10214. fprintf(outfile,"%s\n",buf);
  10215. }
  10216. }
  10217. else
  10218. {
  10219. if(ChargingProfileAdded == FALSE)
  10220. {
  10221. fprintf(outfile,"%s\n",buf);
  10222. fprintf(outfile,"%s\n",payload);
  10223. ChargingProfileAdded = TRUE;
  10224. }
  10225. else
  10226. {
  10227. fprintf(outfile,"%s\n",buf);
  10228. }
  10229. }
  10230. }
  10231. }
  10232. else
  10233. {
  10234. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10235. {
  10236. if(ChargingProfileAdded == FALSE)
  10237. {
  10238. fprintf(outfile,"%s\n",buf);
  10239. fprintf(outfile,"%s\n",payload);
  10240. ChargingProfileAdded = TRUE;
  10241. }
  10242. else
  10243. {
  10244. fprintf(outfile,"%s\n",buf);
  10245. }
  10246. }
  10247. else if(tempstackLevelInt < stackLevelInt)
  10248. {
  10249. if(ChargingProfileAdded == FALSE)
  10250. {
  10251. fprintf(outfile,"%s\n",buf);
  10252. fprintf(outfile,"%s\n",payload);
  10253. ChargingProfileAdded = TRUE;
  10254. }
  10255. else
  10256. {
  10257. fprintf(outfile,"%s\n",buf);
  10258. }
  10259. }
  10260. else
  10261. {
  10262. if(ChargingProfileAdded == FALSE)
  10263. {
  10264. fprintf(outfile,"%s\n",buf);
  10265. fprintf(outfile,"%s\n",payload);
  10266. ChargingProfileAdded = TRUE;
  10267. }
  10268. else
  10269. {
  10270. fprintf(outfile,"%s\n",buf);
  10271. }
  10272. }
  10273. }
  10274. } // end of while loop
  10275. fclose(infile);
  10276. fclose(outfile);
  10277. sprintf(rmFileCmd,"rm -f %s",filename);
  10278. system(rmFileCmd);
  10279. rename(tempfile, filename);
  10280. }
  10281. sleep(1);
  10282. result = TRUE;
  10283. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10284. end:
  10285. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10286. {
  10287. if(connectorIdInt == 0)
  10288. {
  10289. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10290. {
  10291. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10292. }
  10293. }
  10294. else
  10295. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10296. }
  10297. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10298. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10299. return result;
  10300. }
  10301. int handleTriggerMessageRequest(char *uuid, char *payload)
  10302. {
  10303. mtrace();
  10304. int result = FAIL;
  10305. int connectorIdIsNULL = FALSE;
  10306. int connectorIdInt =0;
  10307. char sstr[40]={0},sstrtemp[100]={ 0 };
  10308. char requestedMessagestr[40]={0};
  10309. char comfirmstr[20]={0};
  10310. int c = 0;
  10311. char *loc;
  10312. DEBUG_INFO("handleTriggerMessageRequest\n");
  10313. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10314. strcpy(sstrtemp, stringtrimspace(payload));
  10315. c = 0;
  10316. loc = strstr(sstrtemp, "requestedMessage");
  10317. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10318. {
  10319. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10320. c++;
  10321. }
  10322. sstr[c] = '\0';
  10323. strcpy(requestedMessagestr, sstr);
  10324. c = 0;
  10325. loc = strstr(sstrtemp, "connectorId");
  10326. if(loc == NULL)
  10327. {
  10328. connectorIdIsNULL = TRUE;
  10329. }
  10330. else
  10331. {
  10332. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10333. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10334. {
  10335. sstr[c] = loc[strlen("connectorId")+2+c];
  10336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10337. c++;
  10338. }
  10339. sstr[c] = '\0';
  10340. connectorIdInt = atoi(sstr);
  10341. }
  10342. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10343. {
  10344. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10345. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10346. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10347. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10348. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10349. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10350. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10351. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10352. {
  10353. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10354. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10355. return TRUE;
  10356. }
  10357. else
  10358. {
  10359. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10360. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10361. }
  10362. }
  10363. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10364. {
  10365. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10366. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10367. return TRUE;
  10368. }
  10369. //==========================
  10370. // Trigger message
  10371. //==========================
  10372. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10373. {
  10374. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10375. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10376. {
  10377. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10378. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10379. }
  10380. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10381. }
  10382. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10383. {
  10384. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10385. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10386. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10387. }
  10388. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10389. {
  10390. //sendBootNotificationRequest();
  10391. server_sign = FALSE;
  10392. }
  10393. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10394. {
  10395. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10396. }
  10397. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10398. {
  10399. if(connectorIdIsNULL == FALSE)
  10400. {
  10401. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10402. {
  10403. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10404. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10405. }
  10406. }
  10407. else
  10408. {
  10409. for(int idx=0;idx< gunTotalNumber;idx++)
  10410. {
  10411. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10412. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10413. }
  10414. }
  10415. }
  10416. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10417. {
  10418. if(connectorIdIsNULL == FALSE)
  10419. {
  10420. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10421. {
  10422. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10423. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10424. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10425. }
  10426. }
  10427. else
  10428. {
  10429. for(int idx=0;idx< gunTotalNumber;idx++)
  10430. {
  10431. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10432. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10433. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10434. }
  10435. }
  10436. }
  10437. return result;
  10438. }
  10439. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10440. {
  10441. mtrace();
  10442. int result = FAIL;
  10443. int connectorIdInt =0;
  10444. char comfirmstr[20]={0};
  10445. int tempIndex = 0;
  10446. json_object *UnlockConnector;
  10447. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10448. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10449. UnlockConnector = json_tokener_parse(payload);
  10450. if(!is_error(UnlockConnector))
  10451. {
  10452. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10453. {
  10454. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10455. }
  10456. }
  10457. json_object_put(UnlockConnector);
  10458. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10459. if(gunTotalNumber == 0)
  10460. {
  10461. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10462. goto end;
  10463. }
  10464. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10465. {
  10466. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10467. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10468. goto end;
  10469. }
  10470. else
  10471. {
  10472. //check Transaction active
  10473. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10474. {
  10475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10476. {
  10477. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10478. }
  10479. else
  10480. {
  10481. tempIndex = connectorIdInt -1;
  10482. }
  10483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10484. {
  10485. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10486. {
  10487. //stop Transaction
  10488. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10489. }
  10490. }
  10491. }
  10492. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10493. {
  10494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10495. {
  10496. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10497. }
  10498. else
  10499. {
  10500. tempIndex = connectorIdInt -1;
  10501. }
  10502. for (int index = 0; index < CCS_QUANTITY; index++)
  10503. {
  10504. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10505. {
  10506. //stop Transaction
  10507. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10508. }
  10509. }
  10510. }
  10511. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10512. {
  10513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10514. {
  10515. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10516. }
  10517. else
  10518. {
  10519. tempIndex = connectorIdInt -1;
  10520. }
  10521. for (int index = 0; index < GB_QUANTITY; index++)
  10522. {
  10523. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10524. {
  10525. //stop Transaction
  10526. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10527. }
  10528. }
  10529. }
  10530. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10531. {
  10532. tempIndex = connectorIdInt -1;
  10533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10534. {
  10535. 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)))
  10536. {
  10537. //stop Transaction
  10538. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10539. }
  10540. }
  10541. }
  10542. else
  10543. {
  10544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10545. {
  10546. tempIndex = 2;
  10547. }
  10548. else
  10549. {
  10550. tempIndex = connectorIdInt-1;
  10551. }
  10552. for (int index = 0; index < AC_QUANTITY; index++)
  10553. {
  10554. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10555. {
  10556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10557. }
  10558. }
  10559. }
  10560. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10561. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10562. result = TRUE;
  10563. return result;
  10564. }
  10565. end:
  10566. //json_object_put(obj); --- remove temporally
  10567. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10568. return result;
  10569. }
  10570. static char UpdateFirmwarepayloadData[300]={0};
  10571. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10572. {
  10573. mtrace();
  10574. int result = FAIL;
  10575. pthread_t t;
  10576. sendUpdateFirmwareConfirmation(uuid);
  10577. memset(UpdateFirmwarepayloadData, 0, 300);
  10578. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10579. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10580. ////pthread_join(t, NULL); //
  10581. //pthread_detach(t);
  10582. //sendUpdateFirmwareConfirmation(uuid);
  10583. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10584. return result;
  10585. }
  10586. void *UpdateFirmwareProcess(void *data)
  10587. {
  10588. pthread_detach(pthread_self());
  10589. mtrace();
  10590. int retriesInt =0, retryIntervalInt=0;
  10591. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10592. int port=0;
  10593. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10594. int isSuccess = 0;
  10595. char ftpbuf[1024];
  10596. char temp[1024];
  10597. char * pch;
  10598. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10599. json_object *UpdateFirmware;
  10600. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10601. if(!is_error(UpdateFirmware))
  10602. {
  10603. // Required data
  10604. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10605. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10606. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10607. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10608. // Optional data
  10609. if(json_object_object_get(UpdateFirmware, "retries"))
  10610. {
  10611. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10612. }
  10613. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10614. {
  10615. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10616. }
  10617. }
  10618. json_object_put(UpdateFirmware);
  10619. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10620. memset(path, 0, ARRAY_SIZE(path));
  10621. // Wait retrieveData
  10622. if(strlen(retrieveDatestr) > 10)
  10623. {
  10624. do
  10625. {
  10626. sleep(1);
  10627. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10628. }
  10629. // Ready to download
  10630. system("rm -f /mnt/*");
  10631. if(strncmp(locationstr,"http", 4) == 0)
  10632. {
  10633. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10634. sprintf(ftppath,"/%s", path);
  10635. DEBUG_INFO("locationstr: %s\n", locationstr);
  10636. DEBUG_INFO("protocol: %s\n",protocol);
  10637. DEBUG_INFO("host: %s\n",host);
  10638. DEBUG_INFO("path: %s\n",path);
  10639. DEBUG_INFO("ftppath: %s\n",ftppath);
  10640. int ftppathlen=strlen(ftppath);
  10641. int i=1;
  10642. char filenametemp[50];
  10643. while(i < ftppathlen)
  10644. {
  10645. int len=ftppathlen-i;
  10646. if(ftppath[len]== 47) // '/' ascll code: 47
  10647. {
  10648. DEBUG_INFO("compare '/' all right\n");
  10649. break;
  10650. }
  10651. i=i+1;
  10652. }
  10653. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10654. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10655. filenametemp[i+1] = 0;
  10656. do
  10657. {
  10658. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10659. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10660. sleep(1);
  10661. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10662. if(!isSuccess)
  10663. {
  10664. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10665. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10666. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10667. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10668. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10669. }
  10670. else
  10671. {
  10672. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10673. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10674. }
  10675. retriesInt--;
  10676. }while((isSuccess == 0)&&(retriesInt >= 0));
  10677. }
  10678. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10679. {
  10680. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10681. memset(temp, 0, ARRAY_SIZE(temp));
  10682. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10683. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10684. int ftppathlen=strlen(ftpbuf);
  10685. int i=1;
  10686. char filenametemp[50];
  10687. while(i < ftppathlen)
  10688. {
  10689. int len=ftppathlen-i;
  10690. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10691. {
  10692. DEBUG_INFO(" compare '/' all right\n");
  10693. break;
  10694. }
  10695. i=i+1;
  10696. }
  10697. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10698. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10699. filenametemp[i+1] = 0;
  10700. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10701. pch=strchr(temp,'@');
  10702. if(pch==NULL)
  10703. {
  10704. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10705. protocol, host, &port, path);
  10706. strcpy(user,"anonymous");
  10707. strcpy(password,"");
  10708. }
  10709. else
  10710. {
  10711. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10712. protocol, user, password, host, &port, path);
  10713. }
  10714. sscanf(host,"%[^/]%s",host1, path1);
  10715. sprintf(ftppath,"%s", path1);
  10716. //DEBUG_INFO("protocol =%s\n",protocol);
  10717. //DEBUG_INFO("user =%s\n",user);
  10718. //DEBUG_INFO("password =%s\n",password);
  10719. //DEBUG_INFO("host1 =%s\n",host1);
  10720. //DEBUG_INFO("port =%d\n",port);
  10721. //DEBUG_INFO("path1 =%s\n",path1);
  10722. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10723. //ftpFile(host, user, password, port, ftppath, fname);
  10724. //download firmware pthred
  10725. if(port == 0)
  10726. {
  10727. port = 21;
  10728. }
  10729. do
  10730. {
  10731. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10733. sleep(1);
  10734. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10735. if(!isSuccess)
  10736. {
  10737. //BulldogUtil.sleepMs(interval*1000);
  10738. DEBUG_INFO("Update firmware request and download file fail.\n");
  10739. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10740. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10741. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10742. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10743. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10744. }
  10745. else
  10746. {
  10747. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10748. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10749. }
  10750. retriesInt--;
  10751. }while((!isSuccess)&&(retriesInt >= 0));
  10752. }
  10753. else
  10754. {
  10755. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10756. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10757. sleep(1);
  10758. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10759. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10760. }
  10761. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10762. pthread_exit(NULL);
  10763. }
  10764. int handleCertificateSignedRequest(char *uuid, char *payload)
  10765. {
  10766. mtrace();
  10767. int result = PASS;
  10768. json_object *CertificateSigned;
  10769. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10770. CertificateSigned = json_tokener_parse(payload);
  10771. if(!is_error(CertificateSigned))
  10772. {
  10773. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10774. }
  10775. json_object_put(CertificateSigned);
  10776. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10777. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10778. fclose(fp);
  10779. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10780. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10781. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10782. sendCertificateSignedConfirmation(uuid);
  10783. return result;
  10784. }
  10785. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10786. {
  10787. mtrace();
  10788. int result = PASS;
  10789. json_object *DeleteCertificate;
  10790. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10791. DeleteCertificate = json_tokener_parse(payload);
  10792. if(!is_error(DeleteCertificate))
  10793. {
  10794. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10795. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10796. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10797. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10798. }
  10799. json_object_put(DeleteCertificate);
  10800. /*
  10801. * TODO: Delete certificateSigned process
  10802. */
  10803. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10804. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10805. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10806. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10807. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10808. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10809. sendDeleteCertificateConfirmation(uuid);
  10810. return result;
  10811. }
  10812. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10813. {
  10814. mtrace();
  10815. int result = PASS;
  10816. json_object *ExtendedTriggerMessage;
  10817. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10818. ExtendedTriggerMessage = json_tokener_parse(payload);
  10819. if(!is_error(ExtendedTriggerMessage))
  10820. {
  10821. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10822. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10823. {
  10824. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10825. }
  10826. else
  10827. {
  10828. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10829. }
  10830. }
  10831. json_object_put(ExtendedTriggerMessage);
  10832. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10833. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10834. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10835. {
  10836. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10837. }
  10838. else
  10839. {
  10840. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10841. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10842. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10843. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10844. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10845. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10846. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10847. {
  10848. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10849. }
  10850. else
  10851. {
  10852. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10853. }
  10854. }
  10855. sendExtendedTriggerMessageConfirmation(uuid);
  10856. //==========================
  10857. // Trigger message
  10858. //==========================
  10859. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10860. {
  10861. //sendBootNotificationRequest();
  10862. server_sign = FALSE;
  10863. }
  10864. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10865. {
  10866. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10867. }
  10868. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10869. {
  10870. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10871. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10872. {
  10873. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10874. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10875. }
  10876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10877. }
  10878. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10879. {
  10880. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10881. }
  10882. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10883. {
  10884. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10885. {
  10886. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10887. }
  10888. else
  10889. {
  10890. for(int idx=0;idx< gunTotalNumber;idx++)
  10891. {
  10892. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10893. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10894. }
  10895. }
  10896. }
  10897. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10898. {
  10899. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10900. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10901. {
  10902. 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\" &");
  10903. }
  10904. }
  10905. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10906. {
  10907. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10908. {
  10909. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10910. }
  10911. else
  10912. {
  10913. for(int idx=0;idx< gunTotalNumber;idx++)
  10914. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10915. }
  10916. }
  10917. return result;
  10918. }
  10919. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10920. {
  10921. mtrace();
  10922. int result = PASS;
  10923. json_object *GetInstalledCertificateIds;
  10924. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10925. GetInstalledCertificateIds = json_tokener_parse(payload);
  10926. if(!is_error(GetInstalledCertificateIds))
  10927. {
  10928. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10929. }
  10930. json_object_put(GetInstalledCertificateIds);
  10931. /*
  10932. * TODO: Return installed certificate process
  10933. */
  10934. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10935. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10936. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10937. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10938. sendGetInstalledCertificateIdsConfirmation(uuid);
  10939. return result;
  10940. }
  10941. int handleGetLogRequest(char *uuid, char *payload)
  10942. {
  10943. mtrace();
  10944. int result = PASS;
  10945. json_object *GetLog;
  10946. DEBUG_INFO("handleGetLogRequest...\n");
  10947. GetLog = json_tokener_parse(payload);
  10948. if(!is_error(GetLog))
  10949. {
  10950. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10951. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10952. if(json_object_object_get(GetLog, "retries") != NULL)
  10953. {
  10954. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10955. }
  10956. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10957. {
  10958. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10959. }
  10960. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10961. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10962. {
  10963. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10964. }
  10965. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10966. {
  10967. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10968. }
  10969. }
  10970. json_object_put(GetLog);
  10971. /*
  10972. * TODO: Upload log process
  10973. */
  10974. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10975. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10976. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10977. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10978. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10979. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10980. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10981. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10982. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10983. sendGetLogConfirmation(uuid);
  10984. return result;
  10985. }
  10986. int handleInstallCertificateRequest(char *uuid, char *payload)
  10987. {
  10988. mtrace();
  10989. int result = PASS;
  10990. json_object *InstallCertificate;
  10991. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10992. InstallCertificate = json_tokener_parse(payload);
  10993. if(!is_error(InstallCertificate))
  10994. {
  10995. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10996. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10997. /*
  10998. * TODO: Install certificate process
  10999. */
  11000. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11001. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11002. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11003. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11004. sendInstallCertificateConfirmation(uuid);
  11005. }
  11006. json_object_put(InstallCertificate);
  11007. return result;
  11008. }
  11009. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11010. {
  11011. mtrace();
  11012. int result = PASS;
  11013. json_object *SignedUpdateFirmware;
  11014. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11015. SignedUpdateFirmware = json_tokener_parse(payload);
  11016. if(!is_error(SignedUpdateFirmware))
  11017. {
  11018. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11019. {
  11020. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11021. }
  11022. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11023. {
  11024. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11025. }
  11026. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11027. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11028. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11029. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11030. {
  11031. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11032. }
  11033. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11034. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11035. }
  11036. json_object_put(SignedUpdateFirmware);
  11037. /*
  11038. * TODO: Upgrade firmware process
  11039. */
  11040. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11041. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11042. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11043. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11044. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11045. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11046. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11047. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11048. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11049. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11050. sendInstallCertificateConfirmation(uuid);
  11051. return result;
  11052. }
  11053. int handleUnknownRequest(char *uuid, char *payload)
  11054. {
  11055. mtrace();
  11056. int result = PASS;
  11057. DEBUG_INFO("handleUnknownRequest...\n");
  11058. sendUnknownConfirmation(uuid);
  11059. result = PASS;
  11060. return result;
  11061. }
  11062. //==========================================
  11063. // Handle server response routine
  11064. //==========================================
  11065. void handleAuthorizeResponse(char *payload, int gun_index)
  11066. {
  11067. mtrace();
  11068. char expiryDatestr[30]={0};
  11069. char parentIdTagstr[20]={0};
  11070. char statusstr[20]={0};
  11071. int expiryDateISNULL=FALSE;
  11072. int parentIdTagISNULL=FALSE;
  11073. DEBUG_INFO("handleAuthorizeResponse...\n");
  11074. json_object *Authorize;
  11075. Authorize = json_tokener_parse(payload);
  11076. if(!is_error(Authorize))
  11077. {
  11078. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11079. {
  11080. // Required data
  11081. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11082. // Optional data
  11083. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11084. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11085. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11086. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11087. }
  11088. }
  11089. json_object_put(Authorize);
  11090. if(expiryDateISNULL == FALSE)
  11091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11092. if(parentIdTagISNULL == FALSE)
  11093. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11094. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11095. //Update idTag information to authorization cache if supproted
  11096. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11097. {
  11098. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11099. }
  11100. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11101. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11102. authorizeRetryTimes = 0;
  11103. }
  11104. void handleBootNotificationResponse(char *payload, int gun_index)
  11105. {
  11106. mtrace();
  11107. char statusStr[12]={0};
  11108. char currentTimeStr[30]={0};
  11109. int intervalInt = 0;
  11110. DEBUG_INFO("handleBootNotificationResponse...\n");
  11111. json_object *BootNotification;
  11112. BootNotification = json_tokener_parse(payload);
  11113. if(!is_error(BootNotification))
  11114. {
  11115. // Required data
  11116. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11117. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11118. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11119. }
  11120. json_object_put(BootNotification);
  11121. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11122. BootNotificationInterval = intervalInt;
  11123. HeartBeatWaitTime = intervalInt;
  11124. //write back to ShmOCPP16Data->BootNotification
  11125. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11126. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11127. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11128. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11129. {
  11130. server_sign = TRUE;
  11131. server_pending =FALSE;
  11132. }
  11133. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11134. {
  11135. server_pending = TRUE;
  11136. }
  11137. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11138. srand(time(NULL));
  11139. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11140. SetOcppConnStatus(TRUE);
  11141. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11142. }
  11143. void handleDataTransferResponse(char *payload, int gun_index)
  11144. {
  11145. char sstr[160]={0};//sstr[200]={ 0 };
  11146. int c = 0;
  11147. char *loc;
  11148. DEBUG_INFO("handleDataTransferResponse ...\n");
  11149. loc = strstr(payload, "status");
  11150. printf("loc=%s\n",loc);
  11151. c = 0;
  11152. while (loc[3+strlen("status")+c] != '\"')
  11153. {
  11154. sstr[c] = loc[3+strlen("status")+c];
  11155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11156. c++;
  11157. }
  11158. sstr[c] = '\0';
  11159. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11160. }
  11161. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11162. {
  11163. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11164. //struct json_object *obj;
  11165. // obj = json_tokener_parse(payload);
  11166. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11167. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11168. //No fields are defined.
  11169. }
  11170. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11171. {
  11172. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11173. //struct json_object *obj;
  11174. // obj = json_tokener_parse(payload);
  11175. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11176. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11177. //No fields are defined.
  11178. }
  11179. void handleHeartbeatResponse(char *payload, int gun_index)
  11180. {
  11181. mtrace();
  11182. DEBUG_INFO("handleHeartbeatResponse...\n");
  11183. json_object *Heartbeat;
  11184. Heartbeat = json_tokener_parse(payload);
  11185. if(!is_error(Heartbeat))
  11186. {
  11187. // Required data
  11188. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11189. }
  11190. json_object_put(Heartbeat);
  11191. if(FirstHeartBeat == 0)
  11192. {
  11193. FirstHeartBeat = 1;
  11194. DEBUG_INFO("FirstHeartBeat \n");
  11195. }
  11196. HeartBeatWithNOResponse = 0;
  11197. clientTime.Heartbeat=time((time_t*)NULL);
  11198. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11199. }
  11200. void handleMeterValuesResponse(char *payload, int gun_index)
  11201. {
  11202. mtrace();
  11203. DEBUG_INFO("handleMeterValuesResponse...\n");
  11204. }
  11205. void handleStartTransactionResponse(char *payload, int gun_index)
  11206. {
  11207. mtrace();
  11208. //int transactionIdInt = 0;
  11209. FILE *outfile;
  11210. char data[100]={0};
  11211. DEBUG_INFO("handleStartTransactionResponse...\n");
  11212. json_object *StartTransaction;
  11213. StartTransaction = json_tokener_parse(payload);
  11214. if(!is_error(StartTransaction))
  11215. {
  11216. // Required data
  11217. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11218. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11219. // Optional data
  11220. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11221. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11222. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11223. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11224. }
  11225. json_object_put(StartTransaction);
  11226. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11227. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11228. //-----------Start : write to the Queue TransactionId file -----------------//
  11229. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11230. {}
  11231. else
  11232. {
  11233. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11234. if(log == NULL)
  11235. {
  11236. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11237. return ;
  11238. }
  11239. else
  11240. {
  11241. fclose(log);
  11242. }
  11243. }
  11244. // open file for writing
  11245. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11246. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11247. {
  11248. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11249. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11250. fputs(data, outfile);
  11251. fclose (outfile);
  11252. }
  11253. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11254. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11255. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11256. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11257. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11258. }
  11259. void handleStatusNotificationResponse(char *payload, int gun_index)
  11260. {
  11261. mtrace();
  11262. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11263. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11264. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11265. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11266. }
  11267. void handleStopTransactionnResponse(char *payload, int gun_index)
  11268. {
  11269. mtrace();
  11270. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11271. json_object *StopTransaction;
  11272. StopTransaction = json_tokener_parse(payload);
  11273. if(!is_error(StopTransaction))
  11274. {
  11275. // Optional data
  11276. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11277. {
  11278. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11279. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11281. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11283. }
  11284. }
  11285. json_object_put(StopTransaction);
  11286. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11287. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11288. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11289. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11290. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11291. }
  11292. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11293. {
  11294. mtrace();
  11295. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11296. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11297. }
  11298. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11299. {
  11300. mtrace();
  11301. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11302. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11303. }
  11304. void handleSignCertificateResponse(char *payload, int gun_index)
  11305. {
  11306. mtrace();
  11307. DEBUG_INFO("handleSignCertificateResponse...\n");
  11308. json_object *SignCertificate;
  11309. SignCertificate = json_tokener_parse(payload);
  11310. if(!is_error(SignCertificate))
  11311. {
  11312. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11313. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11314. }
  11315. json_object_put(SignCertificate);
  11316. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11317. }
  11318. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11319. {
  11320. mtrace();
  11321. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11322. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11323. }
  11324. //==========================================
  11325. // Handle Error routine
  11326. //==========================================
  11327. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11328. {
  11329. mtrace();
  11330. #ifdef SystemLogMessage
  11331. DEBUG_INFO("errorCode: %s\n", errorCode);
  11332. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11333. DEBUG_INFO("errorDetails: %s\n", payload);
  11334. #endif
  11335. }
  11336. //===============================================
  11337. // Common routine
  11338. //===============================================
  11339. int initialConfigurationTable(void)
  11340. {
  11341. //clock_t start_t, end_t, total_t;
  11342. FILE *fp;
  11343. FILE *outfile;
  11344. char str[512]={0};
  11345. char sstr[256]={0};
  11346. int c = 0;
  11347. char *loc;
  11348. int confVersion = 5;
  11349. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11350. //start_t = clock();
  11351. //printf("Starting of the program, start_t = %ld\n", start_t);
  11352. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11353. // Check configuration file size is correct
  11354. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11355. {
  11356. struct stat st;
  11357. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11358. if(st.st_size < 3100)
  11359. {
  11360. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11361. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11362. }
  11363. }
  11364. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11365. {
  11366. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11367. if(outfile == NULL)
  11368. {
  11369. DEBUG_INFO("Error opening file\n");
  11370. return FALSE;
  11371. }
  11372. /*Core Profile*/
  11373. //AllowOfflineTxForUnknownId
  11374. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11378. //AuthorizationCacheEnabled
  11379. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11383. //AuthorizeRemoteTxRequests
  11384. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11388. //BlinkRepeat
  11389. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11393. //ClockAlignedDataInterval
  11394. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11398. //ConnectionTimeOut
  11399. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11403. //GetConfigurationMaxKeys
  11404. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11408. // HeartbeatInterval
  11409. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11413. // LightIntensity
  11414. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11418. // LocalAuthorizeOffline
  11419. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11423. // LocalPreAuthorize
  11424. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11428. // MaxEnergyOnInvalidId
  11429. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11433. // MeterValuesAlignedData
  11434. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11438. else
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11441. // MeterValuesAlignedDataMaxLength
  11442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11446. else
  11447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11449. // MeterValuesSampledData
  11450. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11454. else
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11457. // MeterValuesSampledDataMaxLength
  11458. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11462. else
  11463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11465. // MeterValueSampleInterval
  11466. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11470. // MinimumStatusDuration
  11471. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11474. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11476. // NumberOfConnectors
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11480. {
  11481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11482. }
  11483. else
  11484. {
  11485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11486. }
  11487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11488. // ResetRetries
  11489. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11493. // ConnectorPhaseRotation
  11494. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11498. // ConnectorPhaseRotationMaxLength
  11499. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11503. // StopTransactionOnEVSideDisconnect
  11504. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11508. // StopTransactionOnInvalidId
  11509. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11513. // StopTxnAlignedData
  11514. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11518. // StopTxnAlignedDataMaxLength
  11519. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11523. // StopTxnSampledData
  11524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11528. else
  11529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11531. // StopTxnSampledDataMaxLength
  11532. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11535. {
  11536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11537. }
  11538. else
  11539. {
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11541. }
  11542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11543. // SupportedFeatureProfiles
  11544. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11548. // SupportedFeatureProfilesMaxLength
  11549. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11553. // TransactionMessageAttempts
  11554. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11557. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11559. // TransactionMessageRetryInterval
  11560. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11563. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11565. // UnlockConnectorOnEVSideDisconnect
  11566. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11570. // WebSocketPingInterval
  11571. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11575. // QueueOffLineStartTransactionMessage
  11576. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11580. // AuthorizationKey
  11581. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11585. // SecurityProfile
  11586. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11590. // DefaultPrice
  11591. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11595. // CustomDisplayCostAndPrice
  11596. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11600. // CustomIdleFeeAfterStop
  11601. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11605. // TimeOffset
  11606. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  11607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  11608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  11609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  11610. // NextTimeOffsetTransitionDateTime
  11611. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  11612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  11613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  11614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  11615. // TimeOffsetNextTransition
  11616. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  11617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  11618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  11619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  11620. // Configuration Version
  11621. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11625. //* Local Auth List Management Profile*/
  11626. #if 0
  11627. //For OCTT Test Case
  11628. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11631. #endif
  11632. #if 1
  11633. //LocalAuthListEnabled
  11634. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11638. #endif
  11639. //LocalAuthListMaxLength
  11640. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11644. //SendLocalListMaxLength
  11645. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11649. //ReserveConnectorZeroSupported
  11650. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11654. //* Smart Charging Profile */
  11655. //ChargeProfileMaxStackLevel
  11656. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11660. // ChargingScheduleAllowedChargingRateUnit
  11661. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11665. // ChargingScheduleMaxPeriods
  11666. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11670. // ConnectorSwitch3to1PhaseSupported
  11671. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11675. // MaxChargingProfilesInstalled
  11676. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11680. fclose(outfile);
  11681. }
  11682. else
  11683. {
  11684. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11685. char keystr[60]={0};
  11686. char readonlystr[10]={0};
  11687. char valuestr[256]={0};
  11688. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11689. if(fp == NULL) {
  11690. DEBUG_INFO("Error opening file");
  11691. return FALSE;
  11692. }
  11693. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11694. {
  11695. //DEBUG_INFO("Get Configuration \n");
  11696. if(strlen(str) > 0)
  11697. {
  11698. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11699. //*************************key*********************************/
  11700. if(strstr(str, "key") != NULL)
  11701. {
  11702. loc = strstr(str, "key");
  11703. c = 0;
  11704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11705. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11706. {
  11707. sstr[c] = loc[strlen("key")+3+c];
  11708. c++;
  11709. }
  11710. sstr[c] = '\0';
  11711. strcpy(keystr,sstr);
  11712. }
  11713. //*************************readonly*********************************/
  11714. if(strstr(str, "readonly") != NULL)
  11715. {
  11716. loc = strstr(str, "readonly");
  11717. c = 0;
  11718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11719. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11720. {
  11721. sstr[c] = loc[strlen("readonly")+2+c];
  11722. c++;
  11723. }
  11724. sstr[c] = '\0';
  11725. strcpy(readonlystr,sstr);
  11726. }
  11727. //*************************value*********************************/
  11728. if(strstr(str, "value") != NULL)
  11729. {
  11730. loc = strstr(str, "value");
  11731. c = 0;
  11732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11733. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11734. {
  11735. sstr[c] = loc[strlen("value")+3+c];
  11736. c++;
  11737. }
  11738. sstr[c] = '\0';
  11739. strcpy(valuestr,sstr);
  11740. }
  11741. // DEBUG_INFO("keystr=%s\n",keystr);
  11742. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11743. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11744. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11745. {
  11746. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11747. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11749. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11750. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11751. }
  11752. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11753. {
  11754. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11755. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11757. }
  11758. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11759. {
  11760. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11762. }
  11763. if(strcmp(keystr, "BlinkRepeat") == 0)
  11764. {
  11765. //Charger.BlinkRepeat = Integer.parseInt(value);
  11766. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11768. }
  11769. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11770. {
  11771. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11773. }
  11774. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11775. {
  11776. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11778. }
  11779. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11780. {
  11781. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11783. }
  11784. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11785. {
  11786. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11788. HeartBeatWaitTime = atoi(valuestr);
  11789. }
  11790. if(strcmp(keystr, "LightIntensity") == 0)
  11791. {
  11792. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11794. }
  11795. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11796. {
  11797. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11799. }
  11800. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11801. {
  11802. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11804. }
  11805. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11806. {
  11807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11809. }
  11810. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11811. {
  11812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11814. }
  11815. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11816. {
  11817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11819. }
  11820. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11821. {
  11822. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11824. }
  11825. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11826. {
  11827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11829. }
  11830. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11831. {
  11832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11834. }
  11835. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11836. {
  11837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11839. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11840. }
  11841. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11842. {
  11843. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11845. }
  11846. if(strcmp(keystr, "ResetRetries") == 0)
  11847. {
  11848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11850. }
  11851. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11852. {
  11853. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11855. }
  11856. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11857. {
  11858. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11860. }
  11861. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11862. {
  11863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11865. }
  11866. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11867. {
  11868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11870. }
  11871. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11872. {
  11873. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11875. }
  11876. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11877. {
  11878. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11880. }
  11881. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11882. {
  11883. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11885. }
  11886. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11887. {
  11888. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11890. }
  11891. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11892. {
  11893. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11895. }
  11896. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11897. {
  11898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11900. }
  11901. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11902. {
  11903. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11905. TransactionMessageAttemptsValue = atoi(valuestr);
  11906. }
  11907. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11908. {
  11909. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11911. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11912. }
  11913. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11914. {
  11915. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11917. }
  11918. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11919. {
  11920. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11922. }
  11923. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11924. {
  11925. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11927. }
  11928. if(strcmp(keystr, "AuthorizationKey") == 0)
  11929. {
  11930. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11931. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11933. }
  11934. if(strcmp(keystr, "SecurityProfile") == 0)
  11935. {
  11936. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11938. }
  11939. if(strcmp(keystr, "DefaultPrice") == 0)
  11940. {
  11941. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11943. }
  11944. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11945. {
  11946. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11948. }
  11949. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11950. {
  11951. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11953. }
  11954. if(strcmp(keystr, "TimeOffset") == 0)
  11955. {
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  11958. }
  11959. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  11960. {
  11961. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  11963. }
  11964. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  11965. {
  11966. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  11968. }
  11969. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11970. {
  11971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11973. }
  11974. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11975. {
  11976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11978. }
  11979. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11980. {
  11981. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11983. }
  11984. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11985. {
  11986. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11988. }
  11989. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11990. {
  11991. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11993. }
  11994. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11995. {
  11996. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11998. }
  11999. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12000. {
  12001. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12003. }
  12004. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12005. {
  12006. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12008. }
  12009. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12010. {
  12011. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12013. }
  12014. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12015. {
  12016. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12018. }
  12019. }
  12020. }
  12021. fclose(fp);
  12022. }
  12023. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12024. {
  12025. return PASS;
  12026. }
  12027. else
  12028. {
  12029. return FAIL;
  12030. }
  12031. }
  12032. void StoreConfigurationTable(void)
  12033. {
  12034. FILE *outfile;
  12035. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12036. if(outfile == NULL)
  12037. {
  12038. DEBUG_INFO("Error opening file");
  12039. return ;
  12040. }
  12041. /*Core Profile*/
  12042. //AllowOfflineTxForUnknownId
  12043. /*
  12044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12045. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12048. */
  12049. //DEBUG_INFO("data=%s\n",data);
  12050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12051. //AuthorizationCacheEnabled
  12052. /*
  12053. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12056. */
  12057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12058. //AuthorizeRemoteTxRequests
  12059. /*
  12060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12063. */
  12064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12065. //BlinkRepeat
  12066. /*
  12067. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12070. */
  12071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12072. //ClockAlignedDataInterval
  12073. /*
  12074. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12077. */
  12078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12079. //ConnectionTimeOut
  12080. /*
  12081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12084. */
  12085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12086. //GetConfigurationMaxKeys
  12087. /*
  12088. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12091. */
  12092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12093. // HeartbeatInterval
  12094. /*
  12095. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12098. */
  12099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12100. // LightIntensity
  12101. /*
  12102. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12105. */
  12106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12107. // LocalAuthorizeOffline
  12108. /*
  12109. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12112. */
  12113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12114. // LocalPreAuthorize
  12115. /*
  12116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12119. */
  12120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12121. // MaxEnergyOnInvalidId
  12122. /*
  12123. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12126. */
  12127. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12129. // MeterValuesAlignedData
  12130. /*
  12131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12134. */
  12135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12136. // MeterValuesAlignedDataMaxLength
  12137. /*
  12138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12141. */
  12142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12143. // MeterValuesSampledData
  12144. /*
  12145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12148. */
  12149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12150. // MeterValuesSampledDataMaxLength
  12151. /*
  12152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12155. */
  12156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12157. // MeterValueSampleInterval
  12158. /*
  12159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12162. */
  12163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12164. // MinimumStatusDuration
  12165. /*
  12166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12169. */
  12170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12171. // NumberOfConnectors
  12172. /*
  12173. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12176. {
  12177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12178. }
  12179. else
  12180. {
  12181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12182. }
  12183. */
  12184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12185. // ResetRetries
  12186. /*
  12187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12190. */
  12191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12192. // ConnectorPhaseRotation
  12193. /*
  12194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12197. */
  12198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12199. // ConnectorPhaseRotationMaxLength
  12200. /*
  12201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12204. */
  12205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12206. // StopTransactionOnEVSideDisconnect
  12207. /*
  12208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12211. */
  12212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12213. // StopTransactionOnInvalidId
  12214. /*
  12215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12218. */
  12219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12220. // StopTxnAlignedData
  12221. /*
  12222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12225. */
  12226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12227. // StopTxnAlignedDataMaxLength
  12228. /*
  12229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12232. */
  12233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12234. // StopTxnSampledData
  12235. /*
  12236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12239. */
  12240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12241. // StopTxnSampledDataMaxLength
  12242. /*
  12243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12246. */
  12247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12248. // SupportedFeatureProfiles
  12249. /*
  12250. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12253. */
  12254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12255. // SupportedFeatureProfilesMaxLength
  12256. /*
  12257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12260. */
  12261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12262. // TransactionMessageAttempts
  12263. /*
  12264. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12267. */
  12268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12269. // TransactionMessageRetryInterval
  12270. /*
  12271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12274. */
  12275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12276. // UnlockConnectorOnEVSideDisconnect
  12277. /*
  12278. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12281. */
  12282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12283. // WebSocketPingInterval
  12284. /*
  12285. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12288. */
  12289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12290. // QueueOffLineStartTransactionMessage
  12291. /*
  12292. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12295. */
  12296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12297. // AuthorizationKey
  12298. /*
  12299. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12302. */
  12303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12304. // SecurityProfile
  12305. /*
  12306. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12309. */
  12310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12311. // DefaultPrice
  12312. /*
  12313. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12316. */
  12317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12318. // CustomDisplayCostAndPrice
  12319. /*
  12320. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12323. */
  12324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12325. // CustomIdleFeeAfterStop
  12326. /*
  12327. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12330. */
  12331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12332. // TimeOffset
  12333. /*
  12334. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  12337. */
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12339. // NextTimeOffsetTransitionDateTime
  12340. /*
  12341. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  12344. */
  12345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12346. // TimeOffsetNextTransition
  12347. /*
  12348. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  12351. */
  12352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12353. // ConfigurationVersion
  12354. /*
  12355. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12358. */
  12359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12360. //* Local Auth List Management Profile*/
  12361. //LocalAuthListEnabled
  12362. /*
  12363. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12366. */
  12367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12368. //LocalAuthListMaxLength
  12369. /*
  12370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12373. */
  12374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12375. //SendLocalListMaxLength
  12376. /*
  12377. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12380. */
  12381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12382. //ReserveConnectorZeroSupported
  12383. /*
  12384. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12387. */
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12389. //* Smart Charging Profile */
  12390. //ChargeProfileMaxStackLevel
  12391. /*
  12392. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12395. */
  12396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12397. // ChargingScheduleAllowedChargingRateUnit
  12398. /*
  12399. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12402. */
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12404. // ChargingScheduleMaxPeriods
  12405. /*
  12406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12409. */
  12410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12411. // ConnectorSwitch3to1PhaseSupported
  12412. /*
  12413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12416. */
  12417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12418. // MaxChargingProfilesInstalled
  12419. /*
  12420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12423. */
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12425. fclose(outfile);
  12426. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12427. }
  12428. void getKeyValue(char *keyReq)
  12429. {
  12430. int isEmpty = FALSE;
  12431. int isKnowKey = FALSE;
  12432. DEBUG_INFO("keyReq = %s\n", keyReq);
  12433. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12434. isEmpty = TRUE;
  12435. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12436. {
  12437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12442. }
  12443. else
  12444. {
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12446. }
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12448. isKnowKey = TRUE;
  12449. }
  12450. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12451. {
  12452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12457. }
  12458. else
  12459. {
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12461. }
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12463. isKnowKey = TRUE;
  12464. }
  12465. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12466. {
  12467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12472. }
  12473. else
  12474. {
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12476. }
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12478. isKnowKey = TRUE;
  12479. }
  12480. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12481. {
  12482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12487. }
  12488. else
  12489. {
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12491. }
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12493. isKnowKey = TRUE;
  12494. }
  12495. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12496. {
  12497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12502. }
  12503. else
  12504. {
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12506. }
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12508. isKnowKey = TRUE;
  12509. }
  12510. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12511. {
  12512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12517. }
  12518. else
  12519. {
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12521. }
  12522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12523. isKnowKey = TRUE;
  12524. }
  12525. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12526. {
  12527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12532. }
  12533. else
  12534. {
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12536. }
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12538. isKnowKey = TRUE;
  12539. }
  12540. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12541. {
  12542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12547. }
  12548. else
  12549. {
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12551. }
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12553. isKnowKey = TRUE;
  12554. }
  12555. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12556. {
  12557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12562. }
  12563. else
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12566. }
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12568. isKnowKey = TRUE;
  12569. }
  12570. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12571. {
  12572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12577. }
  12578. else
  12579. {
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12581. }
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12583. isKnowKey = TRUE;
  12584. }
  12585. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12586. {
  12587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12592. }
  12593. else
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12596. }
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12598. isKnowKey = TRUE;
  12599. }
  12600. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12601. {
  12602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12607. }
  12608. else
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12611. }
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12613. isKnowKey = TRUE;
  12614. }
  12615. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12616. {
  12617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12622. }
  12623. else
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12626. }
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12628. isKnowKey = TRUE;
  12629. }
  12630. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12631. {
  12632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12637. }
  12638. else
  12639. {
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12641. }
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12643. isKnowKey = TRUE;
  12644. }
  12645. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12646. {
  12647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12650. {
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12652. }
  12653. else
  12654. {
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12656. }
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12658. isKnowKey = TRUE;
  12659. }
  12660. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12661. {
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12665. {
  12666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12667. }
  12668. else
  12669. {
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12671. }
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12673. isKnowKey = TRUE;
  12674. }
  12675. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12676. {
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12680. {
  12681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12682. }
  12683. else
  12684. {
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12686. }
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12688. isKnowKey = TRUE;
  12689. }
  12690. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12691. {
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12695. {
  12696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12697. }
  12698. else
  12699. {
  12700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12701. }
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12703. isKnowKey = TRUE;
  12704. }
  12705. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12706. {
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12710. {
  12711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12712. }
  12713. else
  12714. {
  12715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12716. }
  12717. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12719. isKnowKey = TRUE;
  12720. }
  12721. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12722. {
  12723. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12728. }
  12729. else
  12730. {
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12732. }
  12733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12734. isKnowKey = TRUE;
  12735. }
  12736. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12737. {
  12738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12741. {
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12743. }
  12744. else
  12745. {
  12746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12747. }
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12749. isKnowKey = TRUE;
  12750. }
  12751. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12752. {
  12753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12756. {
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12758. }
  12759. else
  12760. {
  12761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12762. }
  12763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12764. isKnowKey = TRUE;
  12765. }
  12766. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12767. {
  12768. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12771. {
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12773. }
  12774. else
  12775. {
  12776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12777. }
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12779. isKnowKey = TRUE;
  12780. }
  12781. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12782. {
  12783. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12786. {
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12788. }
  12789. else
  12790. {
  12791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12792. }
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12794. isKnowKey = TRUE;
  12795. }
  12796. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12797. {
  12798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12803. }
  12804. else
  12805. {
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12807. }
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12809. isKnowKey = TRUE;
  12810. }
  12811. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12812. {
  12813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12816. {
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12818. }
  12819. else
  12820. {
  12821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12822. }
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12824. isKnowKey = TRUE;
  12825. }
  12826. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12827. {
  12828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12833. }
  12834. else
  12835. {
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12837. }
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12839. isKnowKey = TRUE;
  12840. }
  12841. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12842. {
  12843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12848. }
  12849. else
  12850. {
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12852. }
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12854. isKnowKey = TRUE;
  12855. }
  12856. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12857. {
  12858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12863. }
  12864. else
  12865. {
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12867. }
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12869. isKnowKey = TRUE;
  12870. }
  12871. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12872. {
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12878. }
  12879. else
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12882. }
  12883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12884. isKnowKey = TRUE;
  12885. }
  12886. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12887. {
  12888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12891. {
  12892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12893. }
  12894. else
  12895. {
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12897. }
  12898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12899. isKnowKey = TRUE;
  12900. }
  12901. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12902. {
  12903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12906. {
  12907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12908. }
  12909. else
  12910. {
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12912. }
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12914. isKnowKey = TRUE;
  12915. }
  12916. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12917. {
  12918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12921. {
  12922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12923. }
  12924. else
  12925. {
  12926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12927. }
  12928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12929. isKnowKey = TRUE;
  12930. }
  12931. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12932. {
  12933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12936. {
  12937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12938. }
  12939. else
  12940. {
  12941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12942. }
  12943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12944. isKnowKey = TRUE;
  12945. }
  12946. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12947. {
  12948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12951. {
  12952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12953. }
  12954. else
  12955. {
  12956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12957. }
  12958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12959. isKnowKey = TRUE;
  12960. }
  12961. /*
  12962. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12963. {
  12964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12967. {
  12968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12969. }
  12970. else
  12971. {
  12972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12973. }
  12974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12975. isKnowKey = TRUE;
  12976. }*/
  12977. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12978. {
  12979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12982. {
  12983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12984. }
  12985. else
  12986. {
  12987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12988. }
  12989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12990. isKnowKey = TRUE;
  12991. }
  12992. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12993. {
  12994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12997. {
  12998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12999. }
  13000. else
  13001. {
  13002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13003. }
  13004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13005. isKnowKey = TRUE;
  13006. }
  13007. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13008. {
  13009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13012. {
  13013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13014. }
  13015. else
  13016. {
  13017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13018. }
  13019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13020. isKnowKey = TRUE;
  13021. }
  13022. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13023. {
  13024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13027. {
  13028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13029. }
  13030. else
  13031. {
  13032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13033. }
  13034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13035. isKnowKey = TRUE;
  13036. }
  13037. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13038. {
  13039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13042. {
  13043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13044. }
  13045. else
  13046. {
  13047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13048. }
  13049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13050. isKnowKey = TRUE;
  13051. }
  13052. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13053. {
  13054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13057. {
  13058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13059. }
  13060. else
  13061. {
  13062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13063. }
  13064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13065. isKnowKey = TRUE;
  13066. }
  13067. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13068. {
  13069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13072. {
  13073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13074. }
  13075. else
  13076. {
  13077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13078. }
  13079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13080. isKnowKey = TRUE;
  13081. }
  13082. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13083. {
  13084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13087. {
  13088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13089. }
  13090. else
  13091. {
  13092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13093. }
  13094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13095. isKnowKey = TRUE;
  13096. }
  13097. #if 1
  13098. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13099. {
  13100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13102. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13103. {
  13104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13105. }
  13106. else
  13107. {
  13108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13109. }
  13110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13111. isKnowKey = TRUE;
  13112. }
  13113. #endif
  13114. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13115. {
  13116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13118. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13119. {
  13120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13121. }
  13122. else
  13123. {
  13124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13125. }
  13126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13127. isKnowKey = TRUE;
  13128. }
  13129. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13130. {
  13131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13133. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13134. {
  13135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13136. }
  13137. else
  13138. {
  13139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13140. }
  13141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13142. isKnowKey = TRUE;
  13143. }
  13144. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13145. {
  13146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13148. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13149. {
  13150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13151. }
  13152. else
  13153. {
  13154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13155. }
  13156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13157. isKnowKey = TRUE;
  13158. }
  13159. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13160. {
  13161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13163. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13164. {
  13165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13166. }
  13167. else
  13168. {
  13169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13170. }
  13171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13172. isKnowKey = TRUE;
  13173. }
  13174. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13175. {
  13176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13178. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13179. {
  13180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13181. }
  13182. else
  13183. {
  13184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13185. }
  13186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13187. isKnowKey = TRUE;
  13188. }
  13189. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13190. {
  13191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13193. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13196. }
  13197. else
  13198. {
  13199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13200. }
  13201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13202. isKnowKey = TRUE;
  13203. }
  13204. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13205. {
  13206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13208. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13209. {
  13210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13211. }
  13212. else
  13213. {
  13214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13215. }
  13216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13217. isKnowKey = TRUE;
  13218. }
  13219. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13220. {
  13221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13223. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13224. {
  13225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13226. }
  13227. else
  13228. {
  13229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13230. }
  13231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13232. isKnowKey = TRUE;
  13233. }
  13234. //=========================================================
  13235. if(!isEmpty && !isKnowKey)
  13236. {
  13237. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13238. strcpy(unknownkey[UnknownKeynum], keyReq);
  13239. UnknownKeynum = UnknownKeynum + 1;
  13240. }
  13241. }
  13242. void processUnkownKey(void)
  13243. {
  13244. DEBUG_INFO("processUnkownKey...\n");
  13245. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13246. for(int index=0; index < UnknownKeynum; index++)
  13247. {
  13248. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13249. {
  13250. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13251. }
  13252. }
  13253. }
  13254. int setKeyValue(char *key, char *value)
  13255. {
  13256. int isSuccess = NotSupported;
  13257. int check_ascii=0;
  13258. char str[256]={0};
  13259. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13260. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13261. {
  13262. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13264. {
  13265. strcpy(str, (const char*)value);
  13266. for(int i = 0; str[i]; i++){
  13267. str[i] = tolower(str[i]);
  13268. }
  13269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13270. isSuccess = ConfigurationStatus_Accepted;
  13271. }
  13272. else
  13273. {
  13274. isSuccess = ConfigurationStatus_Rejected;
  13275. }
  13276. }
  13277. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13278. {
  13279. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13281. {
  13282. strcpy(str, (const char*)value);
  13283. for(int i = 0; str[i]; i++){
  13284. str[i] = tolower(str[i]);
  13285. }
  13286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13287. isSuccess = ConfigurationStatus_Accepted;
  13288. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13289. }
  13290. else
  13291. {
  13292. isSuccess = ConfigurationStatus_Rejected;
  13293. }
  13294. }
  13295. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13296. {
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13298. {
  13299. strcpy(str, (const char*)value);
  13300. for(int i = 0; str[i]; i++)
  13301. {
  13302. str[i] = tolower(str[i]);
  13303. }
  13304. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13306. isSuccess = ConfigurationStatus_Accepted;
  13307. }
  13308. else
  13309. {
  13310. isSuccess = ConfigurationStatus_Rejected;
  13311. }
  13312. }
  13313. if(strcmp(key, "BlinkRepeat") == 0)
  13314. {
  13315. //Charger.BlinkRepeat = Integer.parseInt(value);
  13316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13317. {
  13318. check_ascii = value[0];
  13319. if( (check_ascii < 48) || (check_ascii > 57) )
  13320. {
  13321. isSuccess = ConfigurationStatus_Rejected;
  13322. }
  13323. else
  13324. {
  13325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13326. isSuccess = ConfigurationStatus_Accepted;
  13327. }
  13328. }
  13329. else
  13330. {
  13331. isSuccess = ConfigurationStatus_Rejected;
  13332. }
  13333. }
  13334. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13335. {
  13336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13337. {
  13338. check_ascii = value[0];
  13339. if( (check_ascii < 48) || (check_ascii > 57) )
  13340. {
  13341. isSuccess = ConfigurationStatus_Rejected;
  13342. }
  13343. else
  13344. {
  13345. if((atoi(value) == 0) || (atoi(value) >= 10))
  13346. {
  13347. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13349. isSuccess = ConfigurationStatus_Accepted;
  13350. }
  13351. else
  13352. isSuccess = ConfigurationStatus_Rejected;
  13353. }
  13354. }
  13355. else
  13356. {
  13357. isSuccess = ConfigurationStatus_Rejected;
  13358. }
  13359. }
  13360. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13361. {
  13362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13363. {
  13364. check_ascii = value[0];
  13365. if( (check_ascii < 48) || (check_ascii > 57) )
  13366. {
  13367. isSuccess = ConfigurationStatus_Rejected;
  13368. }
  13369. else
  13370. {
  13371. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13373. isSuccess = ConfigurationStatus_Accepted;
  13374. }
  13375. }
  13376. else
  13377. {
  13378. isSuccess = ConfigurationStatus_Rejected;
  13379. }
  13380. }
  13381. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13382. {
  13383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13384. {
  13385. check_ascii = value[0];
  13386. if( (check_ascii < 48) || (check_ascii > 57) )
  13387. {
  13388. isSuccess = ConfigurationStatus_Rejected;
  13389. }
  13390. else
  13391. {
  13392. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13394. isSuccess = ConfigurationStatus_Accepted;
  13395. }
  13396. }
  13397. else
  13398. {
  13399. isSuccess = ConfigurationStatus_Rejected;
  13400. }
  13401. }
  13402. if(strcmp(key, "HeartbeatInterval") == 0)
  13403. {
  13404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13405. {
  13406. check_ascii = value[0];
  13407. if( (check_ascii < 48) || (check_ascii > 57) )
  13408. {
  13409. isSuccess = ConfigurationStatus_Rejected;
  13410. }
  13411. else
  13412. {
  13413. if((atoi(value) == 0) || (atoi(value) >= 10))
  13414. {
  13415. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13417. HeartBeatWaitTime = atoi(value);
  13418. isSuccess = ConfigurationStatus_Accepted;
  13419. }
  13420. else
  13421. {
  13422. isSuccess = ConfigurationStatus_Rejected;
  13423. }
  13424. }
  13425. }
  13426. else
  13427. {
  13428. isSuccess = ConfigurationStatus_Rejected;
  13429. }
  13430. }
  13431. if(strcmp(key, "LightIntensity") == 0)
  13432. {
  13433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13434. {
  13435. check_ascii = value[0];
  13436. if( (check_ascii < 48) || (check_ascii > 57) )
  13437. {
  13438. isSuccess = ConfigurationStatus_Rejected;
  13439. }
  13440. else
  13441. {
  13442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13443. isSuccess = ConfigurationStatus_Accepted;
  13444. }
  13445. }
  13446. else
  13447. {
  13448. isSuccess = ConfigurationStatus_Rejected;
  13449. }
  13450. }
  13451. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13452. {
  13453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13454. {
  13455. strcpy(str, (const char*)value);
  13456. for(int i = 0; str[i]; i++)
  13457. {
  13458. str[i] = tolower(str[i]);
  13459. }
  13460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13461. isSuccess = ConfigurationStatus_Accepted;
  13462. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13463. }
  13464. else
  13465. {
  13466. isSuccess = ConfigurationStatus_Rejected;
  13467. }
  13468. }
  13469. if(strcmp(key, "LocalPreAuthorize") == 0)
  13470. {
  13471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13472. {
  13473. strcpy(str, (const char*)value);
  13474. for(int i = 0; str[i]; i++)
  13475. {
  13476. str[i] = tolower(str[i]);
  13477. }
  13478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13479. isSuccess = ConfigurationStatus_Accepted;
  13480. }
  13481. else
  13482. {
  13483. isSuccess = ConfigurationStatus_Rejected;
  13484. }
  13485. }
  13486. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13487. {
  13488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13489. {
  13490. check_ascii = value[0];
  13491. if( (check_ascii < 48) || (check_ascii > 57) )
  13492. {
  13493. isSuccess = ConfigurationStatus_Rejected;
  13494. }
  13495. else
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13498. isSuccess = ConfigurationStatus_Accepted;
  13499. }
  13500. }
  13501. else
  13502. {
  13503. isSuccess = ConfigurationStatus_Rejected;
  13504. }
  13505. }
  13506. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13507. {
  13508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13509. {
  13510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13511. isSuccess = ConfigurationStatus_Accepted;
  13512. }
  13513. else
  13514. {
  13515. isSuccess = ConfigurationStatus_Rejected;
  13516. }
  13517. }
  13518. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13519. {
  13520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13521. {
  13522. check_ascii = value[0];
  13523. if( (check_ascii < 48) || (check_ascii > 57) )
  13524. {
  13525. isSuccess = ConfigurationStatus_Rejected;
  13526. }
  13527. else
  13528. {
  13529. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13531. isSuccess = ConfigurationStatus_Accepted;
  13532. }
  13533. }
  13534. else
  13535. {
  13536. isSuccess = ConfigurationStatus_Rejected;
  13537. }
  13538. }
  13539. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13540. {
  13541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13542. {
  13543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13544. isSuccess = ConfigurationStatus_Accepted;
  13545. }
  13546. else
  13547. {
  13548. isSuccess = ConfigurationStatus_Rejected;
  13549. }
  13550. }
  13551. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13552. {
  13553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13554. {
  13555. check_ascii = value[0];
  13556. if( (check_ascii < 48) || (check_ascii > 57) )
  13557. {
  13558. isSuccess = ConfigurationStatus_Rejected;
  13559. }
  13560. else
  13561. {
  13562. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13564. isSuccess = ConfigurationStatus_Accepted;
  13565. }
  13566. }
  13567. else
  13568. {
  13569. isSuccess = ConfigurationStatus_Rejected;
  13570. }
  13571. }
  13572. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13573. {
  13574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13575. {
  13576. check_ascii = value[0];
  13577. if( (check_ascii < 48) || (check_ascii > 57) )
  13578. {
  13579. isSuccess = ConfigurationStatus_Rejected;
  13580. }
  13581. else
  13582. {
  13583. if((atoi(value) == 0) || (atoi(value) >= 10))
  13584. {
  13585. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13587. isSuccess = ConfigurationStatus_Accepted;
  13588. }
  13589. else
  13590. {
  13591. isSuccess = ConfigurationStatus_Rejected;
  13592. }
  13593. }
  13594. }
  13595. else
  13596. {
  13597. isSuccess = ConfigurationStatus_Rejected;
  13598. }
  13599. }
  13600. if(strcmp(key, "MinimumStatusDuration") == 0)
  13601. {
  13602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13603. {
  13604. check_ascii = value[0];
  13605. if( (check_ascii < 48) || (check_ascii > 57) )
  13606. {
  13607. isSuccess = ConfigurationStatus_Rejected;
  13608. }
  13609. else
  13610. {
  13611. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13612. {
  13613. isSuccess = ConfigurationStatus_Rejected;
  13614. }
  13615. else
  13616. {
  13617. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13619. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13620. isSuccess = ConfigurationStatus_Accepted;
  13621. }
  13622. }
  13623. }
  13624. else
  13625. {
  13626. isSuccess = ConfigurationStatus_Rejected;
  13627. }
  13628. }
  13629. if(strcmp(key, "NumberOfConnectors") == 0)
  13630. {
  13631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13632. {
  13633. check_ascii = value[0];
  13634. if( (check_ascii < 48) || (check_ascii > 57) )
  13635. {
  13636. isSuccess = ConfigurationStatus_Rejected;
  13637. }
  13638. else
  13639. {
  13640. //Charger.ResetRetries = Integer.parseInt(value);
  13641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13642. isSuccess = ConfigurationStatus_Accepted;
  13643. }
  13644. }
  13645. else
  13646. {
  13647. isSuccess = ConfigurationStatus_Rejected;
  13648. }
  13649. }
  13650. if(strcmp(key, "ResetRetries") == 0)
  13651. {
  13652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13653. {
  13654. check_ascii = value[0];
  13655. if( (check_ascii < 48) || (check_ascii > 57) )
  13656. {
  13657. isSuccess = ConfigurationStatus_Rejected;
  13658. }
  13659. else
  13660. {
  13661. //Charger.ResetRetries = Integer.parseInt(value);
  13662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13663. isSuccess = ConfigurationStatus_Accepted;
  13664. }
  13665. }
  13666. else
  13667. {
  13668. isSuccess = ConfigurationStatus_Rejected;
  13669. }
  13670. }
  13671. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13672. {
  13673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13674. {
  13675. strcpy(str, (const char*)value);
  13676. for(int i = 0; str[i]; i++)
  13677. {
  13678. str[i] = tolower(str[i]);
  13679. }
  13680. if(strcmp(str, "notapplicable")== 0)
  13681. {
  13682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13683. isSuccess = ConfigurationStatus_Accepted;
  13684. }
  13685. else if(strcmp(str, "unknown")== 0)
  13686. {
  13687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13688. isSuccess = ConfigurationStatus_Accepted;
  13689. }
  13690. else if(strcmp(str, "rst")== 0)
  13691. {
  13692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13693. isSuccess = ConfigurationStatus_Accepted;
  13694. }
  13695. else if(strcmp(str, "rts")== 0)
  13696. {
  13697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13698. isSuccess = ConfigurationStatus_Accepted;
  13699. }
  13700. else if(strcmp(str, "srt")== 0)
  13701. {
  13702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13703. isSuccess = ConfigurationStatus_Accepted;
  13704. }
  13705. else if(strcmp(str, "str")== 0)
  13706. {
  13707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13708. isSuccess = ConfigurationStatus_Accepted;
  13709. }
  13710. else if(strcmp(str, "trs")== 0)
  13711. {
  13712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13713. isSuccess = ConfigurationStatus_Accepted;
  13714. }
  13715. else if(strcmp(str, "tsr")== 0)
  13716. {
  13717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13718. isSuccess = ConfigurationStatus_Accepted;
  13719. }
  13720. else
  13721. {
  13722. isSuccess = ConfigurationStatus_Rejected;
  13723. }
  13724. }
  13725. else
  13726. {
  13727. isSuccess = ConfigurationStatus_Rejected;
  13728. }
  13729. }
  13730. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13731. {
  13732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13733. {
  13734. check_ascii = value[0];
  13735. if( (check_ascii < 48) || (check_ascii > 57) )
  13736. {
  13737. isSuccess = ConfigurationStatus_Rejected;
  13738. }
  13739. else
  13740. {
  13741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13742. isSuccess = ConfigurationStatus_Accepted;
  13743. }
  13744. }
  13745. else
  13746. {
  13747. isSuccess = ConfigurationStatus_Rejected;
  13748. }
  13749. }
  13750. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13751. {
  13752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13753. {
  13754. strcpy(str, (const char*)value);
  13755. for(int i = 0; str[i]; i++)
  13756. {
  13757. str[i] = tolower(str[i]);
  13758. }
  13759. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13761. isSuccess = ConfigurationStatus_Accepted;
  13762. }
  13763. else
  13764. {
  13765. isSuccess = ConfigurationStatus_Rejected;
  13766. }
  13767. }
  13768. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13769. {
  13770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13771. {
  13772. strcpy(str, (const char*)value);
  13773. for(int i = 0; str[i]; i++)
  13774. {
  13775. str[i] = tolower(str[i]);
  13776. }
  13777. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13779. isSuccess = ConfigurationStatus_Accepted;
  13780. }
  13781. else
  13782. {
  13783. isSuccess = ConfigurationStatus_Rejected;
  13784. }
  13785. }
  13786. if(strcmp(key, "StopTxnAlignedData") == 0)
  13787. {
  13788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13789. {
  13790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13791. isSuccess = ConfigurationStatus_Accepted;
  13792. }
  13793. else
  13794. {
  13795. isSuccess = ConfigurationStatus_Rejected;
  13796. }
  13797. }
  13798. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13799. {
  13800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13801. {
  13802. check_ascii = value[0];
  13803. if( (check_ascii < 48) || (check_ascii > 57) )
  13804. {
  13805. isSuccess = ConfigurationStatus_Rejected;
  13806. }
  13807. else
  13808. {
  13809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13810. isSuccess = ConfigurationStatus_Accepted;
  13811. }
  13812. }
  13813. else
  13814. {
  13815. isSuccess = ConfigurationStatus_Rejected;
  13816. }
  13817. }
  13818. if(strcmp(key, "StopTxnSampledData") == 0)
  13819. {
  13820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13821. {
  13822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13823. isSuccess = ConfigurationStatus_Accepted;
  13824. }
  13825. else
  13826. {
  13827. isSuccess = ConfigurationStatus_Rejected;
  13828. }
  13829. }
  13830. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13831. {
  13832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13833. {
  13834. check_ascii = value[0];
  13835. if( (check_ascii < 48) || (check_ascii > 57) )
  13836. {
  13837. isSuccess = ConfigurationStatus_Rejected;
  13838. }
  13839. else
  13840. {
  13841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13842. isSuccess = ConfigurationStatus_Accepted;
  13843. }
  13844. }
  13845. else
  13846. {
  13847. isSuccess = ConfigurationStatus_Rejected;
  13848. }
  13849. }
  13850. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13851. {
  13852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13853. {
  13854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13855. isSuccess = ConfigurationStatus_Accepted;
  13856. }
  13857. else
  13858. {
  13859. isSuccess = ConfigurationStatus_Rejected;
  13860. }
  13861. }
  13862. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13863. {
  13864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13865. {
  13866. check_ascii = value[0];
  13867. if( (check_ascii < 48) || (check_ascii > 57) )
  13868. {
  13869. isSuccess = ConfigurationStatus_Rejected;
  13870. }
  13871. else
  13872. {
  13873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13874. isSuccess = ConfigurationStatus_Accepted;
  13875. }
  13876. }
  13877. else
  13878. {
  13879. isSuccess = ConfigurationStatus_Rejected;
  13880. }
  13881. }
  13882. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13883. {
  13884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13885. {
  13886. check_ascii = value[0];
  13887. if( (check_ascii < 48) || (check_ascii > 57) )
  13888. {
  13889. isSuccess = ConfigurationStatus_Rejected;
  13890. }
  13891. else
  13892. {
  13893. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13895. TransactionMessageAttemptsValue = atoi(value);
  13896. isSuccess = ConfigurationStatus_Accepted;
  13897. }
  13898. }
  13899. else
  13900. {
  13901. isSuccess = ConfigurationStatus_Rejected;
  13902. }
  13903. }
  13904. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13905. {
  13906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13907. {
  13908. check_ascii = value[0];
  13909. if( (check_ascii < 48) || (check_ascii > 57) )
  13910. {
  13911. isSuccess = ConfigurationStatus_Rejected;
  13912. }
  13913. else
  13914. {
  13915. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13917. TransactionMessageRetryIntervalValue = atoi(value);
  13918. isSuccess = ConfigurationStatus_Accepted;
  13919. }
  13920. }
  13921. else
  13922. {
  13923. isSuccess = ConfigurationStatus_Rejected;
  13924. }
  13925. }
  13926. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13927. {
  13928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13929. {
  13930. strcpy(str, (const char*)value);
  13931. for(int i = 0; str[i]; i++)
  13932. {
  13933. str[i] = tolower(str[i]);
  13934. }
  13935. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13937. isSuccess = ConfigurationStatus_Accepted;
  13938. }
  13939. else
  13940. {
  13941. isSuccess = ConfigurationStatus_Rejected;
  13942. }
  13943. }
  13944. if(strcmp(key, "WebSocketPingInterval") == 0)
  13945. {
  13946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13947. {
  13948. check_ascii = value[0];
  13949. if( (check_ascii < 48) || (check_ascii > 57) )
  13950. {
  13951. isSuccess = ConfigurationStatus_Rejected;
  13952. }
  13953. else
  13954. {
  13955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13956. isSuccess = ConfigurationStatus_Accepted;
  13957. }
  13958. }
  13959. else
  13960. {
  13961. isSuccess = ConfigurationStatus_Rejected;
  13962. }
  13963. }
  13964. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13965. {
  13966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13967. {
  13968. strcpy(str, (const char*)value);
  13969. for(int i = 0; str[i]; i++)
  13970. {
  13971. str[i] = tolower(str[i]);
  13972. }
  13973. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13975. isSuccess = ConfigurationStatus_Accepted;
  13976. }
  13977. else
  13978. {
  13979. isSuccess = ConfigurationStatus_Rejected;
  13980. }
  13981. }
  13982. if(strcmp(key, "AuthorizationKey") == 0)
  13983. {
  13984. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13985. {
  13986. strcpy(str, (const char*)value);
  13987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13988. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13989. isSuccess = ConfigurationStatus_Accepted;
  13990. }
  13991. else
  13992. {
  13993. isSuccess = ConfigurationStatus_Rejected;
  13994. }
  13995. }
  13996. if(strcmp(key, "SecurityProfile") == 0)
  13997. {
  13998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13999. {
  14000. check_ascii = value[0];
  14001. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14002. {
  14003. isSuccess = ConfigurationStatus_Rejected;
  14004. }
  14005. else if(check_ascii == 0x33)
  14006. {
  14007. isSuccess = NotSupported;
  14008. }
  14009. else
  14010. {
  14011. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14012. {
  14013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14014. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14015. isSuccess = ConfigurationStatus_Accepted;
  14016. }
  14017. else
  14018. isSuccess = ConfigurationStatus_Rejected;
  14019. }
  14020. }
  14021. else
  14022. {
  14023. isSuccess = ConfigurationStatus_Rejected;
  14024. }
  14025. }
  14026. if(strcmp(key, "DefaultPrice") == 0)
  14027. {
  14028. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14029. {
  14030. strcpy(str, (const char*)value);
  14031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14032. isSuccess = ConfigurationStatus_Accepted;
  14033. }
  14034. else
  14035. {
  14036. isSuccess = ConfigurationStatus_Rejected;
  14037. }
  14038. }
  14039. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14040. {
  14041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14042. {
  14043. strcpy(str, (const char*)value);
  14044. for(int i = 0; str[i]; i++)
  14045. {
  14046. str[i] = tolower(str[i]);
  14047. }
  14048. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14050. isSuccess = ConfigurationStatus_Accepted;
  14051. }
  14052. else
  14053. {
  14054. isSuccess = ConfigurationStatus_Rejected;
  14055. }
  14056. }
  14057. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14058. {
  14059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14060. {
  14061. strcpy(str, (const char*)value);
  14062. for(int i = 0; str[i]; i++)
  14063. {
  14064. str[i] = tolower(str[i]);
  14065. }
  14066. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14068. isSuccess = ConfigurationStatus_Accepted;
  14069. }
  14070. else
  14071. {
  14072. isSuccess = ConfigurationStatus_Rejected;
  14073. }
  14074. }
  14075. if(strcmp(key, "TimeOffset") == 0)
  14076. {
  14077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14078. {
  14079. strcpy(str, (const char*)value);
  14080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14081. isSuccess = ConfigurationStatus_Accepted;
  14082. }
  14083. else
  14084. {
  14085. isSuccess = ConfigurationStatus_Rejected;
  14086. }
  14087. }
  14088. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14089. {
  14090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14091. {
  14092. strcpy(str, (const char*)value);
  14093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14094. isSuccess = ConfigurationStatus_Accepted;
  14095. }
  14096. else
  14097. {
  14098. isSuccess = ConfigurationStatus_Rejected;
  14099. }
  14100. }
  14101. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14102. {
  14103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14104. {
  14105. strcpy(str, (const char*)value);
  14106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14107. isSuccess = ConfigurationStatus_Accepted;
  14108. }
  14109. else
  14110. {
  14111. isSuccess = ConfigurationStatus_Rejected;
  14112. }
  14113. }
  14114. #if 0
  14115. //For OCPP Test Case
  14116. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14117. {
  14118. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14119. {
  14120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14121. isSuccess = ConfigurationStatus_Accepted;
  14122. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14123. }
  14124. else
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. }
  14129. #endif
  14130. #if 1
  14131. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14132. {
  14133. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14134. {
  14135. strcpy(str, (const char*)value);
  14136. for(int i = 0; str[i]; i++)
  14137. {
  14138. str[i] = tolower(str[i]);
  14139. }
  14140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14141. isSuccess = ConfigurationStatus_Accepted;
  14142. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14143. }
  14144. else
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. }
  14149. #endif
  14150. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14151. {
  14152. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14153. {
  14154. check_ascii = value[0];
  14155. if( (check_ascii < 48) || (check_ascii > 57) )
  14156. {
  14157. isSuccess = ConfigurationStatus_Rejected;
  14158. }
  14159. else
  14160. {
  14161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14162. isSuccess = ConfigurationStatus_Accepted;
  14163. }
  14164. }
  14165. else
  14166. {
  14167. isSuccess = ConfigurationStatus_Rejected;
  14168. }
  14169. }
  14170. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14171. {
  14172. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14173. {
  14174. check_ascii = value[0];
  14175. if( (check_ascii < 48) || (check_ascii > 57) )
  14176. {
  14177. isSuccess = ConfigurationStatus_Rejected;
  14178. }
  14179. else
  14180. {
  14181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14182. isSuccess = ConfigurationStatus_Accepted;
  14183. }
  14184. }
  14185. else
  14186. {
  14187. isSuccess = ConfigurationStatus_Rejected;
  14188. }
  14189. }
  14190. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14191. {
  14192. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14193. {
  14194. strcpy(str, (const char*)value);
  14195. for(int i = 0; str[i]; i++)
  14196. {
  14197. str[i] = tolower(str[i]);
  14198. }
  14199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14200. isSuccess = ConfigurationStatus_Accepted;
  14201. }
  14202. else
  14203. {
  14204. isSuccess = ConfigurationStatus_Rejected;
  14205. }
  14206. }
  14207. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14208. {
  14209. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14210. {
  14211. check_ascii = value[0];
  14212. if( (check_ascii < 48) || (check_ascii > 57) )
  14213. {
  14214. isSuccess = ConfigurationStatus_Rejected;
  14215. }
  14216. else
  14217. {
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14219. isSuccess = ConfigurationStatus_Accepted;
  14220. }
  14221. }
  14222. else
  14223. {
  14224. isSuccess = ConfigurationStatus_Rejected;
  14225. }
  14226. }
  14227. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14228. {
  14229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14230. {
  14231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14232. isSuccess = ConfigurationStatus_Accepted;
  14233. }
  14234. else
  14235. {
  14236. isSuccess = ConfigurationStatus_Rejected;
  14237. }
  14238. }
  14239. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14240. {
  14241. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14242. {
  14243. check_ascii = value[0];
  14244. if( (check_ascii < 48) || (check_ascii > 57) )
  14245. {
  14246. isSuccess = ConfigurationStatus_Rejected;
  14247. }
  14248. else
  14249. {
  14250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14251. isSuccess = ConfigurationStatus_Accepted;
  14252. }
  14253. }
  14254. else
  14255. {
  14256. isSuccess = ConfigurationStatus_Rejected;
  14257. }
  14258. }
  14259. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14260. {
  14261. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14262. {
  14263. strcpy(str, (const char*)value);
  14264. for(int i = 0; str[i]; i++)
  14265. {
  14266. str[i] = tolower(str[i]);
  14267. }
  14268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14269. isSuccess = ConfigurationStatus_Accepted;
  14270. }
  14271. else
  14272. {
  14273. isSuccess = ConfigurationStatus_Rejected;
  14274. }
  14275. }
  14276. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14277. {
  14278. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14279. {
  14280. check_ascii = value[0];
  14281. if( (check_ascii < 48) || (check_ascii > 57) )
  14282. {
  14283. isSuccess = ConfigurationStatus_Rejected;
  14284. }
  14285. else
  14286. {
  14287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14288. isSuccess = ConfigurationStatus_Accepted;
  14289. }
  14290. }
  14291. else
  14292. {
  14293. isSuccess = ConfigurationStatus_Rejected;
  14294. }
  14295. }
  14296. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14297. return isSuccess;
  14298. }
  14299. int TransactionMessageAttemptsGet(void)
  14300. {
  14301. return TransactionMessageAttemptsValue;
  14302. }
  14303. int FirstHeartBeatResponse(void)
  14304. {
  14305. return FirstHeartBeat;
  14306. }
  14307. int TransactionMessageRetryIntervalGet(void)
  14308. {
  14309. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14310. }
  14311. int ReadHttpStatus(int sock)
  14312. {
  14313. //char c;
  14314. char buff[1024]="",*ptr=buff+1;
  14315. int bytes_received, status;
  14316. DEBUG_INFO("Begin Response ..\n");
  14317. while((bytes_received = recv(sock, ptr, 1, 0))){
  14318. if(bytes_received==-1){
  14319. perror("ReadHttpStatus");
  14320. exit(1);
  14321. }
  14322. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14323. ptr++;
  14324. }
  14325. *ptr=0;
  14326. ptr=buff+1;
  14327. sscanf(ptr,"%*s %d ", &status);
  14328. DEBUG_INFO("%s\n",ptr);
  14329. DEBUG_INFO("status=%d\n",status);
  14330. DEBUG_INFO("End Response ..\n");
  14331. return (bytes_received>0)?status:0;
  14332. }
  14333. //the only filed that it parsed is 'Content-Length'
  14334. int ParseHeader(int sock)
  14335. {
  14336. //char c;
  14337. char buff[1024]="",*ptr=buff+4;
  14338. int bytes_received;
  14339. DEBUG_INFO("Begin HEADER ..\n");
  14340. while((bytes_received = recv(sock, ptr, 1, 0))){
  14341. if(bytes_received==-1){
  14342. perror("Parse Header");
  14343. exit(1);
  14344. }
  14345. if(
  14346. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14347. (ptr[-1]=='\r') && (*ptr=='\n' )
  14348. ) break;
  14349. ptr++;
  14350. }
  14351. *ptr=0;
  14352. ptr=buff+4;
  14353. //printf("%s",ptr);
  14354. if(bytes_received){
  14355. ptr=strstr(ptr,"Content-Length:");
  14356. if(ptr){
  14357. sscanf(ptr,"%*s %d",&bytes_received);
  14358. }else
  14359. bytes_received=-1; //unknown size
  14360. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14361. }
  14362. DEBUG_INFO("End HEADER ..\n");
  14363. return bytes_received ;
  14364. }
  14365. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14366. {
  14367. int result = TRUE;
  14368. char rmFileCmd[100]={0};
  14369. char FilePath[100]={0};
  14370. char ftpbuf[200];
  14371. int systemresult;
  14372. //DEBUG_INFO("filename=%s\n",filename);
  14373. //DEBUG_INFO("url=%s\n",url);
  14374. sprintf(FilePath,"/mnt/%s",filename);
  14375. system("ping 8.8.8.8 &");
  14376. if((access(FilePath,F_OK))!=-1)
  14377. {
  14378. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14379. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14380. system(rmFileCmd);
  14381. }
  14382. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14383. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14384. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14385. systemresult = system(ftpbuf);
  14386. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14387. if(systemresult != 0)
  14388. {
  14389. DEBUG_INFO("http DownLoad error!\n");
  14390. result = FALSE;
  14391. }
  14392. system("pkill ping");
  14393. return result;
  14394. }
  14395. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14396. {
  14397. int result = TRUE;
  14398. char rmFileCmd[100]={0};
  14399. char FilePath[100]={0};
  14400. char ftpbuf[200];
  14401. int systemresult;
  14402. //char temp[100];
  14403. sprintf(FilePath,"/mnt/%s",filename);
  14404. system("ping 8.8.8.8 &");
  14405. if((access(FilePath,F_OK))!=-1)
  14406. {
  14407. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14408. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14409. system(rmFileCmd);
  14410. }
  14411. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14412. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14413. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14414. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14415. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14416. systemresult = system(ftpbuf);
  14417. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14418. if(systemresult != 0)
  14419. {
  14420. printf("wget error!\n");
  14421. result = FALSE;
  14422. }
  14423. system("pkill ping");
  14424. return result;
  14425. }
  14426. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14427. {
  14428. char rmFileCmd[100]={0};
  14429. char FilePath[100]={0};
  14430. char buf[512];
  14431. int systemresult = 0;
  14432. //DEBUG_INFO("filename=%s\n",filename);
  14433. //DEBUG_INFO("url=%s\n",url);
  14434. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14435. if((access(FilePath,F_OK))!=-1)
  14436. {
  14437. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14438. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14439. system(rmFileCmd);
  14440. }
  14441. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14442. if(fp == NULL)
  14443. {
  14444. DEBUG_INFO("log is NULL\n");
  14445. return FALSE;
  14446. }
  14447. else
  14448. {
  14449. fprintf(fp, "%s\n", url);
  14450. fprintf(fp, "%s\n", filename);
  14451. fclose(fp);
  14452. }
  14453. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14454. if(phpFP == NULL)
  14455. {
  14456. DEBUG_INFO("PHP upload fail.\n");
  14457. return FALSE;
  14458. }
  14459. else
  14460. {
  14461. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14462. {
  14463. if(strstr(buf, "result") != NULL)
  14464. {
  14465. sscanf(buf, "result: %d", &systemresult);
  14466. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14467. }
  14468. }
  14469. pclose(phpFP);
  14470. }
  14471. if(systemresult != 1)
  14472. {
  14473. DEBUG_INFO("HTTP upload error!\n");
  14474. return FALSE;
  14475. }
  14476. return TRUE;
  14477. }
  14478. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14479. {
  14480. struct hostent* server;
  14481. char *IPbuffer;
  14482. char ftpbuf[200];
  14483. int systemresult;
  14484. // To retrieve host information
  14485. server = gethostbyname(location);
  14486. // To convert an Internet network
  14487. // address into ASCII string
  14488. IPbuffer = inet_ntoa(*((struct in_addr*)
  14489. server->h_addr_list[0]));
  14490. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14491. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14492. /* format : ftpput -u username -p passwd IP target source*/
  14493. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14494. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14495. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14496. systemresult = system(ftpbuf);
  14497. DEBUG_INFO("systemresult=%d\n",systemresult);
  14498. if(systemresult != 0)
  14499. {
  14500. DEBUG_INFO("ftpput error!\n");
  14501. return FALSE;
  14502. }
  14503. return TRUE;
  14504. }
  14505. int GetOcppServerURL()
  14506. {
  14507. int result = FALSE;
  14508. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14509. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14510. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14511. struct yuarel url;
  14512. char urlStr[512];
  14513. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14514. {
  14515. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14516. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14517. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14518. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14519. if(yuarel_parse(&url, urlStr) != -1)
  14520. {
  14521. sprintf(OcppProtocol, "%s", url.scheme);
  14522. sprintf(OcppHost, "%s", url.host);
  14523. if(url.path == NULL)
  14524. OcppTempPath[0] = '\0';
  14525. else
  14526. {
  14527. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14528. {
  14529. sprintf(OcppTempPath, "%s/", url.path);
  14530. }
  14531. else
  14532. {
  14533. sprintf(OcppTempPath, "%s", url.path);
  14534. }
  14535. }
  14536. if(url.port == 0)
  14537. {
  14538. if(strcmp(OcppProtocol, "wss") == 0)
  14539. OcppPort = 443;
  14540. else
  14541. OcppPort = 80;
  14542. }
  14543. else
  14544. OcppPort = url.port;
  14545. result = TRUE;
  14546. }
  14547. }
  14548. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14549. {
  14550. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14551. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14552. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14553. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14554. if(yuarel_parse(&url, urlStr) != -1)
  14555. {
  14556. sprintf(OcppProtocol, "%s", url.scheme);
  14557. sprintf(OcppHost, "%s", url.host);
  14558. if(url.path == NULL)
  14559. OcppTempPath[0] = '\0';
  14560. else
  14561. sprintf(OcppTempPath, "%s", url.path);
  14562. if(url.port == 0)
  14563. {
  14564. if(strcmp(OcppProtocol, "wss") == 0)
  14565. OcppPort = 443;
  14566. else
  14567. OcppPort = 80;
  14568. }
  14569. else
  14570. OcppPort = url.port;
  14571. result = TRUE;
  14572. }
  14573. }
  14574. else
  14575. {
  14576. strcpy(OcppHost,"");
  14577. }
  14578. return result;
  14579. }
  14580. int GetOcppPath()
  14581. {
  14582. int result = FALSE;
  14583. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14584. {
  14585. if(OcppTempPath == NULL)
  14586. {
  14587. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14588. }
  14589. else
  14590. {
  14591. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14592. }
  14593. result = TRUE;
  14594. goto End;
  14595. }
  14596. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14597. {
  14598. if(OcppTempPath == NULL)
  14599. {
  14600. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14601. }
  14602. else
  14603. {
  14604. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14605. }
  14606. result = TRUE;
  14607. goto End;
  14608. }
  14609. else
  14610. {
  14611. strcpy(OcppPath,"");
  14612. }
  14613. End:
  14614. return result;
  14615. }
  14616. int GetOcppPort()
  14617. {
  14618. return OcppPort;
  14619. }
  14620. int GetOcppConnStatus(void)
  14621. {
  14622. return ShmOCPP16Data->OcppConnStatus;
  14623. }
  14624. void SetOcppConnStatus(uint8_t status)
  14625. {
  14626. ShmOCPP16Data->OcppConnStatus = status;
  14627. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14628. }
  14629. int GetHeartBeatWithNOResponse(void)
  14630. {
  14631. return HeartBeatWithNOResponse;
  14632. }
  14633. void SetHeartBeatWithNOResponse(void)
  14634. {
  14635. HeartBeatWithNOResponse = 0;
  14636. }
  14637. void GetStartTransactionIdTag(int gun_index)
  14638. {
  14639. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14640. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14641. }
  14642. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14643. {
  14644. char ch;
  14645. FILE *fptr1;
  14646. int temptransactionId;
  14647. char str[100]={0};
  14648. temptransactionId = 0;
  14649. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14650. {
  14651. DEBUG_INFO("IdTag is empty.\n");
  14652. return temptransactionId;
  14653. }
  14654. /*------ Read the file ----------------*/
  14655. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14656. if (!fptr1)
  14657. {
  14658. DEBUG_INFO("QueueTransactionId file open error.\n");
  14659. //printf(" File not found or unable to open the input file!!\n");
  14660. return temptransactionId;
  14661. }
  14662. ch=fgetc(fptr1);
  14663. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14664. rewind(fptr1);
  14665. if(ch!=EOF)
  14666. {
  14667. // printf("%c",ch);
  14668. while (fgets(str, 100, fptr1) != NULL)
  14669. {
  14670. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14671. if(str[0]=='\0')
  14672. {
  14673. break;
  14674. }
  14675. char *revbuf[8] = {0}; // Variable store string split
  14676. int num = 0;// Quantity after string split
  14677. DEBUG_INFO("Transaction queue data= %s\n", str);
  14678. splitstring(str,",",revbuf,&num); // String split
  14679. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14680. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14681. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14682. DEBUG_INFO("------------------------------\n");
  14683. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14684. {
  14685. if(isStopTransaction)
  14686. {
  14687. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14688. {
  14689. temptransactionId = atoi(revbuf[2]);
  14690. //break;
  14691. }
  14692. }
  14693. else
  14694. {
  14695. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14696. {
  14697. temptransactionId = atoi(revbuf[2]);
  14698. //break;
  14699. }
  14700. }
  14701. }
  14702. }
  14703. }
  14704. else
  14705. DEBUG_INFO("EOF\n");
  14706. fclose(fptr1);
  14707. /*------- End of reading ---------------*/
  14708. return temptransactionId;
  14709. }
  14710. void SetTransactionIdZero(int transactionId)
  14711. {
  14712. char ch;
  14713. FILE *fptr1, *fptr2;
  14714. int temptransactionId = 0;
  14715. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14716. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14717. if (!fptr1)
  14718. {
  14719. //printf(" File not found or unable to open the input file!!\n");
  14720. return ;
  14721. }
  14722. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14723. if (!fptr2)
  14724. {
  14725. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14726. fclose(fptr1);
  14727. return ;
  14728. }
  14729. ch=fgetc(fptr1);
  14730. rewind(fptr1);
  14731. if(ch!=EOF)
  14732. {
  14733. // copy all contents to the temporary file except the specific line
  14734. while (fgets(str, 100, fptr1) != NULL)
  14735. {
  14736. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14737. if(str[0]=='\0')
  14738. {
  14739. break;
  14740. }
  14741. char *revbuf[8] = {0};
  14742. int num = 0;
  14743. strcpy(strtemp, str);
  14744. splitstring(str,",",revbuf,&num);
  14745. if(revbuf[2][0] != '\0')
  14746. {
  14747. temptransactionId = atoi(revbuf[2]);
  14748. if(transactionId != temptransactionId)
  14749. {
  14750. fprintf(fptr2, "%s\n", strtemp);
  14751. }
  14752. }
  14753. }
  14754. }
  14755. fclose(fptr1);
  14756. fclose(fptr2);
  14757. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14758. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14759. /*------ Read the file ----------------*/
  14760. }
  14761. int InternetDisconnect(void)
  14762. {
  14763. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14764. }
  14765. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14766. void storeTempStopTransaction(int gun_index)
  14767. {
  14768. char guid[37]={0};
  14769. int tempIndex = 0;
  14770. char TempStopTransaction[256];
  14771. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14772. DEBUG_INFO("storeTempStopTransaction...\n");
  14773. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14774. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14775. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14778. {
  14779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14780. {
  14781. tempIndex = ((gun_index==2) ? 1: 0);
  14782. }
  14783. else
  14784. {
  14785. tempIndex = gun_index;
  14786. }
  14787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14788. {
  14789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14790. {
  14791. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14792. }
  14793. }// END OF CHAdeMO_QUANTITY
  14794. }
  14795. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14796. {
  14797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14798. {
  14799. tempIndex = ((gun_index==2) ? 1: 0);
  14800. }
  14801. else
  14802. {
  14803. tempIndex = gun_index;
  14804. }
  14805. for (int index = 0; index < CCS_QUANTITY; index++)
  14806. {
  14807. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14808. {
  14809. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14810. }
  14811. }// END OF CCS_QUANTITY
  14812. }
  14813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14814. {
  14815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14816. {
  14817. tempIndex = ((gun_index==2) ? 1: 0);
  14818. }
  14819. else
  14820. {
  14821. tempIndex = gun_index;
  14822. }
  14823. for (int index = 0; index < GB_QUANTITY; index++)
  14824. {
  14825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14826. {
  14827. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14828. }
  14829. }// END OF GB_QUANTITY
  14830. }
  14831. else if(gunType[gun_index] == GUN_TYPE_DO)
  14832. {
  14833. tempIndex = gun_index;
  14834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14835. {
  14836. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14837. {
  14838. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14839. }
  14840. }
  14841. }
  14842. else
  14843. {
  14844. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14845. {
  14846. tempIndex = 2;
  14847. }
  14848. else
  14849. {
  14850. tempIndex = gun_index;
  14851. }
  14852. for (int index = 0; index < AC_QUANTITY; index++)
  14853. {
  14854. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14855. {
  14856. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14857. }
  14858. }// END OF AC_QUANTITY
  14859. }
  14860. //Stop Transaction Time
  14861. struct timeval tmnow;
  14862. struct tm *tm;
  14863. char buf[28];//, usec_buf[6];
  14864. gettimeofday(&tmnow, NULL);
  14865. time_t t;
  14866. t = time(NULL);
  14867. /*UTC time and date*/
  14868. tm = gmtime(&t);
  14869. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14871. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14873. random_uuid(guid);
  14874. /***********************************transactionData******************************************************/
  14875. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14877. //=================================
  14878. //1. Transaction_Begin
  14879. //=================================
  14880. //============================== Energy.Active.Import.Interval ===========================================
  14881. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14882. {
  14883. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14886. 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*/]);
  14887. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14888. 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))
  14889. {
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14891. }
  14892. else
  14893. {
  14894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14895. }
  14896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14898. }
  14899. //=================================
  14900. //2. Transaction_End
  14901. //=================================
  14902. //2.1====================================== Current.Import L1 ==============================================
  14903. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14904. {
  14905. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14906. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14907. {
  14908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14909. {
  14910. tempIndex = ((gun_index==2) ? 1: 0);
  14911. }
  14912. else
  14913. {
  14914. tempIndex = gun_index;
  14915. }
  14916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14917. {
  14918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14919. {
  14920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14921. }
  14922. }// End of for CHAdeMO_QUANTITY
  14923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14924. }
  14925. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14926. {
  14927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14928. {
  14929. tempIndex = ((gun_index==2) ? 1: 0);
  14930. }
  14931. else
  14932. {
  14933. tempIndex = gun_index;
  14934. }
  14935. for (int index = 0; index < CCS_QUANTITY; index++)
  14936. {
  14937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14938. {
  14939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14940. }
  14941. }// End of for CCS_QUANTITY
  14942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14943. }
  14944. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14945. {
  14946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14947. {
  14948. tempIndex = ((gun_index==2) ? 1: 0);
  14949. }
  14950. else
  14951. {
  14952. tempIndex = gun_index;
  14953. }
  14954. for (int index = 0; index < GB_QUANTITY; index++)
  14955. {
  14956. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14957. {
  14958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14959. }
  14960. }// End of for GB_QUANTITY
  14961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14962. }
  14963. else if(gunType[gun_index] == GUN_TYPE_DO)
  14964. {
  14965. tempIndex = gun_index;
  14966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14967. {
  14968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14969. {
  14970. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14971. }
  14972. }
  14973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14974. }
  14975. else
  14976. {
  14977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14978. {
  14979. tempIndex = 2;
  14980. }
  14981. else
  14982. {
  14983. tempIndex = gun_index;
  14984. }
  14985. for (int index = 0; index < AC_QUANTITY; index++)
  14986. {
  14987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14988. {
  14989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14990. }
  14991. }// End of for AC_QUANTITY
  14992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14993. }
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14997. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15000. }
  15001. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15002. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15003. {
  15004. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15005. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15006. {
  15007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15008. {
  15009. tempIndex = ((gun_index==2) ? 1: 0);
  15010. }
  15011. else
  15012. {
  15013. tempIndex = gun_index;
  15014. }
  15015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15016. {
  15017. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15018. {
  15019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15020. }
  15021. }// END OF CHAdeMO_QUANTITY
  15022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15023. }
  15024. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15025. {
  15026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15027. {
  15028. tempIndex = ((gun_index==2) ? 1: 0);
  15029. }
  15030. else
  15031. {
  15032. tempIndex = gun_index;
  15033. }
  15034. for (int index = 0; index < CCS_QUANTITY; index++)
  15035. {
  15036. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15037. {
  15038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15039. }
  15040. }// END OF CCS_QUANTITY
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15042. }
  15043. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15044. {
  15045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15046. {
  15047. tempIndex = ((gun_index==2) ? 1: 0);
  15048. }
  15049. else
  15050. {
  15051. tempIndex = gun_index;
  15052. }
  15053. for (int index = 0; index < GB_QUANTITY; index++)
  15054. {
  15055. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15056. {
  15057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15058. }
  15059. }// END OF GB_QUANTITY
  15060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15061. }
  15062. else if(gunType[gun_index] == GUN_TYPE_DO)
  15063. {
  15064. tempIndex = gun_index;
  15065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15066. {
  15067. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15068. {
  15069. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15070. }
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15073. }
  15074. else
  15075. {
  15076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15077. {
  15078. tempIndex = 2;
  15079. }
  15080. else
  15081. {
  15082. tempIndex = gun_index;
  15083. }
  15084. for (int index = 0; index < AC_QUANTITY; index++)
  15085. {
  15086. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15087. {
  15088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15089. }
  15090. }// END OF AC_QUANTITY
  15091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15092. }
  15093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15096. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15099. }
  15100. //2.3====================================== Power.Active.Import =========================================
  15101. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15102. {
  15103. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15104. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15105. {
  15106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15107. {
  15108. tempIndex = ((gun_index==2) ? 1: 0);
  15109. }
  15110. else
  15111. {
  15112. tempIndex = gun_index;
  15113. }
  15114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15115. {
  15116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15117. {
  15118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15119. }
  15120. } // End for CHAdeMO_QUANTITY
  15121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15122. }
  15123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15124. {
  15125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15126. {
  15127. tempIndex = ((gun_index==2) ? 1: 0);
  15128. }
  15129. else
  15130. {
  15131. tempIndex = gun_index;
  15132. }
  15133. for (int index = 0; index < CCS_QUANTITY; index++)
  15134. {
  15135. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15136. {
  15137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15138. }
  15139. } // END for CCS_QUANTITY
  15140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15141. }
  15142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15143. {
  15144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15145. {
  15146. tempIndex = ((gun_index==2) ? 1: 0);
  15147. }
  15148. else
  15149. {
  15150. tempIndex = gun_index;
  15151. }
  15152. for (int index = 0; index < GB_QUANTITY; index++)
  15153. {
  15154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15155. {
  15156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15157. }
  15158. }// END for GB_QUANTITY
  15159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15160. }
  15161. else if(gunType[gun_index] == GUN_TYPE_DO)
  15162. {
  15163. tempIndex = gun_index;
  15164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15165. {
  15166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15167. {
  15168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15169. }
  15170. }
  15171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15172. }
  15173. else
  15174. {
  15175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15176. {
  15177. tempIndex = 2;
  15178. }
  15179. else
  15180. {
  15181. tempIndex = gun_index;
  15182. }
  15183. for (int index = 0; index < AC_QUANTITY; index++)
  15184. {
  15185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15186. {
  15187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15188. }
  15189. } // END for AC_QUANTITY
  15190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15191. }
  15192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15195. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15198. }
  15199. //2.4====================================== Voltage L1 ====================================================
  15200. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15201. {
  15202. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15203. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15204. {
  15205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15206. {
  15207. tempIndex = ((gun_index==2) ? 1: 0);
  15208. }
  15209. else
  15210. {
  15211. tempIndex = gun_index;
  15212. }
  15213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15214. {
  15215. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15216. {
  15217. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15218. }
  15219. } // END OF FOR CHAdeMO_QUANTITY
  15220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15221. }
  15222. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15223. {
  15224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15225. {
  15226. tempIndex = ((gun_index==2) ? 1: 0);
  15227. }
  15228. else
  15229. {
  15230. tempIndex = gun_index;
  15231. }
  15232. for (int index = 0; index < CCS_QUANTITY; index++)
  15233. {
  15234. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15235. {
  15236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15237. }
  15238. } // END OF FOR CCS_QUANTITY
  15239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15240. }
  15241. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15242. {
  15243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15244. {
  15245. tempIndex = ((gun_index==2) ? 1: 0);
  15246. }
  15247. else
  15248. {
  15249. tempIndex = gun_index;
  15250. }
  15251. for (int index = 0; index < GB_QUANTITY; index++)
  15252. {
  15253. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15254. {
  15255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15256. }
  15257. } // END OF FOR GB_QUANTITY
  15258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15259. }
  15260. else if(gunType[gun_index] == GUN_TYPE_DO)
  15261. {
  15262. tempIndex = gun_index;
  15263. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15264. {
  15265. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15266. {
  15267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15268. }
  15269. }
  15270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15271. }
  15272. else
  15273. {
  15274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15275. {
  15276. tempIndex = 2;
  15277. }
  15278. else
  15279. {
  15280. tempIndex = gun_index;
  15281. }
  15282. for (int index = 0; index < AC_QUANTITY; index++)
  15283. {
  15284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15285. {
  15286. 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
  15287. }
  15288. } // END OF FOR AC_QUANTITY
  15289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15290. }
  15291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15294. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15297. }
  15298. //2.5============================================== End SoC =========================================================
  15299. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15300. {
  15301. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15302. 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))
  15303. {
  15304. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15305. {
  15306. tempIndex = ((gun_index==2) ? 1: 0);
  15307. }
  15308. else
  15309. {
  15310. tempIndex = gun_index;
  15311. }
  15312. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15313. {
  15314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15315. {
  15316. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15317. {
  15318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15319. }
  15320. }
  15321. }
  15322. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15323. {
  15324. for (int index = 0; index < CCS_QUANTITY; index++)
  15325. {
  15326. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15327. {
  15328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15329. }
  15330. }
  15331. }
  15332. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15333. {
  15334. for (int index = 0; index < GB_QUANTITY; index++)
  15335. {
  15336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15337. {
  15338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15339. }
  15340. }
  15341. }
  15342. else if(gunType[gun_index] == GUN_TYPE_DO)
  15343. {
  15344. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15345. {
  15346. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15347. {
  15348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15349. }
  15350. }
  15351. }
  15352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15358. } // END FOR DC CASE
  15359. }
  15360. //2.6====================================== Current.Import L2 ==============================================
  15361. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15362. {
  15363. // AC 3 phase L2 current
  15364. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15365. {
  15366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15367. {
  15368. tempIndex = 2;
  15369. }
  15370. else
  15371. {
  15372. tempIndex = gun_index;
  15373. }
  15374. for (int index = 0; index < AC_QUANTITY; index++)
  15375. {
  15376. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15377. {
  15378. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15379. }
  15380. }// End of for AC_QUANTITY
  15381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15382. }
  15383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15388. }
  15389. //2.7====================================== Current.Import L3 ==============================================
  15390. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15391. {
  15392. // AC 3 phase L3 current
  15393. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15394. {
  15395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15396. {
  15397. tempIndex = 2;
  15398. }
  15399. else
  15400. {
  15401. tempIndex = gun_index;
  15402. }
  15403. for (int index = 0; index < AC_QUANTITY; index++)
  15404. {
  15405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15406. {
  15407. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15408. }
  15409. }// End of for AC_QUANTITY
  15410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15411. }
  15412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15417. }
  15418. //2.9====================================== Voltage L2 ====================================================
  15419. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15420. {
  15421. // AC 3 phase L2 volatge
  15422. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15423. {
  15424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15425. {
  15426. tempIndex = 2;
  15427. }
  15428. else
  15429. {
  15430. tempIndex = gun_index;
  15431. }
  15432. for (int index = 0; index < AC_QUANTITY; index++)
  15433. {
  15434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15435. {
  15436. 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
  15437. }
  15438. } // END OF FOR AC_QUANTITY
  15439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15440. }
  15441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15446. }
  15447. //2.10====================================== Voltage L3 ====================================================
  15448. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15449. {
  15450. // AC 3 phase L3 volatge
  15451. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15452. {
  15453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15454. {
  15455. tempIndex = 2;
  15456. }
  15457. else
  15458. {
  15459. tempIndex = gun_index;
  15460. }
  15461. for (int index = 0; index < AC_QUANTITY; index++)
  15462. {
  15463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15464. {
  15465. 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
  15466. }
  15467. } // END OF FOR AC_QUANTITY
  15468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15469. }
  15470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15475. }
  15476. //====================== Start SoC ================================
  15477. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15478. {
  15479. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15480. 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))
  15481. {
  15482. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15483. {
  15484. tempIndex = ((gun_index==2) ? 1: 0);
  15485. }
  15486. else
  15487. {
  15488. tempIndex = gun_index;
  15489. }
  15490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15491. {
  15492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15493. {
  15494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15495. {
  15496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15497. }
  15498. }
  15499. }
  15500. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15501. {
  15502. for (int index = 0; index < CCS_QUANTITY; index++)
  15503. {
  15504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15505. {
  15506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15507. }
  15508. }
  15509. }
  15510. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15511. {
  15512. for (int index = 0; index < GB_QUANTITY; index++)
  15513. {
  15514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15515. {
  15516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15517. }
  15518. }
  15519. }
  15520. else if(gunType[gun_index] == GUN_TYPE_DO)
  15521. {
  15522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15523. {
  15524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15525. {
  15526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15527. }
  15528. }
  15529. }
  15530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15536. } // END FOR DC CASE
  15537. }
  15538. //======================================== Message create ==============================================
  15539. json_object *StopTransaction = json_object_new_object();
  15540. json_object *transactionDatas = json_object_new_array();
  15541. json_object *sampledValues = json_object_new_array();
  15542. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15543. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15544. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15545. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15546. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15547. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15548. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15549. {
  15550. json_object *transactionData = json_object_new_object();
  15551. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15552. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15553. {
  15554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15555. {
  15556. json_object *sampledValue = json_object_new_object();
  15557. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15558. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15559. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15561. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15563. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15565. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15567. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15569. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15570. json_object_array_add(sampledValues, sampledValue);
  15571. }
  15572. }
  15573. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15574. json_object_array_add(transactionDatas, transactionData);
  15575. }
  15576. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15577. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15578. ,MESSAGE_TYPE_CALL
  15579. ,guid
  15580. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15581. json_object_put(StopTransaction);
  15582. // Check File "TempStopTransaction" Exist
  15583. if((access(TempStopTransaction,F_OK))!=-1)
  15584. {
  15585. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15586. fclose(fopen(TempStopTransaction, "w"));
  15587. }
  15588. else
  15589. {
  15590. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15591. FILE *log = fopen(TempStopTransaction, "w+");
  15592. if(log == NULL)
  15593. {
  15594. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15595. return ;
  15596. }
  15597. else
  15598. {
  15599. fclose(log);
  15600. }
  15601. }
  15602. //Add TempStopTransaction | Update TempStopTransaction
  15603. // open file for writing
  15604. FILE *outfile;
  15605. outfile = fopen (TempStopTransaction, "a");
  15606. //DEBUG_INFO("data = %s\n", queuedata);
  15607. fputs(queuedata, outfile);
  15608. fputs("\n", outfile);
  15609. fclose (outfile);
  15610. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15611. }
  15612. void checkTempStopTransaction(int gun_index)
  15613. {
  15614. FILE *fptr1;
  15615. char ch;
  15616. char str[QUEUE_MESSAGE_LENGTH]={0};
  15617. char guid[37]={0};
  15618. char tempdata[65]={0};
  15619. char connectorStr[2]={0};
  15620. char TempStopTransaction[256];
  15621. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15622. fptr1 = fopen(TempStopTransaction, "r");
  15623. //TempStopTransaction格式: 槍號,StopTransaction封包
  15624. if (!fptr1)
  15625. {
  15626. //printf(" File not found or unable to open the input file!!\n");
  15627. return ;
  15628. }
  15629. ch=fgetc(fptr1);
  15630. //printf(" Now the content of the file %s is : \n",fname);
  15631. rewind(fptr1);
  15632. if(ch!=EOF)
  15633. {
  15634. // copy all contents to the temporary file except the specific line
  15635. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15636. {
  15637. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15638. if(str[0]=='\0')
  15639. {
  15640. break;
  15641. }
  15642. //TempStopTransaction格式: 槍號,StopTransaction封包
  15643. strncpy(connectorStr, str, 1);
  15644. if(atoi(connectorStr) != (gun_index+1))
  15645. {
  15646. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15647. fclose(fptr1);
  15648. return ;
  15649. }
  15650. //random_uuid(guid);
  15651. strncpy(guid, str+6, 36); //copy guid
  15652. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15653. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15654. {
  15655. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15656. }
  15657. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15658. OCPP_insert_transaction_msg(NO, str);
  15659. memset(str,0,ARRAY_SIZE(str));
  15660. }
  15661. }
  15662. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15663. fclose(fptr1);
  15664. remove(TempStopTransaction); // remove the original file
  15665. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15666. }
  15667. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15668. {
  15669. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15670. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15671. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15672. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15673. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15674. }
  15675. int GetWebSocketPingInterval(void)
  15676. {
  15677. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15678. }
  15679. int GetServerSign(void)
  15680. {
  15681. return server_sign;
  15682. }
  15683. uint8_t GetOcppSecurityProfile()
  15684. {
  15685. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15686. }
  15687. void GetOcppChargerBoxId(uint8_t *data)
  15688. {
  15689. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15690. }
  15691. void GetOcppSecurityPassword(uint8_t *data)
  15692. {
  15693. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15694. }
  15695. void SetOcppVersion(uint8_t *version)
  15696. {
  15697. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15698. DEBUG_INFO("ocpp version: %s\n", version);
  15699. if(strstr((char*)version, "ocpp1.6") != NULL)
  15700. {
  15701. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15702. }
  15703. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15704. {
  15705. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15706. system("pkill OcppBackend");
  15707. }
  15708. }
  15709. void SetServerSign(int value)
  15710. {
  15711. server_sign = value;
  15712. }
  15713. int GetBootNotificationInterval(void)
  15714. {
  15715. return BootNotificationInterval;
  15716. }
  15717. int GetInternetConn(void)
  15718. {
  15719. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15720. }
  15721. int GetBackendConnectionTimeout(void)
  15722. {
  15723. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15724. }
  15725. int isConnectorInitMode(int gun_index)
  15726. {
  15727. int tempIndex = 0;
  15728. int result = TRUE;
  15729. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15730. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15731. {
  15732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15733. {
  15734. tempIndex = ((gun_index==2) ? 1: 0);
  15735. }
  15736. else
  15737. {
  15738. tempIndex = gun_index;
  15739. }
  15740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15741. {
  15742. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15743. {
  15744. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15745. } //end of the same index
  15746. }//end of for CHAdeMO_QUANTITY
  15747. }
  15748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15749. {
  15750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15751. {
  15752. tempIndex = ((gun_index==2) ? 1: 0);
  15753. }
  15754. else
  15755. {
  15756. tempIndex = gun_index;
  15757. }
  15758. for (int index = 0; index < CCS_QUANTITY; index++)
  15759. {
  15760. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15761. {
  15762. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15763. } //end of the same index
  15764. } // end of for CCS_QUANTITY
  15765. }
  15766. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15767. {
  15768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15769. {
  15770. tempIndex = ((gun_index==2) ? 1: 0);
  15771. }
  15772. else
  15773. {
  15774. tempIndex = gun_index;
  15775. }
  15776. for (int index = 0; index < GB_QUANTITY; index++)
  15777. {
  15778. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15779. {
  15780. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15781. } //end of the same index
  15782. } // end of for GB_QUANTITY
  15783. }
  15784. else if(gunType[gun_index] == GUN_TYPE_DO)
  15785. {
  15786. tempIndex = gun_index;
  15787. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15788. {
  15789. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15790. {
  15791. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15792. } //end of the same index
  15793. }
  15794. }
  15795. else
  15796. {
  15797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15798. {
  15799. tempIndex = 2;
  15800. }
  15801. else
  15802. {
  15803. tempIndex = gun_index;
  15804. }
  15805. for (int index = 0; index < AC_QUANTITY; index++)
  15806. {
  15807. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15808. {
  15809. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15810. }//end of the same index
  15811. }//end of for AC_QUANTITY
  15812. }
  15813. return result;
  15814. }
  15815. void refreshProcDogTimer()
  15816. {
  15817. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15818. }
  15819. void InitialSystemValue(void)
  15820. {
  15821. int connectorIndex = 0;
  15822. //int valueASCII = 0;
  15823. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15824. gunTotalNumber=0;
  15825. SystemInitial = 0;
  15826. locallistVersion=0;
  15827. BootNotificationInterval = 0;
  15828. authorizeRetryTimes = 0;
  15829. GunStatusInterval = 10;
  15830. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15831. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15832. //Hear Beat
  15833. HeartBeatWithNOResponse = 0;
  15834. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15835. FirstHeartBeat = 0;
  15836. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15837. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15838. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15839. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15840. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15841. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15842. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15843. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15844. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15845. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15846. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15847. memset(gunType, 0, ARRAY_SIZE(gunType));
  15848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15849. {
  15850. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15851. {
  15852. // DO series
  15853. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15854. {
  15855. SystemInitial = SystemInitial + 1;
  15856. gunTotalNumber = gunTotalNumber + 1;
  15857. gunType[connectorIndex] = GUN_TYPE_DO;
  15858. connectorIndex = connectorIndex + 1;
  15859. }
  15860. }
  15861. else
  15862. {
  15863. // DM, DW, DS series
  15864. //check connector / socket type (index: 8, 9, 10)
  15865. for(int index=7; index <10 ; index++)
  15866. {
  15867. if(index != 8)
  15868. {
  15869. // DC Connector
  15870. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15871. {
  15872. SystemInitial = SystemInitial + 1;
  15873. gunTotalNumber = gunTotalNumber + 1;
  15874. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15875. connectorIndex = connectorIndex + 1;
  15876. }
  15877. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15878. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15879. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15880. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15881. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15882. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15883. {
  15884. SystemInitial = SystemInitial + 1;
  15885. gunTotalNumber = gunTotalNumber + 1;
  15886. gunType[connectorIndex] = GUN_TYPE_CCS;
  15887. connectorIndex = connectorIndex + 1;
  15888. }
  15889. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15890. {
  15891. SystemInitial = SystemInitial + 1;
  15892. gunTotalNumber = gunTotalNumber + 1;
  15893. gunType[connectorIndex] = GUN_TYPE_GBT;
  15894. connectorIndex = connectorIndex + 1;
  15895. }
  15896. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15897. {
  15898. SystemInitial = SystemInitial + 1;
  15899. gunTotalNumber = gunTotalNumber + 1;
  15900. gunType[connectorIndex] = GUN_TYPE_DO;
  15901. connectorIndex = connectorIndex + 1;
  15902. }
  15903. }
  15904. else
  15905. {
  15906. // AC Connector
  15907. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15908. {
  15909. SystemInitial = SystemInitial + 1;
  15910. gunTotalNumber = gunTotalNumber + 1;
  15911. gunType[connectorIndex] = GUN_TYPE_AC;
  15912. connectorIndex = connectorIndex + 1;
  15913. }
  15914. }
  15915. }
  15916. }
  15917. //DEBUG_INFO("DC ...\n");
  15918. }
  15919. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15920. {
  15921. //check connector / socket type (index: 8, 9, 10)
  15922. for(int index=7; index <10 ; index++)
  15923. {
  15924. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15925. {
  15926. SystemInitial = SystemInitial + 1;
  15927. gunTotalNumber = gunTotalNumber + 1;
  15928. gunType[connectorIndex] = GUN_TYPE_AC;
  15929. connectorIndex = connectorIndex + 1;
  15930. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15931. }
  15932. }
  15933. }
  15934. //Status && ConnectorPlugIn Setting
  15935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15936. {
  15937. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15938. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15939. }
  15940. for (int index = 0; index < CCS_QUANTITY; index++)
  15941. {
  15942. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15943. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15944. }
  15945. for (int index = 0; index < GB_QUANTITY; index++)
  15946. {
  15947. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15948. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15949. }
  15950. for (int index = 0; index < AC_QUANTITY; index++)
  15951. {
  15952. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15953. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15954. }
  15955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15956. {
  15957. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15958. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15959. }
  15960. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15961. {
  15962. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15963. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15964. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15965. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15966. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15967. }
  15968. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15969. clientTime.Heartbeat=time((time_t*)NULL);
  15970. sleep(1);
  15971. }
  15972. void LWS_Send(char *str)
  15973. {
  15974. //=====================================================
  15975. // Check InternetConn 0: disconnected, 1: connected
  15976. //====================================================
  15977. if(GetOcppConnStatus() == 0)
  15978. {
  15979. DEBUG_INFO("offline now !!!\n");
  15980. return;
  15981. }
  15982. // Only disable isWebsocketSendable operation initiated by charger
  15983. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15984. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15985. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15986. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15987. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15988. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15989. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15990. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15991. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15992. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15993. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15994. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15995. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15996. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15997. {
  15998. isWebsocketSendable = 0;
  15999. }
  16000. pthread_mutex_lock(&lock_send);
  16001. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16002. sprintf((char *)SendBuffer, "%s", str);
  16003. SendBufLen = strlen(str);
  16004. pthread_mutex_unlock(&lock_send);
  16005. lws_callback_on_writable(wsi_client);
  16006. //lws_service(context, 0);
  16007. //sleep(1);
  16008. }
  16009. void LWS_SendNow(char *str)
  16010. {
  16011. //=====================================================
  16012. // Check InternetConn 0: disconnected, 1: connected
  16013. //====================================================
  16014. if(GetOcppConnStatus() == 0)
  16015. {
  16016. DEBUG_INFO("offline now !!!\n");
  16017. return;
  16018. }
  16019. // Only disable isWebsocketSendable operation initiated by charger
  16020. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16021. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16022. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16023. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16024. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16025. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16026. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16027. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16028. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16029. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16030. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16031. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16032. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16033. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16034. {
  16035. isWebsocketSendable = 0;
  16036. }
  16037. pthread_mutex_lock(&lock_send);
  16038. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16039. sprintf((char *)SendBuffer, "%s", str);
  16040. SendBufLen = strlen(str);
  16041. pthread_mutex_unlock(&lock_send);
  16042. lws_callback_on_writable(wsi_client);
  16043. lws_service(context, 0);
  16044. //sleep(1);
  16045. }