MessageHandler.c 933 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. 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);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. 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);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. 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));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo);
  1186. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1187. }
  1188. //==========================================
  1189. // Check time passed since today
  1190. //==========================================
  1191. long long DiffTimebWithNow(struct timeb ST)
  1192. {
  1193. //return milli-second
  1194. struct timeb ET;
  1195. long long StartTime,StopTime;
  1196. ftime(&ET);
  1197. StartTime=(long long)ST.time;
  1198. StopTime=(long long)ET.time;
  1199. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1200. }
  1201. int getTimePassSinceToday(uint8_t gun_index)
  1202. {
  1203. int result = -1;
  1204. static time_t lastTime[4];
  1205. time_t t;
  1206. struct tm *tmStartToday;
  1207. struct timeb tbStartToday;
  1208. t=time(NULL);
  1209. if(difftime(t, lastTime[gun_index])>0)
  1210. {
  1211. tmStartToday=localtime(&t);
  1212. tmStartToday->tm_hour = 0;
  1213. tmStartToday->tm_min = 0;
  1214. tmStartToday->tm_sec = 0;
  1215. tbStartToday.time = mktime(tmStartToday);
  1216. tbStartToday.millitm = 0;
  1217. result = DiffTimebWithNow(tbStartToday)/1000;
  1218. lastTime[gun_index] = t;
  1219. }
  1220. return result;
  1221. }
  1222. void getNowDatetime(uint8_t *data)
  1223. {
  1224. time_t t = time(NULL);
  1225. struct tm tm = *localtime(&t);
  1226. 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);
  1227. }
  1228. int syncDateTimeRTC(uint8_t *data)
  1229. {
  1230. struct ParsingResult
  1231. {
  1232. int result;
  1233. int scanedElement;
  1234. int year;
  1235. int month;
  1236. int mday;
  1237. int hour;
  1238. int min;
  1239. int sec;
  1240. int tz_hour;
  1241. int tz_min;
  1242. float minSec;
  1243. }result;
  1244. struct tm tmOrg;
  1245. struct tm *tmTarget;
  1246. struct timeb tbTarget;
  1247. char buf[128];
  1248. memset(&result, 0x00, sizeof(struct ParsingResult));
  1249. result.result = PASS;
  1250. if(strstr((char*)data, ".") != NULL)
  1251. {
  1252. // Original data with mini second
  1253. if(strstr((char*)data, "Z") != NULL)
  1254. {
  1255. // Original data with Z
  1256. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1257. &result.year,
  1258. &result.month,
  1259. &result.mday,
  1260. &result.hour,
  1261. &result.min,
  1262. &result.sec,
  1263. &result.minSec);
  1264. }
  1265. else
  1266. {
  1267. // Original data without Z
  1268. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1269. &result.year,
  1270. &result.month,
  1271. &result.mday,
  1272. &result.hour,
  1273. &result.min,
  1274. &result.sec,
  1275. &result.minSec,
  1276. &result.tz_hour,
  1277. &result.tz_min);
  1278. }
  1279. }
  1280. else
  1281. {
  1282. // Original data without mini second
  1283. if(strstr((char*)data, "Z") != NULL)
  1284. {
  1285. // Original data with Z
  1286. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1287. &result.year,
  1288. &result.month,
  1289. &result.mday,
  1290. &result.hour,
  1291. &result.min,
  1292. &result.sec);
  1293. }
  1294. else
  1295. {
  1296. // Original data without Z
  1297. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1298. &result.year,
  1299. &result.month,
  1300. &result.mday,
  1301. &result.hour,
  1302. &result.min,
  1303. &result.sec,
  1304. &result.tz_hour,
  1305. &result.tz_min);
  1306. }
  1307. }
  1308. tmOrg.tm_year = result.year - 1900;
  1309. tmOrg.tm_mon = result.month - 1;
  1310. tmOrg.tm_mday = result.mday;
  1311. tmOrg.tm_hour = result.hour;
  1312. tmOrg.tm_min = result.min;
  1313. tmOrg.tm_sec = result.sec;
  1314. tmOrg.tm_gmtoff = 0;
  1315. tbTarget.time = mktime(&tmOrg);
  1316. tbTarget.timezone = 0;
  1317. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1318. tmTarget = gmtime(&tbTarget.time);
  1319. 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);
  1320. //DEBUG_INFO(" org date time: %s\n", data);
  1321. //DEBUG_INFO("parse date time: %s\n", buf);
  1322. system(buf);
  1323. system("/sbin/hwclock -w --systohc");
  1324. if(result.scanedElement < 6)
  1325. result.result = FAIL;
  1326. return result.result;
  1327. }
  1328. //==========================================
  1329. // GetCompositeSchedule logic related function
  1330. //==========================================
  1331. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1332. {
  1333. //return milli-second
  1334. unsigned int StartTime,StopTime;
  1335. StartTime=(unsigned int)ST.time;
  1336. StopTime=(unsigned int)ET.time;
  1337. return (StopTime-StartTime);
  1338. }
  1339. int DiffTimebWithNowSec(struct timeb ST)
  1340. {
  1341. //return milli-second
  1342. struct timeb ET;
  1343. unsigned int StartTime,StopTime;
  1344. ftime(&ET);
  1345. StartTime=(unsigned int)ST.time;
  1346. StopTime=(unsigned int)ET.time;
  1347. return (StopTime-StartTime);
  1348. }
  1349. int getStartStop(uint8_t *start, uint8_t *stop)
  1350. {
  1351. int result = -1;
  1352. struct tm tmStart;
  1353. struct timeb tbStart;
  1354. struct tm tmStop;
  1355. struct timeb tbStop;
  1356. 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) &&
  1357. (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))
  1358. {
  1359. //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);
  1360. //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);
  1361. tmStart.tm_year -= 1900;
  1362. tmStart.tm_mon -= 1;
  1363. tbStart.time = mktime(&tmStart);
  1364. tbStart.millitm = 0;
  1365. tmStop.tm_year -= 1900;
  1366. tmStop.tm_mon -= 1;
  1367. tbStop.time = mktime(&tmStop);
  1368. tbStop.millitm = 0;
  1369. result = DiffTimebSec(tbStart, tbStop);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. int isOvertNow(uint8_t *start)
  1379. {
  1380. int result = NO;
  1381. struct ParsingResult
  1382. {
  1383. int result;
  1384. int scanedElement;
  1385. int year;
  1386. int month;
  1387. int mday;
  1388. int hour;
  1389. int min;
  1390. int sec;
  1391. int tz_hour;
  1392. int tz_min;
  1393. float minSec;
  1394. }parsingResult;
  1395. struct tm tmStart;
  1396. struct timeb tbStart;
  1397. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1398. if(strstr((char*)start, ".") != NULL)
  1399. {
  1400. // Original data with mini second
  1401. if(strstr((char*)start, "Z") != NULL)
  1402. {
  1403. // Original data with Z
  1404. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1405. &parsingResult.year,
  1406. &parsingResult.month,
  1407. &parsingResult.mday,
  1408. &parsingResult.hour,
  1409. &parsingResult.min,
  1410. &parsingResult.sec,
  1411. &parsingResult.minSec);
  1412. }
  1413. else
  1414. {
  1415. // Original data without Z
  1416. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1417. &parsingResult.year,
  1418. &parsingResult.month,
  1419. &parsingResult.mday,
  1420. &parsingResult.hour,
  1421. &parsingResult.min,
  1422. &parsingResult.sec,
  1423. &parsingResult.minSec,
  1424. &parsingResult.tz_hour,
  1425. &parsingResult.tz_min);
  1426. }
  1427. }
  1428. else
  1429. {
  1430. // Original data without mini second
  1431. if(strstr((char*)start, "Z") != NULL)
  1432. {
  1433. // Original data with Z
  1434. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1435. &parsingResult.year,
  1436. &parsingResult.month,
  1437. &parsingResult.mday,
  1438. &parsingResult.hour,
  1439. &parsingResult.min,
  1440. &parsingResult.sec);
  1441. }
  1442. else
  1443. {
  1444. // Original data without Z
  1445. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1446. &parsingResult.year,
  1447. &parsingResult.month,
  1448. &parsingResult.mday,
  1449. &parsingResult.hour,
  1450. &parsingResult.min,
  1451. &parsingResult.sec,
  1452. &parsingResult.tz_hour,
  1453. &parsingResult.tz_min);
  1454. }
  1455. }
  1456. if(parsingResult.scanedElement >= 6)
  1457. {
  1458. tmStart.tm_year = parsingResult.year - 1900;
  1459. tmStart.tm_mon = parsingResult.month - 1;
  1460. tmStart.tm_mday = parsingResult.mday;
  1461. tmStart.tm_hour = parsingResult.hour;
  1462. tmStart.tm_min = parsingResult.min;
  1463. tmStart.tm_sec = parsingResult.sec;
  1464. tmStart.tm_gmtoff = 0;
  1465. tbStart.time = mktime(&tmStart);
  1466. tbStart.timezone = 0;
  1467. tbStart.millitm = 0;
  1468. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1469. if(DiffTimebWithNowSec(tbStart) <= 0)
  1470. result = NO;
  1471. else
  1472. result = YES;
  1473. }
  1474. else
  1475. {
  1476. DEBUG_WARN("Start date parsing error.\n");
  1477. }
  1478. return result;
  1479. }
  1480. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1481. {
  1482. int result = -1;
  1483. struct tm tmStart;
  1484. struct timeb tbStart;
  1485. struct tm tmStop;
  1486. struct timeb tbStop;
  1487. 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) &&
  1488. (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))
  1489. {
  1490. tmStart.tm_year -= 1900;
  1491. tmStart.tm_mon -= 1;
  1492. tbStart.time = mktime(&tmStart);
  1493. tbStart.millitm = 0;
  1494. tmStop.tm_year -= 1900;
  1495. tmStop.tm_mon -= 1;
  1496. tbStop.time = mktime(&tmStop);
  1497. tbStop.millitm = 0;
  1498. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1499. }
  1500. return result;
  1501. }
  1502. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1503. {
  1504. FILE *fp;
  1505. char profileFileName[128];
  1506. char *line = NULL;
  1507. size_t len = 0;
  1508. time_t CurrentTime;
  1509. struct tm *tmComposite;
  1510. struct StructChargingProfile maxProfile;
  1511. struct StructChargingProfile compositeProfile;
  1512. uint8_t limitMax=0;
  1513. int compositePeriodIdx = 0;
  1514. CurrentTime = time(NULL);
  1515. tmComposite=localtime(&CurrentTime);
  1516. 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);
  1517. if(isUnitA)
  1518. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1519. else
  1520. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1521. compositeProfile.ChargingSchedule.Duration = durationReq;
  1522. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1523. {
  1524. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1525. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1526. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1527. }
  1528. compositeProfile.ChargingProfileId = 0;
  1529. compositeProfile.StackLevel = 99 ;
  1530. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1531. maxProfile.ChargingProfileId = -1;
  1532. maxProfile.ChargingSchedule.Duration = -1;
  1533. system("rm -f /tmp/*.json");
  1534. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1535. // Search max profile
  1536. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1537. if((access(profileFileName, F_OK))!=-1)
  1538. {
  1539. fp = fopen(profileFileName, "r");
  1540. while(getline(&line, &len, fp) != -1)
  1541. {
  1542. json_object *obj = NULL;
  1543. obj = json_tokener_parse(line);
  1544. if(is_error(obj))
  1545. {
  1546. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1547. }
  1548. else
  1549. {
  1550. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1551. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1552. )
  1553. {
  1554. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1555. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1556. )
  1557. {
  1558. struct tm tmFrom, tmTo;
  1559. struct timeb tbFrom, tbTo;
  1560. 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) &&
  1561. (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))
  1562. {
  1563. tmFrom.tm_year -= 1900;
  1564. tmFrom.tm_mon -= 1;
  1565. tbFrom.time = mktime(&tmFrom);
  1566. tmTo.tm_year -= 1900;
  1567. tmTo.tm_mon -= 1;
  1568. tbTo.time = mktime(&tmTo);
  1569. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1570. {
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1576. }
  1577. maxProfile.ChargingProfileId = -1;
  1578. maxProfile.StackLevel = -1;
  1579. if(maxProfile.ChargingProfileId == -1)
  1580. DEBUG_INFO("MaxProfile found.\n");
  1581. else
  1582. DEBUG_INFO("MaxProfile updated.\n");
  1583. // Required item
  1584. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1585. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1586. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1587. if(isUnitA)
  1588. {
  1589. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1590. 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++)
  1591. {
  1592. 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"));
  1593. 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?
  1594. 3:
  1595. 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")));
  1596. 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")));
  1597. }
  1598. }
  1599. else
  1600. {
  1601. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1602. 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++)
  1603. {
  1604. 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"));
  1605. 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?
  1606. 3:
  1607. 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")));
  1608. 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));
  1609. }
  1610. }
  1611. // Optional item
  1612. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1613. {
  1614. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1615. }
  1616. else
  1617. {
  1618. sprintf((char*)maxProfile.ValidFrom, " ");
  1619. }
  1620. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1621. {
  1622. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1623. }
  1624. else
  1625. {
  1626. sprintf((char*)maxProfile.ValidTo, " ");
  1627. }
  1628. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1629. {
  1630. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1631. }
  1632. else
  1633. {
  1634. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1635. }
  1636. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1637. {
  1638. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1639. }
  1640. else
  1641. {
  1642. maxProfile.TransactionId = -1;
  1643. }
  1644. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1645. {
  1646. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1647. }
  1648. else
  1649. {
  1650. maxProfile.ChargingSchedule.Duration = 86400;
  1651. }
  1652. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1653. {
  1654. 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")));
  1655. }
  1656. else
  1657. {
  1658. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1659. }
  1660. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1661. {
  1662. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1663. }
  1664. else
  1665. {
  1666. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1667. }
  1668. }
  1669. }
  1670. }
  1671. else
  1672. {
  1673. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1674. {
  1675. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1676. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1678. }
  1679. maxProfile.ChargingProfileId = -1;
  1680. maxProfile.StackLevel = -1;
  1681. if(maxProfile.ChargingProfileId == -1)
  1682. DEBUG_INFO("MaxProfile found.\n");
  1683. else
  1684. DEBUG_INFO("MaxProfile updated.\n");
  1685. // Required item
  1686. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1687. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1688. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1689. if(isUnitA)
  1690. {
  1691. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1692. 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++)
  1693. {
  1694. 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"));
  1695. 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?
  1696. 3:
  1697. 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")));
  1698. 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")));
  1699. }
  1700. }
  1701. else
  1702. {
  1703. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1704. 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++)
  1705. {
  1706. 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"));
  1707. 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?
  1708. 3:
  1709. 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")));
  1710. 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));
  1711. }
  1712. }
  1713. // Optional item
  1714. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1715. {
  1716. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1717. }
  1718. else
  1719. {
  1720. sprintf((char*)maxProfile.ValidFrom, " ");
  1721. }
  1722. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1723. {
  1724. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1725. }
  1726. else
  1727. {
  1728. sprintf((char*)maxProfile.ValidTo, " ");
  1729. }
  1730. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1731. {
  1732. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1733. }
  1734. else
  1735. {
  1736. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1737. }
  1738. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1739. {
  1740. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1741. }
  1742. else
  1743. {
  1744. maxProfile.TransactionId = -1;
  1745. }
  1746. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1747. {
  1748. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1749. }
  1750. else
  1751. {
  1752. maxProfile.ChargingSchedule.Duration = 86400;
  1753. }
  1754. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1755. {
  1756. 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")));
  1757. }
  1758. else
  1759. {
  1760. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1761. }
  1762. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1763. {
  1764. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1765. }
  1766. else
  1767. {
  1768. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1769. }
  1770. }
  1771. }
  1772. }
  1773. json_object_put(obj);
  1774. }
  1775. fclose(fp);
  1776. /*
  1777. if(maxProfile.ChargingProfileId !=-1)
  1778. {
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. }
  1800. else
  1801. DEBUG_INFO("MaxProfile not found.\n");
  1802. DEBUG_INFO("------------------------------------\n");*/
  1803. }
  1804. if(maxProfile.ChargingProfileId != -1)
  1805. {
  1806. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1807. {
  1808. if(maxProfile.ChargingSchedule.Duration != -1)
  1809. {
  1810. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1811. 0:
  1812. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1813. }
  1814. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1815. {
  1816. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1817. {
  1818. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1819. 0:
  1820. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1821. if(idxPeriod > 0)
  1822. {
  1823. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1824. {
  1825. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1832. {
  1833. if(maxProfile.ChargingSchedule.Duration != -1)
  1834. {
  1835. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1836. }
  1837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1838. {
  1839. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1840. {
  1841. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1842. if(idxPeriod > 0)
  1843. {
  1844. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1845. {
  1846. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. else
  1853. {
  1854. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1855. {
  1856. if(maxProfile.ChargingSchedule.Duration != -1)
  1857. {
  1858. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1859. 0:
  1860. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1861. }
  1862. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1863. {
  1864. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1865. {
  1866. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1867. 0:
  1868. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1869. if(idxPeriod > 0)
  1870. {
  1871. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1872. {
  1873. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. else
  1880. {
  1881. if(maxProfile.ChargingSchedule.Duration != -1)
  1882. {
  1883. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1884. 0:
  1885. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1886. }
  1887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1888. {
  1889. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1890. {
  1891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1892. 0:
  1893. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1894. if(idxPeriod > 0)
  1895. {
  1896. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1897. {
  1898. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1899. }
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. /*
  1906. DEBUG_INFO("MaxProfile after align.\n");
  1907. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1908. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1909. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1910. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1911. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1912. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1913. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1914. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1915. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1916. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1917. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1918. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1919. {
  1920. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1921. {
  1922. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1923. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1924. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1925. }
  1926. }
  1927. DEBUG_INFO("------------------------------------\n");*/
  1928. }
  1929. // Find each profile period quantity
  1930. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1931. {
  1932. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1933. limitMax = idx+1;
  1934. }
  1935. if(maxProfile.ChargingProfileId != -1)
  1936. {
  1937. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1938. {
  1939. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1940. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1941. (maxProfile.ChargingSchedule.Duration > 0))
  1942. {
  1943. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1944. {
  1945. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1946. compositePeriodIdx++;
  1947. }
  1948. else
  1949. {
  1950. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1951. }
  1952. }
  1953. }
  1954. }
  1955. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1956. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1957. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1958. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1959. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1960. {
  1961. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1962. {
  1963. compositeProfile.ChargingProfileId = 1;
  1964. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1965. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1966. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1967. }
  1968. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1969. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1970. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1971. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1972. }
  1973. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1974. if(line)
  1975. free(line);
  1976. }
  1977. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1978. {
  1979. FILE *fp;
  1980. char profileFileName[128];
  1981. char *line = NULL;
  1982. size_t len = 0;
  1983. time_t CurrentTime;
  1984. struct tm *tmComposite;
  1985. struct StructChargingProfile maxProfile;
  1986. struct StructChargingProfile defaultTxProfile;
  1987. struct StructChargingProfile txProfile;
  1988. struct StructChargingProfile compositeProfile;
  1989. struct StructChargingSchedulePeriod tmpPeriod;
  1990. uint8_t limitMax=0;
  1991. uint8_t limitDef=0;
  1992. uint8_t limitTx=0;
  1993. int compositePeriodIdx = 0;
  1994. CurrentTime = time(NULL);
  1995. tmComposite=localtime(&CurrentTime);
  1996. 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);
  1997. if(isUnitA)
  1998. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1999. else
  2000. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2001. compositeProfile.ChargingSchedule.Duration = durationReq;
  2002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2003. {
  2004. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2005. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2006. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2007. }
  2008. compositeProfile.ChargingProfileId = 0;
  2009. compositeProfile.StackLevel = 99 ;
  2010. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2011. maxProfile.ChargingProfileId = -1;
  2012. defaultTxProfile.ChargingProfileId = -1;
  2013. txProfile.ChargingProfileId = -1;
  2014. maxProfile.ChargingSchedule.Duration = -1;
  2015. defaultTxProfile.ChargingSchedule.Duration = -1;
  2016. txProfile.ChargingSchedule.Duration = -1;
  2017. system("rm -f /tmp/*.json");
  2018. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2019. /*
  2020. * Search valid charging profile
  2021. */
  2022. //DEBUG_INFO("====================================\n");
  2023. // Search tx profile
  2024. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2025. if((access(profileFileName, F_OK))!=-1)
  2026. {
  2027. fp = fopen(profileFileName, "r");
  2028. while(getline(&line, &len, fp) != -1)
  2029. {
  2030. json_object *obj = NULL;
  2031. obj = json_tokener_parse(line);
  2032. if(is_error(obj))
  2033. {
  2034. DEBUG_ERROR("Parse txProfile from file error.\n");
  2035. }
  2036. else
  2037. {
  2038. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2039. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2040. )
  2041. {
  2042. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2043. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2044. )
  2045. {
  2046. struct tm tmFrom, tmTo;
  2047. struct timeb tbFrom, tbTo;
  2048. 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) &&
  2049. (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))
  2050. {
  2051. tmFrom.tm_year -= 1900;
  2052. tmFrom.tm_mon -= 1;
  2053. tbFrom.time = mktime(&tmFrom);
  2054. tmTo.tm_year -= 1900;
  2055. tmTo.tm_mon -= 1;
  2056. tbTo.time = mktime(&tmTo);
  2057. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2058. {
  2059. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2060. {
  2061. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2063. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2064. }
  2065. txProfile.ChargingProfileId = -1;
  2066. txProfile.StackLevel = -1;
  2067. if(txProfile.ChargingProfileId == -1)
  2068. DEBUG_INFO("TxProfile found.\n");
  2069. else
  2070. DEBUG_INFO("TxProfile updated.\n");
  2071. // Required item
  2072. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2073. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2074. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2075. if(isUnitA)
  2076. {
  2077. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2078. 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++)
  2079. {
  2080. 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"));
  2081. 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?
  2082. 3:
  2083. 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")));
  2084. 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")));
  2085. }
  2086. }
  2087. else
  2088. {
  2089. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2090. 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++)
  2091. {
  2092. 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"));
  2093. 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?
  2094. 3:
  2095. 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")));
  2096. 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));
  2097. }
  2098. }
  2099. // Optional item
  2100. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2101. {
  2102. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2103. }
  2104. else
  2105. {
  2106. sprintf((char*)txProfile.ValidFrom, " ");
  2107. }
  2108. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2109. {
  2110. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2111. }
  2112. else
  2113. {
  2114. sprintf((char*)txProfile.ValidTo, " ");
  2115. }
  2116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2117. {
  2118. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2119. }
  2120. else
  2121. {
  2122. sprintf((char*)txProfile.RecurrencyKind, " ");
  2123. }
  2124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2125. {
  2126. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2127. }
  2128. else
  2129. {
  2130. txProfile.TransactionId = -1;
  2131. }
  2132. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2133. {
  2134. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2135. }
  2136. else
  2137. {
  2138. txProfile.ChargingSchedule.Duration = 86400;
  2139. }
  2140. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2141. {
  2142. 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")));
  2143. }
  2144. else
  2145. {
  2146. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2147. }
  2148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2149. {
  2150. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2151. }
  2152. else
  2153. {
  2154. txProfile.ChargingSchedule.MinChargingRate = -1;
  2155. }
  2156. }
  2157. }
  2158. }
  2159. else
  2160. {
  2161. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2162. {
  2163. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2164. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2165. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2166. }
  2167. txProfile.ChargingProfileId = -1;
  2168. txProfile.StackLevel = -1;
  2169. if(txProfile.ChargingProfileId == -1)
  2170. DEBUG_INFO("TxProfile found.\n");
  2171. else
  2172. DEBUG_INFO("TxProfile updated.\n");
  2173. // Required item
  2174. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2175. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2176. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2177. if(isUnitA)
  2178. {
  2179. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2180. 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++)
  2181. {
  2182. 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"));
  2183. 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?
  2184. 3:
  2185. 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")));
  2186. 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")));
  2187. }
  2188. }
  2189. else
  2190. {
  2191. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2192. 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++)
  2193. {
  2194. 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"));
  2195. 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?
  2196. 3:
  2197. 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")));
  2198. 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));
  2199. }
  2200. }
  2201. // Optional item
  2202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2203. {
  2204. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2205. }
  2206. else
  2207. {
  2208. sprintf((char*)txProfile.ValidFrom, " ");
  2209. }
  2210. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2211. {
  2212. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2213. }
  2214. else
  2215. {
  2216. sprintf((char*)txProfile.ValidTo, " ");
  2217. }
  2218. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2219. {
  2220. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2221. }
  2222. else
  2223. {
  2224. sprintf((char*)txProfile.RecurrencyKind, " ");
  2225. }
  2226. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2227. {
  2228. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2229. }
  2230. else
  2231. {
  2232. txProfile.TransactionId = -1;
  2233. }
  2234. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2235. {
  2236. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2237. }
  2238. else
  2239. {
  2240. txProfile.ChargingSchedule.Duration = 86400;
  2241. }
  2242. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2243. {
  2244. 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")));
  2245. }
  2246. else
  2247. {
  2248. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2249. }
  2250. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2251. {
  2252. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2253. }
  2254. else
  2255. {
  2256. txProfile.ChargingSchedule.MinChargingRate = -1;
  2257. }
  2258. }
  2259. }
  2260. }
  2261. json_object_put(obj);
  2262. }
  2263. fclose(fp);
  2264. /*
  2265. if(txProfile.ChargingProfileId != -1)
  2266. {
  2267. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2268. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2269. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2270. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2271. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2272. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2273. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2274. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2275. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2276. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2277. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2278. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2279. {
  2280. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2281. {
  2282. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2283. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2284. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2285. }
  2286. }
  2287. }
  2288. else
  2289. DEBUG_INFO("TxProfile not found.\n");*/
  2290. }
  2291. // Search default tx profile
  2292. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2293. if((access(profileFileName, F_OK))==-1)
  2294. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2295. if((access(profileFileName, F_OK))!=-1)
  2296. {
  2297. fp = fopen(profileFileName, "r");
  2298. while(getline(&line, &len, fp) != -1)
  2299. {
  2300. json_object *obj = NULL;
  2301. obj = json_tokener_parse(line);
  2302. if(is_error(obj))
  2303. {
  2304. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2305. }
  2306. else
  2307. {
  2308. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2309. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2310. )
  2311. {
  2312. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2313. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2314. )
  2315. {
  2316. struct tm tmFrom, tmTo;
  2317. struct timeb tbFrom, tbTo;
  2318. 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) &&
  2319. (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))
  2320. {
  2321. tmFrom.tm_year -= 1900;
  2322. tmFrom.tm_mon -= 1;
  2323. tbFrom.time = mktime(&tmFrom);
  2324. tmTo.tm_year -= 1900;
  2325. tmTo.tm_mon -= 1;
  2326. tbTo.time = mktime(&tmTo);
  2327. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2328. {
  2329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2330. {
  2331. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2333. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2334. }
  2335. defaultTxProfile.ChargingProfileId = -1;
  2336. defaultTxProfile.StackLevel = -1;
  2337. if(defaultTxProfile.ChargingProfileId == -1)
  2338. DEBUG_INFO("TxDefaultProfile found.\n");
  2339. else
  2340. DEBUG_INFO("TxDefaultProfile updated.\n");
  2341. // Required item
  2342. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2343. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2344. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2345. if(isUnitA)
  2346. {
  2347. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2348. 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++)
  2349. {
  2350. 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"));
  2351. 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?
  2352. 3:
  2353. 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")));
  2354. 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")));
  2355. }
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2360. 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++)
  2361. {
  2362. 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"));
  2363. 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?
  2364. 3:
  2365. 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")));
  2366. 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));
  2367. }
  2368. }
  2369. // Optional item
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2371. {
  2372. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2373. }
  2374. else
  2375. {
  2376. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2377. }
  2378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2379. {
  2380. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2381. }
  2382. else
  2383. {
  2384. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2385. }
  2386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2387. {
  2388. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2393. }
  2394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2395. {
  2396. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2397. }
  2398. else
  2399. {
  2400. defaultTxProfile.TransactionId = -1;
  2401. }
  2402. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2403. {
  2404. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2405. }
  2406. else
  2407. {
  2408. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2409. }
  2410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2411. {
  2412. 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")));
  2413. }
  2414. else
  2415. {
  2416. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2417. }
  2418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2419. {
  2420. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2421. }
  2422. else
  2423. {
  2424. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. else
  2430. {
  2431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2432. {
  2433. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2435. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2436. }
  2437. defaultTxProfile.ChargingProfileId = -1;
  2438. defaultTxProfile.StackLevel = -1;
  2439. if(defaultTxProfile.ChargingProfileId == -1)
  2440. DEBUG_INFO("TxDefaultProfile found.\n");
  2441. else
  2442. DEBUG_INFO("TxDefaultProfile updated.\n");
  2443. // Required item
  2444. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2445. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2446. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2447. if(isUnitA)
  2448. {
  2449. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2450. 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++)
  2451. {
  2452. 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"));
  2453. 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?
  2454. 3:
  2455. 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")));
  2456. 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")));
  2457. }
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2462. 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++)
  2463. {
  2464. 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"));
  2465. 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?
  2466. 3:
  2467. 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")));
  2468. 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));
  2469. }
  2470. }
  2471. // Optional item
  2472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2473. {
  2474. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2475. }
  2476. else
  2477. {
  2478. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2479. }
  2480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2481. {
  2482. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2487. }
  2488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2489. {
  2490. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2495. }
  2496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2497. {
  2498. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2499. }
  2500. else
  2501. {
  2502. defaultTxProfile.TransactionId = -1;
  2503. }
  2504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2505. {
  2506. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2507. }
  2508. else
  2509. {
  2510. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2511. }
  2512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2513. {
  2514. 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")));
  2515. }
  2516. else
  2517. {
  2518. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2519. }
  2520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2521. {
  2522. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2523. }
  2524. else
  2525. {
  2526. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. json_object_put(obj);
  2532. }
  2533. fclose(fp);
  2534. /*
  2535. if(defaultTxProfile.ChargingProfileId != -1)
  2536. {
  2537. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2538. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2539. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2540. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2541. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2542. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2543. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2544. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2545. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2546. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2547. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2551. {
  2552. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2554. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2555. }
  2556. }
  2557. }
  2558. else
  2559. DEBUG_INFO("TxDefaultProfile not found.\n");
  2560. DEBUG_INFO("------------------------------------\n");*/
  2561. }
  2562. // Search max profile
  2563. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2564. if((access(profileFileName, F_OK))!=-1)
  2565. {
  2566. fp = fopen(profileFileName, "r");
  2567. while(getline(&line, &len, fp) != -1)
  2568. {
  2569. json_object *obj = NULL;
  2570. obj = json_tokener_parse(line);
  2571. if(is_error(obj))
  2572. {
  2573. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2574. }
  2575. else
  2576. {
  2577. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2578. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2579. )
  2580. {
  2581. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2582. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2583. )
  2584. {
  2585. struct tm tmFrom, tmTo;
  2586. struct timeb tbFrom, tbTo;
  2587. 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) &&
  2588. (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))
  2589. {
  2590. tmFrom.tm_year -= 1900;
  2591. tmFrom.tm_mon -= 1;
  2592. tbFrom.time = mktime(&tmFrom);
  2593. tmTo.tm_year -= 1900;
  2594. tmTo.tm_mon -= 1;
  2595. tbTo.time = mktime(&tmTo);
  2596. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2597. {
  2598. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2599. {
  2600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2602. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2603. }
  2604. maxProfile.ChargingProfileId = -1;
  2605. maxProfile.StackLevel = -1;
  2606. if(maxProfile.ChargingProfileId == -1)
  2607. DEBUG_INFO("MaxProfile found.\n");
  2608. else
  2609. DEBUG_INFO("MaxProfile updated.\n");
  2610. // Required item
  2611. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2612. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2613. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2614. if(isUnitA)
  2615. {
  2616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2617. 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++)
  2618. {
  2619. 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"));
  2620. 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?
  2621. 3:
  2622. 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")));
  2623. 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")));
  2624. }
  2625. }
  2626. else
  2627. {
  2628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2629. 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++)
  2630. {
  2631. 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"));
  2632. 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?
  2633. 3:
  2634. 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")));
  2635. 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));
  2636. }
  2637. }
  2638. // Optional item
  2639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2640. {
  2641. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2642. }
  2643. else
  2644. {
  2645. sprintf((char*)maxProfile.ValidFrom, " ");
  2646. }
  2647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2648. {
  2649. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2650. }
  2651. else
  2652. {
  2653. sprintf((char*)maxProfile.ValidTo, " ");
  2654. }
  2655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2656. {
  2657. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2658. }
  2659. else
  2660. {
  2661. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2662. }
  2663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2664. {
  2665. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2666. }
  2667. else
  2668. {
  2669. maxProfile.TransactionId = -1;
  2670. }
  2671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2672. {
  2673. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2674. }
  2675. else
  2676. {
  2677. maxProfile.ChargingSchedule.Duration = 86400;
  2678. }
  2679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2680. {
  2681. 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")));
  2682. }
  2683. else
  2684. {
  2685. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2686. }
  2687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2688. {
  2689. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2690. }
  2691. else
  2692. {
  2693. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. else
  2699. {
  2700. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2701. {
  2702. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2703. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2704. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2705. }
  2706. maxProfile.ChargingProfileId = -1;
  2707. maxProfile.StackLevel = -1;
  2708. if(maxProfile.ChargingProfileId == -1)
  2709. DEBUG_INFO("MaxProfile found.\n");
  2710. else
  2711. DEBUG_INFO("MaxProfile updated.\n");
  2712. // Required item
  2713. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2714. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2715. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2716. if(isUnitA)
  2717. {
  2718. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2719. 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++)
  2720. {
  2721. 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"));
  2722. 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?
  2723. 3:
  2724. 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")));
  2725. 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")));
  2726. }
  2727. }
  2728. else
  2729. {
  2730. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2731. 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++)
  2732. {
  2733. 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"));
  2734. 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?
  2735. 3:
  2736. 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")));
  2737. 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));
  2738. }
  2739. }
  2740. // Optional item
  2741. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2742. {
  2743. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2744. }
  2745. else
  2746. {
  2747. sprintf((char*)maxProfile.ValidFrom, " ");
  2748. }
  2749. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2750. {
  2751. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2752. }
  2753. else
  2754. {
  2755. sprintf((char*)maxProfile.ValidTo, " ");
  2756. }
  2757. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2758. {
  2759. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2760. }
  2761. else
  2762. {
  2763. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2764. }
  2765. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2766. {
  2767. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2768. }
  2769. else
  2770. {
  2771. maxProfile.TransactionId = -1;
  2772. }
  2773. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2774. {
  2775. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2776. }
  2777. else
  2778. {
  2779. maxProfile.ChargingSchedule.Duration = 86400;
  2780. }
  2781. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2782. {
  2783. 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")));
  2784. }
  2785. else
  2786. {
  2787. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2788. }
  2789. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2790. {
  2791. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2792. }
  2793. else
  2794. {
  2795. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2796. }
  2797. }
  2798. }
  2799. }
  2800. json_object_put(obj);
  2801. }
  2802. fclose(fp);
  2803. /*
  2804. if(maxProfile.ChargingProfileId !=-1)
  2805. {
  2806. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2807. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2808. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2809. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2810. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2811. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2812. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2813. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2814. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2815. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2816. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2817. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2818. {
  2819. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2820. {
  2821. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2822. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2823. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2824. }
  2825. }
  2826. }
  2827. else
  2828. DEBUG_INFO("MaxProfile not found.\n");
  2829. DEBUG_INFO("------------------------------------\n");*/
  2830. }
  2831. /*
  2832. * Align found profile start schedule & periods
  2833. */
  2834. //DEBUG_INFO("====================================\n");
  2835. /*
  2836. // For local test usage, force modify found profile start schedule info
  2837. 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);
  2838. 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);
  2839. 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);
  2840. */
  2841. if(txProfile.ChargingProfileId != -1)
  2842. {
  2843. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2844. {
  2845. if(txProfile.ChargingSchedule.Duration != -1)
  2846. {
  2847. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2848. 0:
  2849. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2850. }
  2851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2852. {
  2853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2854. {
  2855. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2856. 0:
  2857. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2858. if(idxPeriod > 0)
  2859. {
  2860. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2861. {
  2862. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2863. }
  2864. }
  2865. }
  2866. }
  2867. }
  2868. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2869. {
  2870. if(txProfile.ChargingSchedule.Duration != -1)
  2871. {
  2872. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2873. 0:
  2874. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2875. }
  2876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2877. {
  2878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2879. {
  2880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2881. 0:
  2882. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2883. if(idxPeriod > 0)
  2884. {
  2885. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2886. {
  2887. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2888. }
  2889. }
  2890. }
  2891. }
  2892. }
  2893. else
  2894. {
  2895. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2896. {
  2897. if(txProfile.ChargingSchedule.Duration != -1)
  2898. {
  2899. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2900. 0:
  2901. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2902. }
  2903. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2904. {
  2905. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2906. {
  2907. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2908. 0:
  2909. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2910. if(idxPeriod > 0)
  2911. {
  2912. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2913. {
  2914. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2915. }
  2916. }
  2917. }
  2918. }
  2919. }
  2920. else
  2921. {
  2922. if(txProfile.ChargingSchedule.Duration != -1)
  2923. {
  2924. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2925. 0:
  2926. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2927. }
  2928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2929. {
  2930. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2931. {
  2932. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2933. 0:
  2934. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2935. if(idxPeriod > 0)
  2936. {
  2937. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2938. {
  2939. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. /*
  2947. DEBUG_INFO("txProfile after align.\n");
  2948. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2949. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2950. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2951. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2952. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2953. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2954. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2955. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2956. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2957. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2958. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2959. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2960. {
  2961. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2962. {
  2963. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2964. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2965. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2966. }
  2967. }*/
  2968. }
  2969. if(defaultTxProfile.ChargingProfileId != -1)
  2970. {
  2971. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2972. {
  2973. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2974. {
  2975. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2976. 0:
  2977. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2978. }
  2979. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2980. {
  2981. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2982. {
  2983. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2984. 0:
  2985. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2987. {
  2988. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2989. }
  2990. if(idxPeriod > 0)
  2991. {
  2992. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2993. {
  2994. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3001. {
  3002. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3003. {
  3004. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3005. 0:
  3006. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3007. }
  3008. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3009. {
  3010. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3011. {
  3012. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3013. 0:
  3014. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3016. {
  3017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3018. }
  3019. if(idxPeriod > 0)
  3020. {
  3021. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3022. {
  3023. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3024. }
  3025. }
  3026. }
  3027. }
  3028. }
  3029. else
  3030. {
  3031. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3032. {
  3033. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3034. {
  3035. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3036. 0:
  3037. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3038. }
  3039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3040. {
  3041. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3042. {
  3043. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3044. 0:
  3045. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3046. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3047. {
  3048. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3049. }
  3050. if(idxPeriod > 0)
  3051. {
  3052. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3053. {
  3054. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. else
  3061. {
  3062. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3063. {
  3064. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3065. 0:
  3066. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3067. }
  3068. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3069. {
  3070. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3071. {
  3072. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3073. 0:
  3074. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3075. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3076. {
  3077. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3078. }
  3079. if(idxPeriod > 0)
  3080. {
  3081. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3082. {
  3083. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3084. }
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. /*
  3091. DEBUG_INFO("defaultTxProfile after align.\n");
  3092. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3093. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3094. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3095. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3096. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3097. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3098. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3099. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3100. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3101. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3102. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3103. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3104. {
  3105. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3106. {
  3107. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3108. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3109. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3110. }
  3111. }
  3112. DEBUG_INFO("------------------------------------\n");*/
  3113. }
  3114. if(maxProfile.ChargingProfileId != -1)
  3115. {
  3116. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3117. {
  3118. if(maxProfile.ChargingSchedule.Duration != -1)
  3119. {
  3120. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3121. 0:
  3122. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3123. }
  3124. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3125. {
  3126. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3127. {
  3128. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3129. 0:
  3130. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3131. if(idxPeriod > 0)
  3132. {
  3133. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3134. {
  3135. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3136. }
  3137. }
  3138. }
  3139. }
  3140. }
  3141. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3142. {
  3143. if(maxProfile.ChargingSchedule.Duration != -1)
  3144. {
  3145. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3146. 0:
  3147. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3148. }
  3149. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3150. {
  3151. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3152. {
  3153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3154. 0:
  3155. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3156. if(idxPeriod > 0)
  3157. {
  3158. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3159. {
  3160. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3161. }
  3162. }
  3163. }
  3164. }
  3165. }
  3166. else
  3167. {
  3168. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3169. {
  3170. if(maxProfile.ChargingSchedule.Duration != -1)
  3171. {
  3172. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3173. 0:
  3174. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3175. }
  3176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3177. {
  3178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3179. {
  3180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3181. 0:
  3182. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3183. if(idxPeriod > 0)
  3184. {
  3185. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3186. {
  3187. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3188. }
  3189. }
  3190. }
  3191. }
  3192. }
  3193. else
  3194. {
  3195. if(maxProfile.ChargingSchedule.Duration != -1)
  3196. {
  3197. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3198. 0:
  3199. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3200. }
  3201. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3202. {
  3203. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3204. {
  3205. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3206. 0:
  3207. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3208. if(idxPeriod > 0)
  3209. {
  3210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3211. {
  3212. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3213. }
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. /*
  3220. DEBUG_INFO("MaxProfile after align.\n");
  3221. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3222. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3223. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3224. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3225. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3226. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3227. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3228. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3229. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3230. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3231. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3232. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3233. {
  3234. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3235. {
  3236. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3237. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3238. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3239. }
  3240. }
  3241. DEBUG_INFO("------------------------------------\n");*/
  3242. }
  3243. /*
  3244. * Merge to conposite schedule
  3245. */
  3246. //DEBUG_INFO("====================================\n");
  3247. // Find each profile period quantity
  3248. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3249. {
  3250. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3251. limitMax = idx+1;
  3252. }
  3253. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3254. {
  3255. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3256. limitDef = idx+1;
  3257. }
  3258. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3259. {
  3260. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3261. limitTx = idx+1;
  3262. }
  3263. // TxProfile found, composite schedule based on it
  3264. if(txProfile.ChargingProfileId != -1)
  3265. {
  3266. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3267. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3268. {
  3269. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3270. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3271. (txProfile.ChargingSchedule.Duration > 0))
  3272. {
  3273. if(maxProfile.ChargingProfileId != -1)
  3274. {
  3275. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3276. {
  3277. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3278. {
  3279. if((maxProfile.ChargingSchedule.Duration > 0))
  3280. {
  3281. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3282. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3283. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3284. }
  3285. else
  3286. {
  3287. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3288. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3289. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3290. }
  3291. }
  3292. if(idxMaxPeriod == (limitMax-1))
  3293. {
  3294. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3295. {
  3296. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3297. {
  3298. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3299. compositePeriodIdx++;
  3300. }
  3301. else
  3302. {
  3303. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3312. {
  3313. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3314. compositePeriodIdx++;
  3315. }
  3316. else
  3317. {
  3318. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3319. }
  3320. }
  3321. }
  3322. if(idxTxPeriod == (limitTx-1))
  3323. {
  3324. if(defaultTxProfile.ChargingProfileId != -1)
  3325. {
  3326. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3327. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3328. {
  3329. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3330. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3331. (defaultTxProfile.ChargingSchedule.Duration>0))
  3332. {
  3333. if(maxProfile.ChargingProfileId != -1)
  3334. {
  3335. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3336. {
  3337. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3338. {
  3339. if((maxProfile.ChargingSchedule.Duration > 0))
  3340. {
  3341. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3342. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3343. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3344. }
  3345. else
  3346. {
  3347. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3348. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3349. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3350. }
  3351. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3352. {
  3353. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3354. {
  3355. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3356. compositePeriodIdx++;
  3357. }
  3358. else
  3359. {
  3360. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3361. }
  3362. }
  3363. // Delete duplicate period
  3364. if(compositePeriodIdx > 1)
  3365. {
  3366. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3367. {
  3368. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3369. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3370. compositePeriodIdx -= 1;
  3371. }
  3372. }
  3373. }
  3374. else
  3375. {
  3376. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3377. {
  3378. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3379. compositePeriodIdx++;
  3380. }
  3381. else
  3382. {
  3383. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3384. }
  3385. break;
  3386. }
  3387. }
  3388. }
  3389. else
  3390. {
  3391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3392. {
  3393. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3394. compositePeriodIdx++;
  3395. }
  3396. else
  3397. {
  3398. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3399. }
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3408. else if(defaultTxProfile.ChargingProfileId != -1)
  3409. {
  3410. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3411. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3412. {
  3413. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3414. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3415. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3416. {
  3417. if(maxProfile.ChargingProfileId != -1)
  3418. {
  3419. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3420. {
  3421. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3422. {
  3423. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3424. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3425. if((maxProfile.ChargingSchedule.Duration > 0))
  3426. {
  3427. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3428. }
  3429. else
  3430. {
  3431. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3432. }
  3433. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3434. {
  3435. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3436. {
  3437. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3438. compositePeriodIdx++;
  3439. }
  3440. else
  3441. {
  3442. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3443. }
  3444. }
  3445. // Delete duplicate period
  3446. if(compositePeriodIdx > 1)
  3447. {
  3448. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3449. {
  3450. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3451. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3452. compositePeriodIdx -= 1;
  3453. }
  3454. }
  3455. }
  3456. else
  3457. {
  3458. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3459. {
  3460. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3461. compositePeriodIdx++;
  3462. }
  3463. else
  3464. {
  3465. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3466. }
  3467. break;
  3468. }
  3469. }
  3470. }
  3471. else
  3472. {
  3473. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3474. {
  3475. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3476. compositePeriodIdx++;
  3477. }
  3478. else
  3479. {
  3480. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3481. }
  3482. }
  3483. }
  3484. }
  3485. }
  3486. // Fill other period by MaxProfile
  3487. if(maxProfile.ChargingProfileId != -1)
  3488. {
  3489. if(compositePeriodIdx==0)
  3490. {
  3491. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3492. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3493. {
  3494. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3495. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3496. (maxProfile.ChargingSchedule.Duration > 0))
  3497. {
  3498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3499. {
  3500. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3501. compositePeriodIdx++;
  3502. }
  3503. else
  3504. {
  3505. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3506. }
  3507. }
  3508. }
  3509. }
  3510. else
  3511. {
  3512. int lastCompositePeriodIdx = compositePeriodIdx;
  3513. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3514. {
  3515. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3516. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3517. (maxProfile.ChargingSchedule.Duration > 0))
  3518. {
  3519. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3520. {
  3521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3522. {
  3523. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3524. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3525. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3526. }
  3527. else
  3528. {
  3529. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3530. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3531. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3532. }
  3533. }
  3534. if(tmpPeriod.Limit != -1)
  3535. {
  3536. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3537. {
  3538. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3539. {
  3540. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3541. compositePeriodIdx++;
  3542. }
  3543. else
  3544. {
  3545. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3546. }
  3547. }
  3548. // Delete duplicate period
  3549. if(compositePeriodIdx > 1)
  3550. {
  3551. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3552. {
  3553. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3554. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3555. compositePeriodIdx -= 1;
  3556. }
  3557. }
  3558. }
  3559. }
  3560. }
  3561. }
  3562. }
  3563. compositeProfile.ChargingSchedule.Duration = durationReq;
  3564. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3565. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3566. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3567. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3569. {
  3570. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3571. {
  3572. compositeProfile.ChargingProfileId = 1;
  3573. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3574. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3575. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3576. }
  3577. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3578. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3579. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3580. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3581. }
  3582. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3583. if(line)
  3584. free(line);
  3585. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3586. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3587. }
  3588. //==========================================
  3589. // Init all share memory
  3590. //==========================================
  3591. int InitShareMemory()
  3592. {
  3593. int result = PASS;
  3594. int MeterSMId;
  3595. //creat ShmSysConfigAndInfo
  3596. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3597. {
  3598. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3599. result = FAIL;
  3600. }
  3601. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3602. {
  3603. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3604. result = FAIL;
  3605. }
  3606. else
  3607. {}
  3608. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3609. {
  3610. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3611. result = FAIL;
  3612. }
  3613. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3614. {
  3615. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3616. result = FAIL;
  3617. }
  3618. else
  3619. {}
  3620. //creat ShmPsuData
  3621. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3622. {
  3623. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3624. result = FAIL;
  3625. }
  3626. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3627. {
  3628. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3629. result = FAIL;
  3630. }
  3631. else
  3632. {}
  3633. //creat ShmOCPP16Data
  3634. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3635. {
  3636. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3637. result = FAIL;
  3638. }
  3639. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3640. {
  3641. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3642. result = FAIL;
  3643. }
  3644. else
  3645. {}
  3646. /****************************** For Initial Settings************************************************/
  3647. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3648. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3649. // allocate Configuration memory address
  3650. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3651. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3652. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3653. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3654. //offline MeterValue Interval
  3655. TempMeterValueInterval = 0;
  3656. return result;
  3657. }
  3658. int ProcessShareMemory()
  3659. {
  3660. int result = PASS;
  3661. if(InitShareMemory() == FAIL)
  3662. {
  3663. DEBUG_ERROR("InitShareMemory NG\n");
  3664. if(ShmStatusCodeData!=NULL)
  3665. {
  3666. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3667. }
  3668. result = FAIL;
  3669. }
  3670. // Model name parsing
  3671. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3672. {
  3673. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3674. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3675. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3676. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3677. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3678. ) // 'D' means DC
  3679. {
  3680. // DO series
  3681. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3682. {
  3683. SystemInitial += 1;
  3684. gunTotalNumber += 1;
  3685. gunType[gun_index] = GUN_TYPE_DO;
  3686. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3687. {
  3688. case Gun_Type_Chademo:
  3689. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3690. break;
  3691. case Gun_Type_CCS_2:
  3692. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3693. break;
  3694. case Gun_Type_GB:
  3695. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3696. break;
  3697. case Gun_Type_AC:
  3698. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3699. break;
  3700. default:
  3701. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3702. break;
  3703. }
  3704. }
  3705. }
  3706. else
  3707. {
  3708. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3709. {
  3710. SystemInitial += 1;
  3711. gunTotalNumber += 1;
  3712. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3713. {
  3714. case Gun_Type_Chademo:
  3715. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3716. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3717. break;
  3718. case Gun_Type_CCS_2:
  3719. gunType[gun_index] = GUN_TYPE_CCS;
  3720. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3721. break;
  3722. case Gun_Type_GB:
  3723. gunType[gun_index] = GUN_TYPE_GBT;
  3724. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3725. break;
  3726. case Gun_Type_AC:
  3727. gunType[gun_index] = GUN_TYPE_AC;
  3728. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3729. break;
  3730. default:
  3731. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3732. break;
  3733. }
  3734. }
  3735. }
  3736. }
  3737. else
  3738. {
  3739. DEBUG_ERROR("Model name parsing fail.\n");
  3740. result = FAIL;
  3741. }
  3742. if(result != PASS)sleep(5);
  3743. return result;
  3744. }
  3745. void checkRemoteStart(uint8_t connectorIdInt)
  3746. {
  3747. uint8_t tempIndex;
  3748. int result = PASS;
  3749. char cmdBuf[512];
  3750. //check Transaction active
  3751. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3754. {
  3755. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = connectorIdInt -1;
  3760. }
  3761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3764. {
  3765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3766. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3767. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3768. {
  3769. //Reserved
  3770. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3771. }
  3772. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3773. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3774. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3775. {
  3776. //Reserved
  3777. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3778. result = FAIL;
  3779. goto end;
  3780. }
  3781. else
  3782. {
  3783. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3784. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3785. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3786. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3787. {
  3788. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3789. result = FAIL;
  3790. goto end;
  3791. }
  3792. }//END FOR ELSE
  3793. }
  3794. }// END FOR CHAdeMO_QUANTITY
  3795. }
  3796. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3797. {
  3798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3799. {
  3800. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3801. }
  3802. else
  3803. {
  3804. tempIndex = connectorIdInt -1;
  3805. }
  3806. for (int index = 0; index < CCS_QUANTITY; index++)
  3807. {
  3808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3809. {
  3810. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3811. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3812. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3813. {
  3814. //Reserved
  3815. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3816. }
  3817. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3818. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3819. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3820. {
  3821. //Reserved
  3822. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3823. result = FAIL;
  3824. goto end;
  3825. }
  3826. else
  3827. {
  3828. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3829. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3830. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3831. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3832. {
  3833. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3834. result = FAIL;
  3835. goto end;
  3836. }
  3837. }// END FOR ELSE
  3838. }
  3839. }// END FOR CCS_QUANTITY
  3840. }
  3841. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3842. {
  3843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3844. {
  3845. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3846. }
  3847. else
  3848. {
  3849. tempIndex = connectorIdInt -1;
  3850. }
  3851. for (int index = 0; index < GB_QUANTITY; index++)
  3852. {
  3853. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3854. {
  3855. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3856. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3857. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3858. {
  3859. //Reserved
  3860. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3861. }
  3862. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3863. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3864. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3865. {
  3866. //Reserved
  3867. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3868. result = FAIL;
  3869. goto end;
  3870. }
  3871. else
  3872. {
  3873. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3874. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3875. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3876. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3877. {
  3878. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3879. result = FAIL;
  3880. goto end;
  3881. }
  3882. }// END FOR ELSE
  3883. }
  3884. } // END FOR GB_QUANTITY
  3885. }
  3886. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3887. {
  3888. tempIndex = connectorIdInt -1;
  3889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3892. {
  3893. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3894. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3895. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3896. {
  3897. //Reserved
  3898. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3899. }
  3900. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3901. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3902. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3903. {
  3904. //Reserved
  3905. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3906. result = FAIL;
  3907. goto end;
  3908. }
  3909. else
  3910. {
  3911. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3912. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3913. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3914. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3915. {
  3916. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3917. result = FAIL;
  3918. goto end;
  3919. }
  3920. }// END FOR ELSE
  3921. }
  3922. } // END FOR GB_QUANTITY
  3923. }
  3924. else
  3925. {
  3926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3927. {
  3928. tempIndex = 2;
  3929. }
  3930. else
  3931. {
  3932. tempIndex = connectorIdInt -1;
  3933. }
  3934. for (int index = 0; index < AC_QUANTITY; index++)
  3935. {
  3936. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3937. {
  3938. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3939. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3940. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3941. {
  3942. //Reserved
  3943. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3944. }
  3945. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3946. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3947. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3948. {
  3949. //Reserved
  3950. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3951. result = FAIL;
  3952. goto end;
  3953. }
  3954. else
  3955. {
  3956. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3957. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3958. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3959. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3960. {
  3961. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3962. result = FAIL;
  3963. goto end;
  3964. }
  3965. }//END FOR ELSE
  3966. }
  3967. }// END FOR AC_QUANTITY
  3968. }
  3969. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3970. {
  3971. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3972. {
  3973. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3974. {
  3975. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3976. system(cmdBuf);
  3977. }
  3978. }
  3979. else
  3980. {
  3981. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3982. result = FAIL;
  3983. }
  3984. }
  3985. end:
  3986. if(result == PASS)
  3987. {
  3988. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3989. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3990. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3991. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3992. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3993. }
  3994. }
  3995. void CheckSystemValue(void)
  3996. {
  3997. char filenmae[100]={0};
  3998. char str[100]={0};
  3999. int tempIndex = 0;
  4000. //===============================
  4001. // send Heartbeat
  4002. //===============================
  4003. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4004. {
  4005. //parameter for test
  4006. sendHeartbeatRequest(0);
  4007. //===========================
  4008. // Reset Waiting Time
  4009. //===========================
  4010. HeartBeatWithNOResponse += 1;
  4011. }
  4012. //===============================
  4013. // Credit deduct report
  4014. //===============================
  4015. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4016. {
  4017. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4018. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4019. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4020. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4021. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4022. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4023. }
  4024. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4025. {
  4026. OCPP_query_deduct_info();
  4027. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4028. }
  4029. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4030. {
  4031. // ClockAlign MeterValue
  4032. 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))
  4033. {
  4034. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4037. {
  4038. tempIndex = ((gun_index==2) ? 1: 0);
  4039. }
  4040. else
  4041. {
  4042. tempIndex = gun_index;
  4043. }
  4044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4045. {
  4046. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4047. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4048. {
  4049. reqClockAlignMeter[gun_index] = 1;
  4050. }
  4051. }// End for CHAdeMO
  4052. }
  4053. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4054. {
  4055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4056. {
  4057. tempIndex = ((gun_index==2) ? 1: 0);
  4058. }
  4059. else
  4060. {
  4061. tempIndex = gun_index;
  4062. }
  4063. for (int index = 0; index < CCS_QUANTITY; index++)
  4064. {
  4065. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4066. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4067. {
  4068. reqClockAlignMeter[gun_index] = 1;
  4069. }
  4070. } // End for CCS
  4071. }
  4072. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4073. {
  4074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4075. {
  4076. tempIndex = ((gun_index==2) ? 1: 0);
  4077. }
  4078. else
  4079. {
  4080. tempIndex = gun_index;
  4081. }
  4082. for (int index = 0; index < GB_QUANTITY; index++)
  4083. {
  4084. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4085. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4086. {
  4087. reqClockAlignMeter[gun_index] = 1;
  4088. }
  4089. }// End for GB
  4090. }
  4091. else if(gunType[gun_index] == GUN_TYPE_DO)
  4092. {
  4093. tempIndex = gun_index;
  4094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4095. {
  4096. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4097. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4098. {
  4099. reqClockAlignMeter[gun_index] = 1;
  4100. }
  4101. }
  4102. }
  4103. else
  4104. {
  4105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4106. {
  4107. tempIndex = 2;
  4108. }
  4109. else
  4110. {
  4111. tempIndex = gun_index;
  4112. }
  4113. for (int index = 0; index < AC_QUANTITY; index++)
  4114. {
  4115. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4116. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4117. {
  4118. reqClockAlignMeter[gun_index] = 1;
  4119. }
  4120. }//End for AC
  4121. }
  4122. }
  4123. }
  4124. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4125. {
  4126. //==========================================
  4127. // Check remote start without connector id
  4128. //==========================================
  4129. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4130. {
  4131. int connectorIdInt = -1;
  4132. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4133. {
  4134. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4135. {
  4136. connectorIdInt = (gun_index+1);
  4137. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4138. checkRemoteStart(connectorIdInt);
  4139. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4140. break;
  4141. }
  4142. }
  4143. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4144. {
  4145. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4146. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4147. }
  4148. }
  4149. //==========================================
  4150. // csu trigger DataTransferReq
  4151. //==========================================
  4152. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4153. {
  4154. sendDataTransferRequest(gun_index);
  4155. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4156. }
  4157. //==========================================
  4158. // CSU Trigger Authorize Request
  4159. //==========================================
  4160. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4161. {
  4162. sendAuthorizeRequest(0);
  4163. authorizeRetryTimes = authorizeRetryTimes + 1;
  4164. if(authorizeRetryTimes < 3)
  4165. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4166. }
  4167. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4168. {
  4169. authorizeRetryTimes = 0;
  4170. SetOcppConnStatus(FALSE);
  4171. server_sign = FALSE;
  4172. }
  4173. 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))
  4174. {
  4175. sendAuthorizeRequest(0);
  4176. }
  4177. //==========================================
  4178. // Charger start transaction
  4179. //==========================================
  4180. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4181. {
  4182. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4183. sendStartTransactionRequest(gun_index);
  4184. refreshStartTimer(&clientTime.StartTransaction);
  4185. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4186. storeTempStopTransaction(gun_index);
  4187. }
  4188. //==========================================
  4189. // Charger stop transaction
  4190. //==========================================
  4191. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4192. {
  4193. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4194. sendStopTransactionRequest(gun_index);
  4195. OCPP_updatePeriodEnergy(gun_index);
  4196. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4197. refreshStartTimer(&clientTime.StopTransaction);
  4198. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4199. }
  4200. //==========================================
  4201. // Charger status report
  4202. //==========================================
  4203. //--- Check Mode Change ---//
  4204. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4206. {
  4207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4208. {
  4209. tempIndex = ((gun_index==2) ? 1: 0);
  4210. }
  4211. else
  4212. {
  4213. tempIndex = gun_index;
  4214. }
  4215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4216. {
  4217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4218. {
  4219. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4220. {
  4221. // Sent unplug message for California pricing logic
  4222. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4223. {
  4224. uint8_t ts[20];
  4225. getNowDatetime(ts);
  4226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4228. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4229. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4230. }
  4231. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4232. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4233. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4234. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4235. {
  4236. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4237. if((access(filenmae,F_OK))!=-1)
  4238. {
  4239. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4240. sprintf(str,"rm -f %s",filenmae);
  4241. system(str);
  4242. }
  4243. }
  4244. }
  4245. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4246. #if 1 // for TempStopTransaction
  4247. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4248. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4249. {
  4250. checkTempStopTransaction(gun_index);
  4251. }
  4252. #endif
  4253. }
  4254. }
  4255. }
  4256. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4259. {
  4260. tempIndex = ((gun_index==2) ? 1: 0);
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < CCS_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4269. {
  4270. 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]*/ )
  4271. {
  4272. // Sent unplug message for California pricing logic
  4273. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4274. {
  4275. uint8_t ts[20];
  4276. getNowDatetime(ts);
  4277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4278. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4279. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4280. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4281. }
  4282. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4283. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4284. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4286. {
  4287. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4288. if((access(filenmae,F_OK))!=-1)
  4289. {
  4290. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4291. sprintf(str,"rm -f %s",filenmae);
  4292. system(str);
  4293. }
  4294. }
  4295. }
  4296. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4297. #if 1 // for TempStopTransaction
  4298. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4299. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4300. {
  4301. checkTempStopTransaction(gun_index);
  4302. }
  4303. #endif
  4304. }
  4305. }
  4306. }
  4307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < GB_QUANTITY; index++)
  4318. {
  4319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4320. {
  4321. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4322. {
  4323. // Sent unplug message for California pricing logic
  4324. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4325. {
  4326. uint8_t ts[20];
  4327. getNowDatetime(ts);
  4328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4331. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4332. }
  4333. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4334. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4336. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4337. {
  4338. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4339. if((access(filenmae,F_OK))!=-1)
  4340. {
  4341. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4342. sprintf(str,"rm -f %s",filenmae);
  4343. system(str);
  4344. }
  4345. }
  4346. }
  4347. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4348. #if 1 // for TempStopTransaction
  4349. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4350. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4351. {
  4352. checkTempStopTransaction(gun_index);
  4353. }
  4354. #endif
  4355. }
  4356. }
  4357. }
  4358. else if(gunType[gun_index] == GUN_TYPE_DO)
  4359. {
  4360. tempIndex = gun_index;
  4361. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4364. {
  4365. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4366. {
  4367. // Sent unplug message for California pricing logic
  4368. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4369. {
  4370. uint8_t ts[20];
  4371. getNowDatetime(ts);
  4372. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4373. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4374. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4375. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4376. }
  4377. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4378. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4379. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4380. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4381. {
  4382. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4383. if((access(filenmae,F_OK))!=-1)
  4384. {
  4385. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4386. sprintf(str,"rm -f %s",filenmae);
  4387. system(str);
  4388. }
  4389. }
  4390. }
  4391. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4392. #if 1 // for TempStopTransaction
  4393. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4394. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4395. {
  4396. checkTempStopTransaction(gun_index);
  4397. }
  4398. #endif
  4399. }
  4400. }
  4401. }
  4402. else
  4403. {
  4404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4405. {
  4406. tempIndex = 2;
  4407. }
  4408. else
  4409. {
  4410. tempIndex = gun_index;
  4411. }
  4412. for (int index = 0; index < AC_QUANTITY; index++)
  4413. {
  4414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4415. {
  4416. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4417. {
  4418. // Sent unplug message for California pricing logic
  4419. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4420. {
  4421. uint8_t ts[20];
  4422. getNowDatetime(ts);
  4423. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4424. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4425. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4426. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4427. }
  4428. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4429. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4430. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4431. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4432. {
  4433. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4434. if((access(filenmae,F_OK))!=-1)
  4435. {
  4436. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4437. sprintf(str,"rm -f %s",filenmae);
  4438. system(str);
  4439. }
  4440. }
  4441. }
  4442. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4443. #if 1 // for TempStopTransaction
  4444. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4445. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4446. {
  4447. checkTempStopTransaction(gun_index);
  4448. }
  4449. #endif
  4450. }
  4451. }// END
  4452. }
  4453. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4454. (
  4455. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4456. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4457. )
  4458. )
  4459. {
  4460. if(SystemInitial > 0)
  4461. SystemInitial -= 1;
  4462. sendStatusNotificationRequest(gun_index);
  4463. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4464. }
  4465. //==============================================
  4466. // TCCI reader status report
  4467. //==============================================
  4468. if(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4469. {
  4470. reportReaderStatus(gun_index);
  4471. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4472. }
  4473. //==============================================
  4474. // CSU Trigger Smart Charging Profile
  4475. //==============================================
  4476. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4477. {
  4478. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4479. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4480. }
  4481. //==============================================
  4482. // Meter report
  4483. //==============================================
  4484. // Trigger MeterValue
  4485. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4486. {
  4487. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4488. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4489. }
  4490. // Clock-aligned Meter value
  4491. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4492. {
  4493. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4494. reqClockAlignMeter[gun_index] = 0;
  4495. }
  4496. // Sample period MeterValue
  4497. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4498. {
  4499. //check Transaction active
  4500. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4501. {
  4502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4503. {
  4504. tempIndex = ((gun_index==2) ? 1: 0);
  4505. }
  4506. else
  4507. {
  4508. tempIndex = gun_index;
  4509. }
  4510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4511. {
  4512. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4513. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4514. {
  4515. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4516. {
  4517. reqSampleMeter[gun_index] = 1;
  4518. }
  4519. }
  4520. }// End for CHAdeMO
  4521. }
  4522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4525. {
  4526. tempIndex = ((gun_index==2) ? 1: 0);
  4527. }
  4528. else
  4529. {
  4530. tempIndex = gun_index;
  4531. }
  4532. for (int index = 0; index < CCS_QUANTITY; index++)
  4533. {
  4534. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4535. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4536. {
  4537. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4538. {
  4539. reqSampleMeter[gun_index] = 1;
  4540. }
  4541. }
  4542. } // End for CCS
  4543. }
  4544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4545. {
  4546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4547. {
  4548. tempIndex = ((gun_index==2) ? 1: 0);
  4549. }
  4550. else
  4551. {
  4552. tempIndex = gun_index;
  4553. }
  4554. for (int index = 0; index < GB_QUANTITY; index++)
  4555. {
  4556. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4558. {
  4559. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4560. {
  4561. reqSampleMeter[gun_index] = 1;
  4562. }
  4563. }
  4564. }// End for GB
  4565. }
  4566. else if(gunType[gun_index] == GUN_TYPE_DO)
  4567. {
  4568. tempIndex = gun_index;
  4569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4570. {
  4571. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4572. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4573. {
  4574. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4575. {
  4576. reqSampleMeter[gun_index] = 1;
  4577. }
  4578. }
  4579. }
  4580. }
  4581. else
  4582. {
  4583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4584. {
  4585. tempIndex = 2;
  4586. }
  4587. else
  4588. {
  4589. tempIndex = gun_index;
  4590. }
  4591. for (int index = 0; index < AC_QUANTITY; index++)
  4592. {
  4593. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4594. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4597. {
  4598. reqSampleMeter[gun_index] = 1;
  4599. }
  4600. }
  4601. }//End for AC
  4602. }
  4603. if(reqSampleMeter[gun_index] == 1)
  4604. {
  4605. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4606. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4607. storeTempStopTransaction(gun_index);
  4608. reqSampleMeter[gun_index] = 0;
  4609. }
  4610. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4611. }
  4612. //==============================================
  4613. // Check Connector reserved
  4614. //==============================================
  4615. //===============================
  4616. // Check if Reserve is expired
  4617. //===============================
  4618. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4619. {
  4620. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4621. {
  4622. DEBUG_INFO("reserve expired.\n");
  4623. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4624. }
  4625. }//END OF Check if Reserve is expired
  4626. //==========================================
  4627. // csu trigger FirmwareStatusNotificationReq
  4628. //==========================================
  4629. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4630. {
  4631. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4632. }
  4633. //==========================================
  4634. // csu trigger DiagnosticsStatusNotificationReq
  4635. //==========================================
  4636. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4637. {
  4638. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4639. }
  4640. //==========================================
  4641. // csu trigger CancelReservationConf
  4642. //==========================================
  4643. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4644. {
  4645. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4646. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4647. }
  4648. //==========================================
  4649. // csu trigger ChangeAvailabilityConf
  4650. //==========================================
  4651. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4652. {
  4653. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4654. }
  4655. //==========================================
  4656. // csu trigger UnlockConnectorConf
  4657. //==========================================
  4658. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4659. {
  4660. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4661. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4662. }
  4663. //==========================================
  4664. // csu trigger ReserveNowConf
  4665. //==========================================
  4666. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4667. {
  4668. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4669. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4670. }
  4671. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4672. {
  4673. sendSignCertificateRequest();
  4674. }
  4675. }
  4676. }
  4677. //==========================================
  4678. // send request routine
  4679. //==========================================
  4680. int sendAuthorizeRequest(int gun_index)
  4681. {
  4682. mtrace();
  4683. int result = FAIL;
  4684. char message[100]={0};
  4685. char guid[37];
  4686. char tempdata[65]={0};
  4687. DEBUG_INFO("sendAuthorizeRequest...\n");
  4688. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4689. //Local Authorize
  4690. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4691. {
  4692. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4693. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4696. result = PASS;
  4697. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4698. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4699. authorizeRetryTimes = 0;
  4700. return result;
  4701. }
  4702. 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))||
  4703. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4704. {
  4705. // Query from cache
  4706. DEBUG_INFO("Authorize from cache.\n");
  4707. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4708. // Query from list
  4709. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4710. {
  4711. DEBUG_INFO("Authorize from list.\n");
  4712. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4713. }
  4714. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4715. {
  4716. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4717. {
  4718. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4719. }
  4720. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4721. {
  4722. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4723. }
  4724. if(!GetOcppConnStatus())
  4725. {
  4726. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4727. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4728. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4729. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4730. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4731. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4732. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4733. authorizeRetryTimes = 0;
  4734. return result;
  4735. }
  4736. }
  4737. else
  4738. {
  4739. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4740. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4741. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4742. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4743. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4744. else
  4745. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4746. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4747. result = PASS;
  4748. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4749. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4750. authorizeRetryTimes = 0;
  4751. return result;
  4752. }
  4753. }
  4754. //initialize struct Authorize
  4755. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4756. //get data from shared memory
  4757. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4758. random_uuid(guid);
  4759. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4760. LWS_Send(message);
  4761. sprintf(tempdata, "Authorize,%d", gun_index);
  4762. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4763. {
  4764. result = PASS;
  4765. DEBUG_INFO("Authorize mapItem pass\n");
  4766. }
  4767. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4768. return result;
  4769. }
  4770. int sendBootNotificationRequest(void)
  4771. {
  4772. mtrace();
  4773. int result = FAIL;
  4774. char message[500]={0}, payload[700]={0};
  4775. char guid[37]={0};
  4776. char tempdata[65]={0};
  4777. // Fill BootNotification fields
  4778. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4779. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4780. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4781. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4782. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4783. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4784. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4785. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4786. ShmOCPP16Data->ChargeBoxId
  4787. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4788. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4789. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4790. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4791. ,ShmOCPP16Data->BootNotification.CpIccid
  4792. ,ShmOCPP16Data->BootNotification.CpImsi);
  4793. random_uuid(guid);
  4794. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4795. LWS_Send(message);
  4796. sprintf(tempdata, "BootNotification,0");
  4797. 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*/)
  4798. {
  4799. result = PASS;
  4800. }
  4801. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4802. strcpy(queuedata,message);
  4803. return result;
  4804. }
  4805. int sendDataTransferRequest(int gun_index)
  4806. {
  4807. mtrace();
  4808. char message[1000]={0};
  4809. char guid[37]={0};
  4810. char tempdata[65]={0};
  4811. int result = FAIL;
  4812. random_uuid(guid);
  4813. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4814. MESSAGE_TYPE_CALL,
  4815. guid,
  4816. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4817. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4818. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4819. LWS_Send(message);
  4820. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4821. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4822. {
  4823. result = PASS;
  4824. DEBUG_INFO("DataTransfer mapItem pass\n");
  4825. }
  4826. return result;
  4827. }
  4828. int sendDiagnosticsStatusNotificationRequest(char *status)
  4829. {
  4830. mtrace();
  4831. int result = FAIL;
  4832. char message[110]={0};
  4833. char guid[37]={0};
  4834. char tempdata[65]={0};
  4835. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4836. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4837. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4838. random_uuid(guid);
  4839. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4840. LWS_SendNow(message);
  4841. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4842. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4843. {
  4844. result = PASS;
  4845. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4846. }
  4847. //#ifdef SystemLogMessage
  4848. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4849. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4850. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4851. //#endif
  4852. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4853. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4854. //record status
  4855. if(strcmp(status,"Idle")==0)
  4856. {
  4857. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4858. }
  4859. else if(strcmp(status,"Uploaded")==0)
  4860. {
  4861. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4862. }
  4863. else if(strcmp(status,"UploadFailed")==0)
  4864. {
  4865. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4866. }
  4867. else if(strcmp(status,"Uploading")==0)
  4868. {
  4869. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4870. }
  4871. return result;
  4872. }
  4873. int sendFirmwareStatusNotificationRequest(char *status)
  4874. {
  4875. mtrace();
  4876. int result = FAIL;
  4877. char message[110]={0};
  4878. char guid[37]={0};
  4879. char tempdata[65]={0};
  4880. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4881. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4882. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4883. random_uuid(guid);
  4884. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4885. LWS_SendNow(message);
  4886. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4887. 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*/)
  4888. {
  4889. result = PASS;
  4890. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4891. }
  4892. //#ifdef SystemLogMessage
  4893. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4894. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4895. //#endif
  4896. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4897. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4898. //record status
  4899. if(strcmp(status,"Downloaded")==0)
  4900. {
  4901. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4902. }
  4903. else if(strcmp(status,"DownloadFailed")==0)
  4904. {
  4905. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4906. }
  4907. else if(strcmp(status,"Downloading")==0)
  4908. {
  4909. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4910. }
  4911. else if(strcmp(status,"Idle")==0)
  4912. {
  4913. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4914. }
  4915. else if(strcmp(status,"InstallationFailed")==0)
  4916. {
  4917. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4918. }
  4919. else if(strcmp(status,"Installing")==0)
  4920. {
  4921. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4922. }
  4923. else if(strcmp(status,"Installed")==0)
  4924. {
  4925. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4926. }
  4927. return result;
  4928. }
  4929. int sendHeartbeatRequest(int gun_index)
  4930. {
  4931. mtrace();
  4932. int result = FAIL;
  4933. char message[80]={0};
  4934. char guid[37]={0};
  4935. char tempdata[65]={0};
  4936. random_uuid(guid);
  4937. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4938. , MESSAGE_TYPE_CALL
  4939. , guid );
  4940. LWS_Send(message);
  4941. sprintf(tempdata, "Heartbeat,%d", 0);
  4942. 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*/)
  4943. {
  4944. result = PASS;
  4945. }
  4946. return result;
  4947. }
  4948. int sendStartTransactionRequest(int gun_index)
  4949. {
  4950. mtrace();
  4951. int result = FAIL;
  4952. char message[250]={0};
  4953. char guid[37]={0};
  4954. struct timeval tmnow;
  4955. struct tm *tm;
  4956. char buf[28];//, usec_buf[6];
  4957. char tempdata[65]={0};
  4958. int tempIndex = 0;
  4959. DEBUG_INFO("sendStartTransactionRequest...\n");
  4960. gettimeofday(&tmnow, NULL);
  4961. time_t t;
  4962. t = time(NULL);
  4963. /*UTC time and date*/
  4964. tm = gmtime(&t);
  4965. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4966. #if 0 // remove temporally
  4967. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4968. strcat(buf,".");
  4969. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4970. strcat(buf,usec_buf);
  4971. #endif
  4972. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4973. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4974. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4975. // clear StartTransaction Response
  4976. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4977. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4978. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4979. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4980. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4985. {
  4986. tempIndex = ((gun_index==2) ? 1: 0);
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4995. {
  4996. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4997. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4998. }
  4999. }
  5000. }
  5001. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5002. {
  5003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5004. {
  5005. tempIndex = ((gun_index==2) ? 1: 0);
  5006. }
  5007. else
  5008. {
  5009. tempIndex = gun_index;
  5010. }
  5011. for (int index = 0; index < CCS_QUANTITY; index++)
  5012. {
  5013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5014. {
  5015. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5016. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5017. }
  5018. }
  5019. }
  5020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5021. {
  5022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5023. {
  5024. tempIndex = ((gun_index==2) ? 1: 0);
  5025. }
  5026. else
  5027. {
  5028. tempIndex = gun_index;
  5029. }
  5030. for (int index = 0; index < GB_QUANTITY; index++)
  5031. {
  5032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5033. {
  5034. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5035. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5036. }
  5037. }
  5038. }
  5039. else if(gunType[gun_index] == GUN_TYPE_DO)
  5040. {
  5041. tempIndex = gun_index;
  5042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5045. {
  5046. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5047. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5048. }
  5049. }
  5050. }
  5051. else
  5052. {
  5053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5054. {
  5055. tempIndex = 2;
  5056. }
  5057. else
  5058. {
  5059. tempIndex = gun_index;
  5060. }
  5061. for (int index = 0; index < AC_QUANTITY; index++)
  5062. {
  5063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5064. {
  5065. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5066. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5067. }
  5068. }
  5069. }
  5070. random_uuid(guid);
  5071. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5072. {
  5073. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5074. , gun_index +1
  5075. , MESSAGE_TYPE_CALL
  5076. , guid
  5077. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5078. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5079. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5080. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5081. }
  5082. else
  5083. {
  5084. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5085. , gun_index +1
  5086. , MESSAGE_TYPE_CALL
  5087. , guid
  5088. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5089. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5090. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5091. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5092. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5093. }
  5094. #if 1
  5095. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5096. 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*/)
  5097. {
  5098. result = PASS;
  5099. }
  5100. #endif
  5101. strcpy(queuedata, message);
  5102. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5103. OCPP_insert_transaction_msg(YES, queuedata);
  5104. return result;
  5105. }
  5106. int sendStatusNotificationRequest(int gun_index)
  5107. {
  5108. mtrace();
  5109. int result = FAIL;
  5110. char message[600]={0};
  5111. char guid[37];
  5112. int currentStatus = 0;
  5113. struct timeval tmnow;
  5114. struct tm *tm;
  5115. char buf[28];//, usec_buf[6];
  5116. char tempdata[65]={0};
  5117. int tempIndex = 0;
  5118. uint8_t isStateChanged = TRUE;
  5119. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5120. gettimeofday(&tmnow, NULL);
  5121. time_t t;
  5122. t = time(NULL);
  5123. /*UTC time and date*/
  5124. tm = gmtime(&t);
  5125. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5126. #if 0 // remove temporally
  5127. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5128. strcat(buf,".");
  5129. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5130. strcat(buf,usec_buf);
  5131. #endif
  5132. //printf("%s",buf);
  5133. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5134. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5135. // it's option
  5136. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5137. /*
  5138. enum _SYSTEM_STATUS
  5139. {
  5140. S_BOOTING = 0,
  5141. S_IDLE, = 1
  5142. S_AUTHORIZING, =2
  5143. S_REASSIGN_CHECK, =3
  5144. S_REASSIGN, =4
  5145. S_PRECHARGE, =5
  5146. S_PREPARING_FOR_EV, =6
  5147. S_PREPARING_FOR_EVSE, =7
  5148. S_CHARGING, =8
  5149. S_TERMINATING, =9
  5150. S_COMPLETE, =10
  5151. S_ALARM, =11
  5152. S_FAULT =12
  5153. }
  5154. */
  5155. //check Transaction active
  5156. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5157. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5160. {
  5161. tempIndex = ((gun_index==2) ? 1: 0);
  5162. }
  5163. else
  5164. {
  5165. tempIndex = gun_index;
  5166. }
  5167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5168. {
  5169. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5170. {
  5171. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5172. {
  5173. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5174. {
  5175. currentStatus = Preparing; //OCPP Status: Preparing
  5176. }
  5177. else
  5178. {
  5179. currentStatus = Available; //OCPP Status: Available
  5180. }
  5181. }
  5182. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5183. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5184. ) //S_PRECHARGE
  5185. {
  5186. currentStatus = Preparing; //OCPP Status: Preparing
  5187. }
  5188. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5189. {
  5190. currentStatus = Charging; //OCPP Status: Charging
  5191. }
  5192. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5193. {
  5194. currentStatus = Finishing; //OCPP Status: Finishing
  5195. }
  5196. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5197. {
  5198. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5199. }
  5200. 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
  5201. {
  5202. currentStatus = Unavailable; //OCPP Status: Unavailable
  5203. }
  5204. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5205. {
  5206. currentStatus = Faulted; //OCPP Status: Faulted
  5207. }
  5208. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5209. {
  5210. currentStatus = Reserved; //OCPP Status: Reserved
  5211. }
  5212. } //end of the same index
  5213. }//end of for CHAdeMO_QUANTITY
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5216. {
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5218. {
  5219. tempIndex = ((gun_index==2) ? 1: 0);
  5220. }
  5221. else
  5222. {
  5223. tempIndex = gun_index;
  5224. }
  5225. for (int index = 0; index < CCS_QUANTITY; index++)
  5226. {
  5227. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5228. {
  5229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5230. {
  5231. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5232. {
  5233. currentStatus = Preparing; //OCPP Status: Preparing
  5234. }
  5235. else
  5236. {
  5237. currentStatus = Available; //OCPP Status: Available
  5238. }
  5239. }
  5240. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5241. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5242. ) //S_PRECHARGE
  5243. {
  5244. currentStatus = Preparing; //OCPP Status: Preparing
  5245. }
  5246. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5247. {
  5248. currentStatus = Charging; //OCPP Status: Charging
  5249. }
  5250. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5251. {
  5252. currentStatus = Finishing; //OCPP Status: Finishing
  5253. }
  5254. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5255. {
  5256. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5257. }
  5258. 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
  5259. {
  5260. currentStatus = Unavailable; //OCPP Status : Unavailable
  5261. }
  5262. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5263. {
  5264. currentStatus = Faulted; //OCPP Status: Faulted
  5265. }
  5266. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5267. {
  5268. currentStatus = Reserved; //OCPP Status: Reserved
  5269. }
  5270. } //end of the same index
  5271. } // end of for CCS_QUANTITY
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5274. {
  5275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5276. {
  5277. tempIndex = ((gun_index==2) ? 1: 0);
  5278. }
  5279. else
  5280. {
  5281. tempIndex = gun_index;
  5282. }
  5283. for (int index = 0; index < GB_QUANTITY; index++)
  5284. {
  5285. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5288. {
  5289. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5290. {
  5291. currentStatus = Preparing; //OCPP Status: Preparing
  5292. }
  5293. else
  5294. {
  5295. currentStatus = Available; //OCPP Status: Available
  5296. }
  5297. }
  5298. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5299. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5300. ) //S_PRECHARGE
  5301. {
  5302. currentStatus = Preparing; //OCPP Status: Preparing
  5303. }
  5304. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5305. {
  5306. currentStatus = Charging; //OCPP Status: Charging
  5307. }
  5308. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5309. {
  5310. currentStatus = Finishing; //OCPP Status: Finishing
  5311. }
  5312. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5313. {
  5314. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5315. }
  5316. 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
  5317. {
  5318. currentStatus = Unavailable; //OCPP Status: Unavailable
  5319. }
  5320. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5321. {
  5322. currentStatus = Faulted; //OCPP Status: Faulted
  5323. }
  5324. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5325. {
  5326. currentStatus = Reserved; //OCPP Status: Reserved
  5327. }
  5328. } //end of the same index
  5329. } // end of for GB_QUANTITY
  5330. }
  5331. else if(gunType[gun_index] == GUN_TYPE_DO)
  5332. {
  5333. tempIndex = gun_index;
  5334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5335. {
  5336. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5337. {
  5338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5339. {
  5340. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5341. {
  5342. currentStatus = Preparing; //OCPP Status: Preparing
  5343. }
  5344. else
  5345. {
  5346. currentStatus = Available; //OCPP Status: Available
  5347. }
  5348. }
  5349. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5350. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5351. ) //S_PRECHARGE
  5352. {
  5353. currentStatus = Preparing; //OCPP Status: Preparing
  5354. }
  5355. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5356. {
  5357. currentStatus = Charging; //OCPP Status: Charging
  5358. }
  5359. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5360. {
  5361. currentStatus = Finishing; //OCPP Status: Finishing
  5362. }
  5363. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5364. {
  5365. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5366. }
  5367. 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
  5368. {
  5369. currentStatus = Unavailable; //OCPP Status: Unavailable
  5370. }
  5371. 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
  5372. {
  5373. currentStatus = Faulted; //OCPP Status: Faulted
  5374. }
  5375. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5376. {
  5377. currentStatus = Reserved; //OCPP Status: Reserved
  5378. }
  5379. } //end of the same index
  5380. }
  5381. }
  5382. else
  5383. {
  5384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5385. {
  5386. tempIndex = 2;
  5387. }
  5388. else
  5389. {
  5390. tempIndex = gun_index;
  5391. }
  5392. for (int index = 0; index < AC_QUANTITY; index++)
  5393. {
  5394. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5395. {
  5396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5397. {
  5398. 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))
  5399. {
  5400. currentStatus = Preparing; //OCPP Status: Preparing
  5401. }
  5402. else
  5403. {
  5404. currentStatus = Available; //OCPP Status: Available
  5405. }
  5406. }
  5407. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5408. {
  5409. currentStatus = Preparing; //OCPP Status: Preparing
  5410. }
  5411. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5412. {
  5413. currentStatus = Charging; //OCPP Status: Charging
  5414. }
  5415. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5416. {
  5417. currentStatus = Finishing; //OCPP Status: Finishing
  5418. }
  5419. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5420. {
  5421. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5422. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5423. else
  5424. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5425. }
  5426. 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
  5427. {
  5428. currentStatus = Unavailable; //OCPP Status: Unavailable
  5429. }
  5430. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5431. {
  5432. currentStatus = Faulted; //OCPP Status: Faulted
  5433. }
  5434. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5435. {
  5436. currentStatus = Reserved; //OCPP Status: Reserved
  5437. }
  5438. }//end of the same index
  5439. }//end of for AC_QUANTITY
  5440. }
  5441. //it's option
  5442. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5443. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5444. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5445. {
  5446. isStateChanged = FALSE;
  5447. }
  5448. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5449. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5450. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5451. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5452. random_uuid(guid);
  5453. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5454. , MESSAGE_TYPE_CALL
  5455. , guid
  5456. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5457. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5458. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5459. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5460. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5461. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5462. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5463. if((server_sign == TRUE) && isStateChanged)
  5464. {
  5465. LWS_Send(message);
  5466. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5467. 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*/)
  5468. {
  5469. //DEBUG_ERROR("statusNotification mapitem pass");
  5470. result = PASS;
  5471. }
  5472. }
  5473. else
  5474. {
  5475. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5476. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5477. result = PASS;
  5478. }
  5479. return result;
  5480. }
  5481. int sendStopTransactionRequest(int gun_index)
  5482. {
  5483. mtrace();
  5484. int result = FAIL;
  5485. //char message[1500]={0};
  5486. char guid[37]={0};
  5487. char tempdata[65]={0};
  5488. int tempIndex = 0;
  5489. char TempStopTransaction[256];
  5490. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5491. //int idx_sample=0;
  5492. DEBUG_INFO("sendStopTransactionRequest \n");
  5493. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5494. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5495. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5496. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5510. {
  5511. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5512. }
  5513. }// END OF CHAdeMO_QUANTITY
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5516. {
  5517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5518. {
  5519. tempIndex = ((gun_index==2) ? 1: 0);
  5520. }
  5521. else
  5522. {
  5523. tempIndex = gun_index;
  5524. }
  5525. for (int index = 0; index < CCS_QUANTITY; index++)
  5526. {
  5527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5528. {
  5529. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5530. }
  5531. }// END OF CCS_QUANTITY
  5532. }
  5533. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5534. {
  5535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5536. {
  5537. tempIndex = ((gun_index==2) ? 1: 0);
  5538. }
  5539. else
  5540. {
  5541. tempIndex = gun_index;
  5542. }
  5543. for (int index = 0; index < GB_QUANTITY; index++)
  5544. {
  5545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5546. {
  5547. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5548. }
  5549. }// END OF GB_QUANTITY
  5550. }
  5551. else if(gunType[gun_index] == GUN_TYPE_DO)
  5552. {
  5553. tempIndex = gun_index;
  5554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5555. {
  5556. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5557. {
  5558. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5559. }
  5560. }// END OF GB_QUANTITY
  5561. }
  5562. else
  5563. {
  5564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5565. {
  5566. tempIndex = 2;
  5567. }
  5568. else
  5569. {
  5570. tempIndex = gun_index;
  5571. }
  5572. for (int index = 0; index < AC_QUANTITY; index++)
  5573. {
  5574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5575. {
  5576. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5577. }
  5578. }// END OF AC_QUANTITY
  5579. }
  5580. //====================================== Stop Transaction Time =====================================================
  5581. struct timeval tmnow;
  5582. struct tm *tm;
  5583. char buf[28];//, usec_buf[6];
  5584. gettimeofday(&tmnow, NULL);
  5585. time_t t;
  5586. t = time(NULL);
  5587. /*UTC time and date*/
  5588. tm = gmtime(&t);
  5589. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5591. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5592. random_uuid(guid);
  5593. /***********************************transactionData******************************************************/
  5594. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5596. //=================================
  5597. // Transaction_Begin
  5598. //=================================
  5599. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5600. {
  5601. //============================================ Energy.Active.Import.Interval ================================
  5602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5605. 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*/]);
  5606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5607. 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))
  5608. {
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5610. }
  5611. else
  5612. {
  5613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5614. }
  5615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5617. }
  5618. //=================================
  5619. // Transaction_End
  5620. //=================================
  5621. // ================================= Current.Import L1 ===============================================
  5622. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5623. {
  5624. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5626. {
  5627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5628. {
  5629. tempIndex = ((gun_index==2) ? 1: 0);
  5630. }
  5631. else
  5632. {
  5633. tempIndex = gun_index;
  5634. }
  5635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5636. {
  5637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5638. {
  5639. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5640. }
  5641. }// End of for CHAdeMO_QUANTITY
  5642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5643. }
  5644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5645. {
  5646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5647. {
  5648. tempIndex = ((gun_index==2) ? 1: 0);
  5649. }
  5650. else
  5651. {
  5652. tempIndex = gun_index;
  5653. }
  5654. for (int index = 0; index < CCS_QUANTITY; index++)
  5655. {
  5656. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5657. {
  5658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5659. }
  5660. }// End of for CCS_QUANTITY
  5661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5662. }
  5663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5664. {
  5665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5666. {
  5667. tempIndex = ((gun_index==2) ? 1: 0);
  5668. }
  5669. else
  5670. {
  5671. tempIndex = gun_index;
  5672. }
  5673. for (int index = 0; index < GB_QUANTITY; index++)
  5674. {
  5675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5676. {
  5677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5678. }
  5679. }// End of for GB_QUANTITY
  5680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5681. }
  5682. else if(gunType[gun_index] == GUN_TYPE_DO)
  5683. {
  5684. tempIndex = gun_index;
  5685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5686. {
  5687. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5688. {
  5689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5690. }
  5691. }
  5692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5693. }
  5694. else
  5695. {
  5696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5697. {
  5698. tempIndex = 2;
  5699. }
  5700. else
  5701. {
  5702. tempIndex = gun_index;
  5703. }
  5704. for (int index = 0; index < AC_QUANTITY; index++)
  5705. {
  5706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5707. {
  5708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5709. }
  5710. }// End of for AC_QUANTITY
  5711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5712. }
  5713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5718. }
  5719. // ================================= Energy.Active.Import.Interval ==============================================
  5720. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5721. {
  5722. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5723. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5724. {
  5725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5726. {
  5727. tempIndex = ((gun_index==2) ? 1: 0);
  5728. }
  5729. else
  5730. {
  5731. tempIndex = gun_index;
  5732. }
  5733. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5734. {
  5735. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5736. {
  5737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5738. }
  5739. }// END OF CHAdeMO_QUANTITY
  5740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5741. }
  5742. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5743. {
  5744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5745. {
  5746. tempIndex = ((gun_index==2) ? 1: 0);
  5747. }
  5748. else
  5749. {
  5750. tempIndex = gun_index;
  5751. }
  5752. for (int index = 0; index < CCS_QUANTITY; index++)
  5753. {
  5754. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5755. {
  5756. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5757. }
  5758. }// END OF CCS_QUANTITY
  5759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5760. }
  5761. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5762. {
  5763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5764. {
  5765. tempIndex = ((gun_index==2) ? 1: 0);
  5766. }
  5767. else
  5768. {
  5769. tempIndex = gun_index;
  5770. }
  5771. for (int index = 0; index < GB_QUANTITY; index++)
  5772. {
  5773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5774. {
  5775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5776. }
  5777. }// END OF GB_QUANTITY
  5778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5779. }
  5780. else if(gunType[gun_index] == GUN_TYPE_DO)
  5781. {
  5782. tempIndex = gun_index;
  5783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5784. {
  5785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5786. {
  5787. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5788. }
  5789. }
  5790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5791. }
  5792. else
  5793. {
  5794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5795. {
  5796. tempIndex = 2;
  5797. }
  5798. else
  5799. {
  5800. tempIndex = gun_index;
  5801. }
  5802. for (int index = 0; index < AC_QUANTITY; index++)
  5803. {
  5804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5805. {
  5806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5807. }
  5808. }// END OF AC_QUANTITY
  5809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5810. }
  5811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5816. }
  5817. //=================================== Power.Active.Import ==================================================
  5818. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5819. {
  5820. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5821. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5822. {
  5823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5824. {
  5825. tempIndex = ((gun_index==2) ? 1: 0);
  5826. }
  5827. else
  5828. {
  5829. tempIndex = gun_index;
  5830. }
  5831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5832. {
  5833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5834. {
  5835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5836. }
  5837. } // End for CHAdeMO_QUANTITY
  5838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5839. }
  5840. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5841. {
  5842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5843. {
  5844. tempIndex = ((gun_index==2) ? 1: 0);
  5845. }
  5846. else
  5847. {
  5848. tempIndex = gun_index;
  5849. }
  5850. for (int index = 0; index < CCS_QUANTITY; index++)
  5851. {
  5852. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5853. {
  5854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5855. }
  5856. } // END for CCS_QUANTITY
  5857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5858. }
  5859. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5860. {
  5861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5862. {
  5863. tempIndex = ((gun_index==2) ? 1: 0);
  5864. }
  5865. else
  5866. {
  5867. tempIndex = gun_index;
  5868. }
  5869. for (int index = 0; index < GB_QUANTITY; index++)
  5870. {
  5871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5872. {
  5873. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5874. }
  5875. }// END for GB_QUANTITY
  5876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5877. }
  5878. else if(gunType[gun_index] == GUN_TYPE_DO)
  5879. {
  5880. tempIndex = gun_index;
  5881. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5882. {
  5883. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5884. {
  5885. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5886. }
  5887. }
  5888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5889. }
  5890. else
  5891. {
  5892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5893. {
  5894. tempIndex = 2;
  5895. }
  5896. else
  5897. {
  5898. tempIndex = gun_index;
  5899. }
  5900. for (int index = 0; index < AC_QUANTITY; index++)
  5901. {
  5902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5903. {
  5904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5905. }
  5906. } // END for AC_QUANTITY
  5907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5908. }
  5909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5914. }
  5915. //============================ Voltage L1 ====================================
  5916. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5917. {
  5918. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5919. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5920. {
  5921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5922. {
  5923. tempIndex = ((gun_index==2) ? 1: 0);
  5924. }
  5925. else
  5926. {
  5927. tempIndex = gun_index;
  5928. }
  5929. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5930. {
  5931. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5932. {
  5933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5934. }
  5935. } // END OF FOR CHAdeMO_QUANTITY
  5936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5937. }
  5938. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5939. {
  5940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5941. {
  5942. tempIndex = ((gun_index==2) ? 1: 0);
  5943. }
  5944. else
  5945. {
  5946. tempIndex = gun_index;
  5947. }
  5948. for (int index = 0; index < CCS_QUANTITY; index++)
  5949. {
  5950. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5951. {
  5952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5953. }
  5954. } // END OF FOR CCS_QUANTITY
  5955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5956. }
  5957. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5958. {
  5959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5960. {
  5961. tempIndex = ((gun_index==2) ? 1: 0);
  5962. }
  5963. else
  5964. {
  5965. tempIndex = gun_index;
  5966. }
  5967. for (int index = 0; index < GB_QUANTITY; index++)
  5968. {
  5969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5970. {
  5971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5972. }
  5973. } // END OF FOR GB_QUANTITY
  5974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5975. }
  5976. else if(gunType[gun_index] == GUN_TYPE_DO)
  5977. {
  5978. tempIndex = gun_index;
  5979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5980. {
  5981. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5982. {
  5983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5984. }
  5985. }
  5986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5987. }
  5988. else
  5989. {
  5990. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5991. {
  5992. tempIndex = 2;
  5993. }
  5994. else
  5995. {
  5996. tempIndex = gun_index;
  5997. }
  5998. for (int index = 0; index < AC_QUANTITY; index++)
  5999. {
  6000. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6001. {
  6002. 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
  6003. }
  6004. } // END OF FOR AC_QUANTITY
  6005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6006. }
  6007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6012. }
  6013. //====================== End SoC ================================
  6014. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6015. {
  6016. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6017. 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))
  6018. {
  6019. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6020. {
  6021. tempIndex = ((gun_index==2) ? 1: 0);
  6022. }
  6023. else
  6024. {
  6025. tempIndex = gun_index;
  6026. }
  6027. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6028. {
  6029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6030. {
  6031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6032. {
  6033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6034. }
  6035. }
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6038. {
  6039. for (int index = 0; index < CCS_QUANTITY; index++)
  6040. {
  6041. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6042. {
  6043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6044. }
  6045. }
  6046. }
  6047. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6048. {
  6049. for (int index = 0; index < GB_QUANTITY; index++)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6052. {
  6053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6054. }
  6055. }
  6056. }
  6057. else if(gunType[gun_index] == GUN_TYPE_DO)
  6058. {
  6059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6064. }
  6065. }
  6066. }
  6067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6073. } // END FOR DC CASE
  6074. }
  6075. // ================================= Current.Import L2 ===============================================
  6076. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6077. {
  6078. // AC 3 phse L2 current
  6079. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6080. {
  6081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6082. {
  6083. tempIndex = 2;
  6084. }
  6085. else
  6086. {
  6087. tempIndex = gun_index;
  6088. }
  6089. for (int index = 0; index < AC_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6094. }
  6095. }// End of for AC_QUANTITY
  6096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6097. }
  6098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6103. }
  6104. // ================================= Current.Import L3 ===============================================
  6105. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6106. {
  6107. // AC 3 phse L3 current
  6108. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6109. {
  6110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6111. {
  6112. tempIndex = 2;
  6113. }
  6114. else
  6115. {
  6116. tempIndex = gun_index;
  6117. }
  6118. for (int index = 0; index < AC_QUANTITY; index++)
  6119. {
  6120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6121. {
  6122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6123. }
  6124. }// End of for AC_QUANTITY
  6125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6126. }
  6127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6132. }
  6133. //============================ Voltage L2 ====================================
  6134. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6135. {
  6136. // AC 3 phse L2 voltage
  6137. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6138. {
  6139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6140. {
  6141. tempIndex = 2;
  6142. }
  6143. else
  6144. {
  6145. tempIndex = gun_index;
  6146. }
  6147. for (int index = 0; index < AC_QUANTITY; index++)
  6148. {
  6149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6150. {
  6151. 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
  6152. }
  6153. } // END OF FOR AC_QUANTITY
  6154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6155. }
  6156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6161. }
  6162. //============================ Voltage L3 ====================================
  6163. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6164. {
  6165. // AC 3 phse L3 voltage
  6166. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. 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
  6181. }
  6182. } // END OF FOR AC_QUANTITY
  6183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6190. }
  6191. //====================== Start SoC ================================
  6192. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6193. {
  6194. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6195. 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))
  6196. {
  6197. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6198. {
  6199. tempIndex = ((gun_index==2) ? 1: 0);
  6200. }
  6201. else
  6202. {
  6203. tempIndex = gun_index;
  6204. }
  6205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6206. {
  6207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6210. {
  6211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6212. }
  6213. }
  6214. }
  6215. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6216. {
  6217. for (int index = 0; index < CCS_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6220. {
  6221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6222. }
  6223. }
  6224. }
  6225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6226. {
  6227. for (int index = 0; index < GB_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6232. }
  6233. }
  6234. }
  6235. else if(gunType[gun_index] == GUN_TYPE_DO)
  6236. {
  6237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6240. {
  6241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6242. }
  6243. }
  6244. }
  6245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6251. } // END FOR DC CASE
  6252. }
  6253. //================================================ Message create ====================================================
  6254. json_object *StopTransaction = json_object_new_object();
  6255. json_object *transactionDatas = json_object_new_array();
  6256. json_object *sampledValues = json_object_new_array();
  6257. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6258. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6259. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6260. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6261. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6262. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6263. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6264. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6265. {
  6266. json_object *transactionData = json_object_new_object();
  6267. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6268. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6269. {
  6270. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6271. {
  6272. json_object *sampledValue = json_object_new_object();
  6273. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6274. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6275. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6276. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6277. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6278. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6279. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6280. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6281. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6282. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6283. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6284. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6285. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6286. json_object_array_add(sampledValues, sampledValue);
  6287. }
  6288. }
  6289. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6290. json_object_array_add(transactionDatas, transactionData);
  6291. }
  6292. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6293. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6294. ,MESSAGE_TYPE_CALL
  6295. ,guid
  6296. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6297. json_object_put(StopTransaction);
  6298. #if 1 // for TempStopTransaction
  6299. //Delete TempStopTransaction
  6300. if((access(TempStopTransaction,F_OK))!=-1)
  6301. {
  6302. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6303. }
  6304. #endif
  6305. #if 1
  6306. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6307. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6308. {
  6309. result = PASS;
  6310. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6311. }
  6312. #endif
  6313. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6314. OCPP_insert_transaction_msg(NO, queuedata);
  6315. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6316. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6317. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6318. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6319. {
  6320. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6321. }
  6322. //for test
  6323. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6324. return result;
  6325. }
  6326. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6327. {
  6328. mtrace();
  6329. int result = FAIL;
  6330. char guid[37]={0};
  6331. char tempdata[65]={0};
  6332. int tempIndex = 0;
  6333. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6334. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6335. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6336. //set value
  6337. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6338. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6339. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6340. -1);
  6341. random_uuid(guid);
  6342. //UTC Date time
  6343. struct timeval tmnow;
  6344. struct tm *tm;
  6345. char buf[28];//, usec_buf[6];
  6346. gettimeofday(&tmnow, NULL);
  6347. time_t t;
  6348. t = time(NULL);
  6349. /*UTC time and date*/
  6350. tm = gmtime(&t);
  6351. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6353. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6354. //********************************(1)Current.Import L1************************************************/
  6355. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6356. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6357. (dataType == ReadingContext_Trigger))
  6358. {
  6359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6361. {
  6362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6363. {
  6364. tempIndex = ((gun_index==2) ? 1: 0);
  6365. }
  6366. else
  6367. {
  6368. tempIndex = gun_index;
  6369. }
  6370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6375. }
  6376. }
  6377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < CCS_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6394. }
  6395. }
  6396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6397. }
  6398. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6399. {
  6400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6401. {
  6402. tempIndex = ((gun_index==2) ? 1: 0);
  6403. }
  6404. else
  6405. {
  6406. tempIndex = gun_index;
  6407. }
  6408. for (int index = 0; index < GB_QUANTITY; index++)
  6409. {
  6410. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6411. {
  6412. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6413. }
  6414. }
  6415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6416. }
  6417. else if(gunType[gun_index] == GUN_TYPE_DO)
  6418. {
  6419. tempIndex = gun_index;
  6420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6421. {
  6422. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6423. {
  6424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6428. }
  6429. else
  6430. {
  6431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6432. {
  6433. tempIndex = 2;
  6434. }
  6435. else
  6436. {
  6437. tempIndex = gun_index;
  6438. }
  6439. for (int index = 0; index < AC_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6444. }
  6445. }
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6447. }
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6453. }
  6454. //********************************(2)Energy.Active.Import.Register ************************************************/
  6455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6457. (dataType == ReadingContext_Trigger))
  6458. {
  6459. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6460. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6475. }
  6476. }
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < CCS_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6494. }
  6495. }
  6496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6497. }
  6498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6499. {
  6500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6501. {
  6502. tempIndex = ((gun_index==2) ? 1: 0);
  6503. }
  6504. else
  6505. {
  6506. tempIndex = gun_index;
  6507. }
  6508. for (int index = 0; index < GB_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6511. {
  6512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6513. }
  6514. }
  6515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6516. }
  6517. else if(gunType[gun_index] == GUN_TYPE_DO)
  6518. {
  6519. tempIndex = gun_index;
  6520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6525. }
  6526. }
  6527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6528. }
  6529. else
  6530. {
  6531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6532. {
  6533. tempIndex = 2;
  6534. }
  6535. else
  6536. {
  6537. tempIndex = gun_index;
  6538. }
  6539. for (int index = 0; index < AC_QUANTITY; index++)
  6540. {
  6541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6542. {
  6543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6544. }
  6545. }
  6546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6547. }
  6548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6553. }
  6554. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6555. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6556. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6557. (dataType == ReadingContext_Trigger))
  6558. {
  6559. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6560. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6561. {
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6563. {
  6564. tempIndex = ((gun_index==2) ? 1: 0);
  6565. }
  6566. else
  6567. {
  6568. tempIndex = gun_index;
  6569. }
  6570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6575. }
  6576. } // END OF FOR CHAdeMO_QUANTITY
  6577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6578. }
  6579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6580. {
  6581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6582. {
  6583. tempIndex = ((gun_index==2) ? 1: 0);
  6584. }
  6585. else
  6586. {
  6587. tempIndex = gun_index;
  6588. }
  6589. for (int index = 0; index < CCS_QUANTITY; index++)
  6590. {
  6591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6592. {
  6593. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6594. }
  6595. } // END OF CCS_QUANTITY
  6596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6597. }
  6598. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6599. {
  6600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6601. {
  6602. tempIndex = ((gun_index==2) ? 1: 0);
  6603. }
  6604. else
  6605. {
  6606. tempIndex = gun_index;
  6607. }
  6608. for (int index = 0; index < GB_QUANTITY; index++)
  6609. {
  6610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6611. {
  6612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6613. }
  6614. } // END OF GB_QUANTITY
  6615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6616. }
  6617. else if(gunType[gun_index] == GUN_TYPE_DO)
  6618. {
  6619. tempIndex = gun_index;
  6620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6621. {
  6622. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6623. {
  6624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6625. }
  6626. }
  6627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6628. }
  6629. else
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6632. {
  6633. tempIndex = 2;
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < AC_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6642. {
  6643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6644. }
  6645. }
  6646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6647. }
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6653. }
  6654. //********************************(4)Power.Active.Import************************************************/
  6655. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6656. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6657. (dataType == ReadingContext_Trigger))
  6658. {
  6659. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6660. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6663. {
  6664. tempIndex = ((gun_index==2) ? 1: 0);
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6673. {
  6674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6675. }
  6676. } // END OF FOR
  6677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6678. }
  6679. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6680. {
  6681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6682. {
  6683. tempIndex = ((gun_index==2) ? 1: 0);
  6684. }
  6685. else
  6686. {
  6687. tempIndex = gun_index;
  6688. }
  6689. for (int index = 0; index < CCS_QUANTITY; index++)
  6690. {
  6691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6692. {
  6693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6694. }
  6695. }
  6696. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6697. }
  6698. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6699. {
  6700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6701. {
  6702. tempIndex = ((gun_index==2) ? 1: 0);
  6703. }
  6704. else
  6705. {
  6706. tempIndex = gun_index;
  6707. }
  6708. for (int index = 0; index < GB_QUANTITY; index++)
  6709. {
  6710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6711. {
  6712. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6713. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6714. }
  6715. }
  6716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6717. }
  6718. else if(gunType[gun_index] == GUN_TYPE_DO)
  6719. {
  6720. tempIndex = gun_index;
  6721. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6722. {
  6723. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6724. {
  6725. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6727. }
  6728. }
  6729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6730. }
  6731. else
  6732. {
  6733. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6734. {
  6735. tempIndex = 2;
  6736. }
  6737. else
  6738. {
  6739. tempIndex = gun_index;
  6740. }
  6741. for (int index = 0; index < AC_QUANTITY; index++)
  6742. {
  6743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6744. {
  6745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6746. }
  6747. }
  6748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6749. }
  6750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6755. }
  6756. //***********************************************(5)VOLTAGE L1******************************************************/
  6757. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6758. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6759. (dataType == ReadingContext_Trigger))
  6760. {
  6761. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6762. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6763. {
  6764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6765. {
  6766. tempIndex = ((gun_index==2) ? 1: 0);
  6767. }
  6768. else
  6769. {
  6770. tempIndex = gun_index;
  6771. }
  6772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6775. {
  6776. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6777. }
  6778. }
  6779. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6780. }
  6781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6782. {
  6783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6784. {
  6785. tempIndex = ((gun_index==2) ? 1: 0);
  6786. }
  6787. else
  6788. {
  6789. tempIndex = gun_index;
  6790. }
  6791. for (int index = 0; index < CCS_QUANTITY; index++)
  6792. {
  6793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6794. {
  6795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6796. }
  6797. }
  6798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6799. }
  6800. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6801. {
  6802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6803. {
  6804. tempIndex = ((gun_index==2) ? 1: 0);
  6805. }
  6806. else
  6807. {
  6808. tempIndex = gun_index;
  6809. }
  6810. for (int index = 0; index < GB_QUANTITY; index++)
  6811. {
  6812. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6813. {
  6814. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6815. }
  6816. }
  6817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6818. }
  6819. else if(gunType[gun_index] == GUN_TYPE_DO)
  6820. {
  6821. tempIndex = gun_index;
  6822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6825. {
  6826. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6827. }
  6828. }
  6829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6830. }
  6831. else
  6832. {
  6833. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6834. {
  6835. tempIndex = 2;
  6836. }
  6837. else
  6838. {
  6839. tempIndex = gun_index;
  6840. }
  6841. for (int index = 0; index < AC_QUANTITY; index++)
  6842. {
  6843. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6844. {
  6845. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6846. }
  6847. }
  6848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6849. }
  6850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6855. }
  6856. //***********************************************(6)SOC******************************************************/
  6857. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6858. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6859. (dataType == ReadingContext_Trigger))
  6860. {
  6861. 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))
  6862. {
  6863. //idx_sample=5;
  6864. //sampledValue = NULL;
  6865. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6866. {
  6867. tempIndex = ((gun_index==2) ? 1: 0);
  6868. }
  6869. else
  6870. {
  6871. tempIndex = gun_index;
  6872. }
  6873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6874. {
  6875. //tempIndex = ((gun_index==2) ? 1: 0);
  6876. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6879. {
  6880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6881. }
  6882. }
  6883. }
  6884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6885. {
  6886. //tempIndex = ((gun_index==2) ? 1: 0);
  6887. for (int index = 0; index < CCS_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6890. {
  6891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6892. }
  6893. }
  6894. }
  6895. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6896. {
  6897. //tempIndex = ((gun_index==2) ? 1: 0);
  6898. for (int index = 0; index < GB_QUANTITY; index++)
  6899. {
  6900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6901. {
  6902. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6903. }
  6904. }
  6905. }
  6906. else if(gunType[gun_index] == GUN_TYPE_DO)
  6907. {
  6908. //tempIndex = ((gun_index==2) ? 1: 0);
  6909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6910. {
  6911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6912. {
  6913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6914. }
  6915. }
  6916. }
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6923. }
  6924. }
  6925. //********************************(7)Current.Import L2************************************************/
  6926. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6927. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6928. (dataType == ReadingContext_Trigger))
  6929. {
  6930. // Only for AC 3 phase
  6931. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6932. {
  6933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6934. {
  6935. tempIndex = 2;
  6936. }
  6937. else
  6938. {
  6939. tempIndex = gun_index;
  6940. }
  6941. for (int index = 0; index < AC_QUANTITY; index++)
  6942. {
  6943. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6944. {
  6945. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6946. }
  6947. }
  6948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6949. }
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6955. }
  6956. //********************************(8)Current.Import L3************************************************/
  6957. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6958. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6959. (dataType == ReadingContext_Trigger))
  6960. {
  6961. // Only for AC 3 phase
  6962. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6963. {
  6964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6965. {
  6966. tempIndex = 2;
  6967. }
  6968. else
  6969. {
  6970. tempIndex = gun_index;
  6971. }
  6972. for (int index = 0; index < AC_QUANTITY; index++)
  6973. {
  6974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6975. {
  6976. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6977. }
  6978. }
  6979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6980. }
  6981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6986. }
  6987. //***********************************************(9)VOLTAGE L2******************************************************/
  6988. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6989. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6990. (dataType == ReadingContext_Trigger))
  6991. {
  6992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6993. {
  6994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6995. {
  6996. tempIndex = 2;
  6997. }
  6998. else
  6999. {
  7000. tempIndex = gun_index;
  7001. }
  7002. for (int index = 0; index < AC_QUANTITY; index++)
  7003. {
  7004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7005. {
  7006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7007. }
  7008. }
  7009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7010. }
  7011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7016. }
  7017. //***********************************************(10)VOLTAGE L3******************************************************/
  7018. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7019. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7020. (dataType == ReadingContext_Trigger))
  7021. {
  7022. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7023. {
  7024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7025. {
  7026. tempIndex = 2;
  7027. }
  7028. else
  7029. {
  7030. tempIndex = gun_index;
  7031. }
  7032. for (int index = 0; index < AC_QUANTITY; index++)
  7033. {
  7034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7035. {
  7036. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7037. }
  7038. }
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7040. }
  7041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7046. }
  7047. //***********************************************(11)Current.Offered******************************************************/
  7048. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7049. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7050. (dataType == ReadingContext_Trigger))
  7051. {
  7052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7054. {
  7055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7056. {
  7057. tempIndex = ((gun_index==2) ? 1: 0);
  7058. }
  7059. else
  7060. {
  7061. tempIndex = gun_index;
  7062. }
  7063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7064. {
  7065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7068. }
  7069. } // END OF FOR CHAdeMO_QUANTITY
  7070. }
  7071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7072. {
  7073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7074. {
  7075. tempIndex = ((gun_index==2) ? 1: 0);
  7076. }
  7077. else
  7078. {
  7079. tempIndex = gun_index;
  7080. }
  7081. for (int index = 0; index < CCS_QUANTITY; index++)
  7082. {
  7083. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7086. }
  7087. } // END OF CCS_QUANTITY
  7088. }
  7089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7092. {
  7093. tempIndex = ((gun_index==2) ? 1: 0);
  7094. }
  7095. else
  7096. {
  7097. tempIndex = gun_index;
  7098. }
  7099. for (int index = 0; index < GB_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7102. {
  7103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7104. }
  7105. } // END OF GB_QUANTITY
  7106. }
  7107. else if(gunType[gun_index] == GUN_TYPE_DO)
  7108. {
  7109. tempIndex = gun_index;
  7110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7111. {
  7112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7113. {
  7114. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7115. }
  7116. }
  7117. }
  7118. else
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7121. {
  7122. tempIndex = 2;
  7123. }
  7124. else
  7125. {
  7126. tempIndex = gun_index;
  7127. }
  7128. for (int index = 0; index < AC_QUANTITY; index++)
  7129. {
  7130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7131. {
  7132. uint16_t currentOffer;
  7133. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7134. {
  7135. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7136. }
  7137. else
  7138. {
  7139. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7140. }
  7141. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7142. }
  7143. }
  7144. }
  7145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7150. }
  7151. //***********************************************(12)Power.Offered******************************************************/
  7152. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7153. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7154. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7155. {
  7156. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7157. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7158. {
  7159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7160. {
  7161. tempIndex = ((gun_index==2) ? 1: 0);
  7162. }
  7163. else
  7164. {
  7165. tempIndex = gun_index;
  7166. }
  7167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7168. {
  7169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7170. {
  7171. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7172. }
  7173. } // END OF FOR CHAdeMO_QUANTITY
  7174. }
  7175. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7176. {
  7177. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7178. {
  7179. tempIndex = ((gun_index==2) ? 1: 0);
  7180. }
  7181. else
  7182. {
  7183. tempIndex = gun_index;
  7184. }
  7185. for (int index = 0; index < CCS_QUANTITY; index++)
  7186. {
  7187. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7188. {
  7189. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7190. }
  7191. } // END OF CCS_QUANTITY
  7192. }
  7193. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7194. {
  7195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7196. {
  7197. tempIndex = ((gun_index==2) ? 1: 0);
  7198. }
  7199. else
  7200. {
  7201. tempIndex = gun_index;
  7202. }
  7203. for (int index = 0; index < GB_QUANTITY; index++)
  7204. {
  7205. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7206. {
  7207. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7208. }
  7209. } // END OF GB_QUANTITY
  7210. }
  7211. else if(gunType[gun_index] == GUN_TYPE_DO)
  7212. {
  7213. tempIndex = gun_index;
  7214. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7215. {
  7216. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7217. {
  7218. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7219. }
  7220. }
  7221. }
  7222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7227. }
  7228. // Message create ====================================================================================================
  7229. if(TRUE)
  7230. {
  7231. json_object *MeterValueReq = json_object_new_object();
  7232. json_object *MeterValues = json_object_new_array();
  7233. json_object *sampledValues = json_object_new_array();
  7234. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7235. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7236. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7237. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7238. {
  7239. json_object *MeterValue = json_object_new_object();
  7240. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7241. {
  7242. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7243. {
  7244. json_object *sampledValue = json_object_new_object();
  7245. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7246. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7247. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7248. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7249. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7250. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7251. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7252. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7253. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7254. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7255. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7256. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7257. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7258. json_object_array_add(sampledValues, sampledValue);
  7259. }
  7260. }
  7261. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7262. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7263. json_object_array_add(MeterValues, MeterValue);
  7264. }
  7265. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7266. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7267. ,gun_index + 1
  7268. ,MESSAGE_TYPE_CALL
  7269. ,guid
  7270. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7271. json_object_put(MeterValueReq);
  7272. }
  7273. // Put request guid to hash map
  7274. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7275. 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*/)
  7276. {
  7277. result = PASS;
  7278. //DEBUG_INFO("MeterValues mapitem pass\n");
  7279. }
  7280. if((dataType != ReadingContext_Trigger) &&
  7281. (dataType != ReadingContext_Sample_Clock) &&
  7282. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7283. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7284. else
  7285. {
  7286. if(FirstHeartBeat)
  7287. LWS_Send(queuedata +2);
  7288. }
  7289. return result;
  7290. }
  7291. int sendLogStatusNotificationRequest(char *status)
  7292. {
  7293. mtrace();
  7294. int result = PASS;
  7295. char message[4096]={0};
  7296. char guid[37]={0};
  7297. char tempdata[128]={0};
  7298. json_object *LogStatusNotification = json_object_new_object();
  7299. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7300. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7301. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7302. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7303. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7304. random_uuid(guid);
  7305. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7306. json_object_put(LogStatusNotification);
  7307. LWS_Send(message);
  7308. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7309. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7310. {
  7311. result = PASS;
  7312. }
  7313. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7314. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7315. return result;
  7316. }
  7317. int sendSecurityEventNotificationRequest()
  7318. {
  7319. mtrace();
  7320. int result = PASS;
  7321. char message[4096]={0};
  7322. char guid[37]={0};
  7323. char tempdata[128]={0};
  7324. json_object *SecurityEventNotification = json_object_new_object();
  7325. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7326. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7327. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7328. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7329. random_uuid(guid);
  7330. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7331. json_object_put(SecurityEventNotification);
  7332. LWS_Send(message);
  7333. sprintf(tempdata, "SecurityEventNotification,0");
  7334. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7335. {
  7336. result = PASS;
  7337. }
  7338. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7339. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7340. return result;
  7341. }
  7342. int sendSignCertificateRequest()
  7343. {
  7344. mtrace();
  7345. int result = PASS;
  7346. char message[4096]={0};
  7347. char guid[37]={0};
  7348. char tempdata[128]={0};
  7349. json_object *SignCertificate = json_object_new_object();
  7350. DEBUG_INFO("sendSignCertificateRequest...\n");
  7351. // Read csr file content
  7352. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7353. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7354. char *line = NULL;
  7355. size_t len = 0;
  7356. while(getline(&line, &len, fp) != -1)
  7357. {
  7358. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7359. {
  7360. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7361. }
  7362. }
  7363. fclose(fp);
  7364. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7365. random_uuid(guid);
  7366. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7367. json_object_put(SignCertificate);
  7368. LWS_Send(message);
  7369. sprintf(tempdata, "SignCertificate,0");
  7370. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7371. {
  7372. result = PASS;
  7373. }
  7374. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7375. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7376. return result;
  7377. }
  7378. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7379. {
  7380. mtrace();
  7381. int result = PASS;
  7382. char message[110]={0};
  7383. char guid[37]={0};
  7384. char tempdata[65]={0};
  7385. json_object *FirmwareStatusNotification = json_object_new_object();
  7386. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7387. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7388. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7389. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7390. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7391. random_uuid(guid);
  7392. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7393. json_object_put(FirmwareStatusNotification);
  7394. LWS_Send(message);
  7395. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7396. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7397. {
  7398. result = PASS;
  7399. }
  7400. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7401. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7402. return result;
  7403. }
  7404. //==========================================
  7405. // send confirm routine
  7406. //==========================================
  7407. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7408. {
  7409. mtrace();
  7410. int result = FAIL;
  7411. char message[100]={0};
  7412. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7413. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7414. LWS_Send(message);
  7415. result = TRUE;
  7416. return result;
  7417. }
  7418. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7419. {
  7420. mtrace();
  7421. int result = FAIL;
  7422. char message[100]={0};
  7423. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7425. LWS_Send(message);
  7426. result = TRUE;
  7427. return result;
  7428. }
  7429. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7430. {
  7431. mtrace();
  7432. int result = FAIL;
  7433. char message[100]={0};
  7434. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7436. LWS_Send(message);
  7437. result = TRUE;
  7438. return result;
  7439. }
  7440. int sendClearCacheConfirmation(char *uuid,char *payload)
  7441. {
  7442. mtrace();
  7443. int result = FAIL;
  7444. char message[500]={0};
  7445. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7446. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7447. LWS_Send(message);
  7448. return result;
  7449. }
  7450. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7451. {
  7452. mtrace();
  7453. int result = FAIL;
  7454. char message[500]={0};
  7455. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7456. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7457. LWS_Send(message);
  7458. return result;
  7459. }
  7460. int sendDataTransferConfirmation(char *uuid,char *payload)
  7461. {
  7462. mtrace();
  7463. char statusStr[20]={0};
  7464. char dataStr[10]={0};
  7465. char sstr[20]={0};
  7466. int c = 0;
  7467. char *loc;
  7468. int result = FAIL;
  7469. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7470. /**********************status**************************/
  7471. loc = strstr(payload, "status");
  7472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7473. c = 0;
  7474. while (loc[3+strlen("status")+c] != '\"')
  7475. {
  7476. sstr[c] = loc[3+strlen("status")+c];
  7477. c++;
  7478. }
  7479. sstr[c] = '\0';
  7480. strcpy(statusStr, sstr);
  7481. /**********************data**************************/
  7482. loc = strstr(payload, "data");
  7483. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7484. c = 0;
  7485. while (loc[3+strlen("data")+c] != '\"')
  7486. {
  7487. sstr[c] = loc[3+strlen("data")+c];
  7488. c++;
  7489. }
  7490. sstr[c] = '\0';
  7491. strcpy(dataStr, sstr);
  7492. return result;
  7493. }
  7494. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7495. {
  7496. mtrace();
  7497. int result = FAIL;
  7498. char message[1000]={0};
  7499. int CompositeScheduleIndex = 0;
  7500. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7501. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7502. if(nPeriod == 0)
  7503. {
  7504. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7505. {
  7506. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7507. ,MESSAGE_TYPE_CALLRESULT
  7508. ,uuid
  7509. ,payload
  7510. ,connectorIdInt);
  7511. }
  7512. else
  7513. {
  7514. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7515. ,MESSAGE_TYPE_CALLRESULT
  7516. ,uuid
  7517. ,payload
  7518. ,connectorIdInt
  7519. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7520. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7521. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7522. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7523. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7524. }
  7525. }
  7526. else
  7527. {
  7528. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7529. ,MESSAGE_TYPE_CALLRESULT
  7530. ,uuid
  7531. ,payload
  7532. ,connectorIdInt
  7533. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7534. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7535. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7536. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7537. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7538. {
  7539. if (idx_sample == 0)
  7540. {
  7541. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7542. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7543. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7544. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7545. }
  7546. else
  7547. {
  7548. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7549. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7551. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7552. }
  7553. }
  7554. sprintf(message + strlen(message), "]}}]");
  7555. }
  7556. LWS_Send(message);
  7557. result = TRUE;
  7558. return result;
  7559. }
  7560. int sendGetConfigurationConfirmation(char *uuid)
  7561. {
  7562. mtrace();
  7563. int result = FAIL;
  7564. int MaxKeySupported = 0;
  7565. int sentConfigurationNumber= 0;
  7566. int sentunConfigurationNumber= 0;
  7567. char message[1024*10]={0};
  7568. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7569. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7570. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7571. ,MESSAGE_TYPE_CALLRESULT
  7572. ,uuid );
  7573. //configuration key
  7574. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7575. {
  7576. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7577. {
  7578. if (sentConfigurationNumber == 0)
  7579. {
  7580. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7581. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7582. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7583. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7584. }
  7585. else
  7586. {
  7587. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7588. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7589. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7590. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7591. }
  7592. sentConfigurationNumber = sentConfigurationNumber + 1;
  7593. }
  7594. }
  7595. sprintf(message + strlen(message), "]");
  7596. if(UnknownKeynum != 0)
  7597. {
  7598. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7599. //unkown key
  7600. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7601. {
  7602. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7603. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7604. if(sentunConfigurationNumber == 0)
  7605. {
  7606. sprintf(message + strlen(message), "\"%s\""
  7607. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7608. }
  7609. else
  7610. {
  7611. sprintf(message + strlen(message), ",\"%s\""
  7612. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7613. }
  7614. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7615. }
  7616. sprintf(message + strlen(message), "]");
  7617. }
  7618. sprintf(message + strlen(message), "}]");
  7619. LWS_Send(message);
  7620. return result;
  7621. }
  7622. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7623. {
  7624. mtrace();
  7625. int result = FAIL;
  7626. char message[400]={0};
  7627. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7628. if(strcmp(payload,"")==0)
  7629. {
  7630. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7631. }
  7632. else
  7633. {
  7634. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7635. }
  7636. LWS_Send(message);
  7637. result = TRUE;
  7638. return result;
  7639. }
  7640. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7641. {
  7642. mtrace();
  7643. int result = FAIL;
  7644. char message[80]={0};
  7645. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7646. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7647. LWS_Send(message);
  7648. result = TRUE;
  7649. return result;
  7650. }
  7651. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7652. {
  7653. mtrace();
  7654. int result = FAIL;
  7655. char message[80]={0};
  7656. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7657. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7658. LWS_Send(message);
  7659. result = TRUE;
  7660. return result;
  7661. }
  7662. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7663. {
  7664. mtrace();
  7665. int result = FAIL;
  7666. char message[80]={0};
  7667. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7668. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7669. LWS_Send(message);
  7670. result = TRUE;
  7671. return result;
  7672. }
  7673. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7674. {
  7675. mtrace();
  7676. int result = FAIL;
  7677. char message[80]={0};
  7678. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7679. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7680. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7681. LWS_Send(message);
  7682. result = TRUE;
  7683. return result;
  7684. }
  7685. int sendResetConfirmation(char *uuid,char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7690. char message[80]={0};
  7691. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7692. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7693. LWS_Send(message);
  7694. result = TRUE;
  7695. return result;
  7696. }
  7697. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7698. {
  7699. mtrace();
  7700. int result = FAIL;
  7701. char message[500]={0};
  7702. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7703. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7704. LWS_Send(message);
  7705. result = TRUE;
  7706. return result;
  7707. }
  7708. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7709. {
  7710. mtrace();
  7711. int result = FAIL;
  7712. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7713. char message[80]={0};
  7714. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7715. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7716. LWS_Send(message);
  7717. result = TRUE;
  7718. return result;
  7719. }
  7720. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7721. {
  7722. mtrace();
  7723. int result = FAIL;
  7724. char message[80]={0};
  7725. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7726. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7727. LWS_Send(message);
  7728. result = TRUE;
  7729. return result;
  7730. }
  7731. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7732. {
  7733. mtrace();
  7734. int result = FAIL;
  7735. char message[80]={0};
  7736. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7737. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7738. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7739. LWS_Send(message);
  7740. result = TRUE;
  7741. return result;
  7742. }
  7743. int sendUpdateFirmwareConfirmation(char *uuid)
  7744. {
  7745. mtrace();
  7746. int result = FAIL;
  7747. char message[60]={0};
  7748. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7749. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7750. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7751. LWS_Send(message);
  7752. result = TRUE;
  7753. return result;
  7754. }
  7755. int sendCertificateSignedConfirmation(char *uuid)
  7756. {
  7757. mtrace();
  7758. int result = PASS;
  7759. char message[4096]={0};
  7760. json_object *CertificateSigned = json_object_new_object();
  7761. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7762. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7763. sprintf(message,"[%d,\"%s\",%s]"
  7764. ,MESSAGE_TYPE_CALLRESULT
  7765. ,uuid
  7766. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7767. json_object_put(CertificateSigned);
  7768. LWS_Send(message);
  7769. return result;
  7770. }
  7771. int sendDeleteCertificateConfirmation(char *uuid)
  7772. {
  7773. mtrace();
  7774. int result = PASS;
  7775. char message[4096]={0};
  7776. json_object *DeleteCertificate = json_object_new_object();
  7777. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7778. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7779. sprintf(message,"[%d,\"%s\",%s]"
  7780. ,MESSAGE_TYPE_CALLRESULT
  7781. ,uuid
  7782. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7783. json_object_put(DeleteCertificate);
  7784. LWS_Send(message);
  7785. return result;
  7786. }
  7787. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7788. {
  7789. mtrace();
  7790. int result = PASS;
  7791. char message[4096]={0};
  7792. json_object *ExtendedTriggerMessage = json_object_new_object();
  7793. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7794. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7795. sprintf(message,"[%d,\"%s\",%s]"
  7796. ,MESSAGE_TYPE_CALLRESULT
  7797. ,uuid
  7798. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7799. json_object_put(ExtendedTriggerMessage);
  7800. LWS_Send(message);
  7801. return result;
  7802. }
  7803. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7804. {
  7805. mtrace();
  7806. int result = PASS;
  7807. char message[4096]={0};
  7808. json_object *GetInstalledCertificateIds = json_object_new_object();
  7809. json_object *certificateHashDataDatas = json_object_new_array();
  7810. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7811. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7812. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7813. {
  7814. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7815. {
  7816. json_object *certificateHashData = json_object_new_object();
  7817. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7818. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7819. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7820. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7821. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7822. }
  7823. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7824. }
  7825. else
  7826. {
  7827. json_object_put(certificateHashDataDatas);
  7828. }
  7829. sprintf(message,"[%d,\"%s\",%s]"
  7830. ,MESSAGE_TYPE_CALLRESULT
  7831. ,uuid
  7832. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7833. json_object_put(GetInstalledCertificateIds);
  7834. LWS_Send(message);
  7835. return result;
  7836. }
  7837. int sendGetLogConfirmation(char *uuid)
  7838. {
  7839. mtrace();
  7840. int result = PASS;
  7841. char message[4096]={0};
  7842. json_object *GetLog = json_object_new_object();
  7843. DEBUG_INFO("sendGetLogConfirmation...\n");
  7844. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7845. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7846. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7847. sprintf(message,"[%d,\"%s\",%s]"
  7848. ,MESSAGE_TYPE_CALLRESULT
  7849. ,uuid
  7850. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7851. json_object_put(GetLog);
  7852. LWS_Send(message);
  7853. return result;
  7854. }
  7855. int sendInstallCertificateConfirmation(char *uuid)
  7856. {
  7857. mtrace();
  7858. int result = PASS;
  7859. char message[4096]={0};
  7860. json_object *InstallCertificate = json_object_new_object();
  7861. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7862. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7863. sprintf(message,"[%d,\"%s\",%s]"
  7864. ,MESSAGE_TYPE_CALLRESULT
  7865. ,uuid
  7866. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7867. json_object_put(InstallCertificate);
  7868. LWS_Send(message);
  7869. return result;
  7870. }
  7871. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7872. {
  7873. mtrace();
  7874. int result = PASS;
  7875. char message[4096]={0};
  7876. json_object *SignedUpdateFirmware = json_object_new_object();
  7877. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7878. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7879. sprintf(message,"[%d,\"%s\",%s]"
  7880. ,MESSAGE_TYPE_CALLRESULT
  7881. ,uuid
  7882. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7883. json_object_put(SignedUpdateFirmware);
  7884. LWS_Send(message);
  7885. return result;
  7886. }
  7887. int sendUnknownConfirmation(char *uuid)
  7888. {
  7889. mtrace();
  7890. int result = PASS;
  7891. char message[256]={0};
  7892. DEBUG_INFO("sendUnknownConfirmation...\n");
  7893. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7894. LWS_Send(message);
  7895. return result;
  7896. }
  7897. //==========================================
  7898. // Handle server request routine Start
  7899. //==========================================
  7900. int handleCancelReservationRequest(char *uuid, char *payload)
  7901. {
  7902. mtrace();
  7903. int result = FAIL;
  7904. int gunNO = 0;
  7905. int reservationIdInt = -1;
  7906. char comfirmstr[20];
  7907. DEBUG_INFO("handleCancelReservationRequest...\n");
  7908. json_object *CancelReservation;
  7909. CancelReservation = json_tokener_parse(payload);
  7910. if(!is_error(CancelReservation))
  7911. {
  7912. // Required data
  7913. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7914. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7915. }
  7916. json_object_put(CancelReservation);
  7917. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7918. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7919. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7920. if(reservationIdInt != -1)
  7921. {
  7922. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7923. //check Transaction active
  7924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7925. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7926. {
  7927. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7928. {
  7929. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7930. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7931. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7932. {
  7933. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7934. }
  7935. else
  7936. {
  7937. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7938. }
  7939. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7940. goto end;
  7941. }
  7942. }
  7943. for (int index = 0; index < CCS_QUANTITY; index++)
  7944. {
  7945. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7946. {
  7947. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7948. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7949. if(gunType[2] == GUN_TYPE_CCS)
  7950. {
  7951. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7952. }
  7953. else
  7954. {
  7955. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7956. }
  7957. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7958. goto end;
  7959. }
  7960. }
  7961. for (int index = 0; index < GB_QUANTITY; index++)
  7962. {
  7963. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7964. {
  7965. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7966. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7967. if(gunType[2] == GUN_TYPE_GBT)
  7968. {
  7969. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7970. }
  7971. else
  7972. {
  7973. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7974. }
  7975. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7976. goto end;
  7977. }
  7978. }
  7979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7980. {
  7981. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7982. {
  7983. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7984. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7985. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7986. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7987. goto end;
  7988. }
  7989. }
  7990. for (int index = 0; index < AC_QUANTITY; index++)
  7991. {
  7992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7993. {
  7994. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7995. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7997. {
  7998. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7999. }
  8000. else
  8001. {
  8002. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8003. }
  8004. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8005. goto end;
  8006. }
  8007. }
  8008. }
  8009. //The reservationId does NOT match the reservationId
  8010. sendCancelReservationConfirmation(uuid, comfirmstr);
  8011. end:
  8012. // Fill in ocpp packet uuid
  8013. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8014. return result;
  8015. }
  8016. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8017. {
  8018. mtrace();
  8019. int result = FAIL;
  8020. int gunIndex = -1;
  8021. char typeStr[16]={0};
  8022. char comfirmstr[20];
  8023. int specificId = FALSE;
  8024. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8025. json_object *ChangeAvailability;
  8026. ChangeAvailability = json_tokener_parse(payload);
  8027. if(!is_error(ChangeAvailability))
  8028. {
  8029. // Required data
  8030. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8031. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8032. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8033. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8034. }
  8035. json_object_put(ChangeAvailability);
  8036. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8037. {
  8038. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8039. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8040. }
  8041. else if(gunIndex == 0)
  8042. {
  8043. for(int i=0; i < gunTotalNumber; i++)
  8044. {
  8045. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8046. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8047. }
  8048. }
  8049. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8051. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8052. {
  8053. specificId = TRUE;
  8054. }
  8055. if(specificId == FALSE)
  8056. goto end;
  8057. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8058. {
  8059. //----------------------gunIndex is 0 ------------------------------------------------//
  8060. if(gunIndex == 0)
  8061. {
  8062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8063. {
  8064. for(int i=0; i < gunTotalNumber; i++)
  8065. {
  8066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8067. {
  8068. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8069. {
  8070. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8071. {
  8072. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8073. goto end;
  8074. }
  8075. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8076. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8078. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8079. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8080. {
  8081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8082. goto end;
  8083. }
  8084. }
  8085. }//END FOR CHAdeMO_QUANTITY
  8086. for (int index = 0; index < CCS_QUANTITY; index++)
  8087. {
  8088. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8089. {
  8090. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8091. {
  8092. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8093. goto end;
  8094. }
  8095. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8096. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8097. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8098. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8100. {
  8101. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8102. goto end;
  8103. }
  8104. }
  8105. }//END FOR CCS_QUANTITY
  8106. for (int index = 0; index < GB_QUANTITY; index++)
  8107. {
  8108. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8109. {
  8110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8111. {
  8112. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8113. goto end;
  8114. }
  8115. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8116. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8118. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8119. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8120. {
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8122. goto end;
  8123. }
  8124. }
  8125. }// END FOR GB_QUANTITY
  8126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8127. {
  8128. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8129. {
  8130. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8131. {
  8132. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8133. goto end;
  8134. }
  8135. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8140. {
  8141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8142. goto end;
  8143. }
  8144. }
  8145. }// END FOR GENERAL_GUN_QUANTITY
  8146. for (int index = 0; index < AC_QUANTITY; index++)
  8147. {
  8148. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8149. {
  8150. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8151. {
  8152. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8153. goto end;
  8154. }
  8155. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8156. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8160. {
  8161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8162. goto end;
  8163. }
  8164. }
  8165. }//END FOR AC_QUANTITY
  8166. }// END FOR gunTotalNumber
  8167. }
  8168. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8169. {
  8170. for(int i=0; i < gunTotalNumber; i++)
  8171. {
  8172. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8173. {
  8174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8175. goto end;
  8176. }
  8177. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8178. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8181. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8182. {
  8183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8184. goto end;
  8185. }
  8186. }
  8187. }
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8189. goto end;
  8190. }
  8191. //----------------------gunIndex is not 0 ------------------------------------------------//
  8192. //check Transaction active
  8193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8194. {
  8195. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8196. {
  8197. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8198. {
  8199. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8200. goto end;
  8201. }
  8202. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8203. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8207. {
  8208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8209. goto end;
  8210. }
  8211. else
  8212. {
  8213. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8215. goto end;
  8216. }
  8217. }
  8218. }//END FOR CHAdeMO_QUANTITY
  8219. for (int index = 0; index < CCS_QUANTITY; index++)
  8220. {
  8221. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8222. {
  8223. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8224. {
  8225. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8226. goto end;
  8227. }
  8228. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8229. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8231. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8232. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8233. {
  8234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8235. goto end;
  8236. }
  8237. else
  8238. {
  8239. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8241. goto end;
  8242. }
  8243. }
  8244. }//END FOR CCS_QUANTITY
  8245. for (int index = 0; index < GB_QUANTITY; index++)
  8246. {
  8247. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8248. {
  8249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8250. {
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8252. goto end;
  8253. }
  8254. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8255. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8256. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8257. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8258. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8259. {
  8260. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8261. goto end;
  8262. }
  8263. else
  8264. {
  8265. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8266. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8267. goto end;
  8268. }
  8269. }
  8270. }// END FOR GB_QUANTITY
  8271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8272. {
  8273. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8274. {
  8275. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8276. {
  8277. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8278. goto end;
  8279. }
  8280. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8281. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8282. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8283. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8284. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8285. {
  8286. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8287. goto end;
  8288. }
  8289. else
  8290. {
  8291. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8292. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8293. goto end;
  8294. }
  8295. }
  8296. }// END FOR GENERAL_GUN_QUANTITY
  8297. for (int index = 0; index < AC_QUANTITY; index++)
  8298. {
  8299. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8300. {
  8301. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8302. {
  8303. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8304. goto end;
  8305. }
  8306. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8307. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8308. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8309. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8310. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8311. {
  8312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8313. goto end;
  8314. }
  8315. else
  8316. {
  8317. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8318. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8319. goto end;
  8320. }
  8321. }
  8322. }//END FOR AC_QUANTITY
  8323. }//END FOR AvailabilityTypeStr[Inoperative]
  8324. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8325. {
  8326. //----------------------gunIndex is 0 ------------------------------------------------//
  8327. if(gunIndex == 0)
  8328. {
  8329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8330. {
  8331. for(int i=0; i < gunTotalNumber; i++)
  8332. {
  8333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8334. {
  8335. 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
  8336. {
  8337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8338. goto end;
  8339. }
  8340. }//END FOR CHAdeMO_QUANTITY
  8341. for (int index = 0; index < CCS_QUANTITY; index++)
  8342. {
  8343. 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
  8344. {
  8345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8346. goto end;
  8347. }
  8348. }//END FOR CCS_QUANTITY
  8349. for (int index = 0; index < GB_QUANTITY; index++)
  8350. {
  8351. 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
  8352. {
  8353. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8355. goto end;
  8356. }
  8357. }// END FOR GB_QUANTITY
  8358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8359. {
  8360. 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
  8361. {
  8362. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8364. goto end;
  8365. }
  8366. }// END FOR GENERAL_GUN_QUANTITY
  8367. for (int index = 0; index < AC_QUANTITY; index++)
  8368. {
  8369. 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
  8370. {
  8371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8372. goto end;
  8373. }
  8374. }//END FOR CHAdeMO_QUANTITY
  8375. }// END FOR gunTotalNumber
  8376. }
  8377. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8378. {
  8379. for(int i=0; i < gunTotalNumber; i++)
  8380. {
  8381. for (int index = 0; index < AC_QUANTITY; index++)
  8382. {
  8383. 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
  8384. {
  8385. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8386. goto end;
  8387. }
  8388. }//END FOR CHAdeMO_QUANTITY
  8389. } // END FOR gunTotalNumber
  8390. }
  8391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8392. goto end;
  8393. }
  8394. //----------------------gunIndex is not 0 ------------------------------------------------//
  8395. //check Transaction active
  8396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8397. {
  8398. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8399. {
  8400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8401. goto end;
  8402. }
  8403. }//END FOR CHAdeMO_QUANTITY
  8404. for (int index = 0; index < CCS_QUANTITY; index++)
  8405. {
  8406. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8407. {
  8408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8409. goto end;
  8410. }
  8411. }//END FOR CCS_QUANTITY
  8412. for (int index = 0; index < GB_QUANTITY; index++)
  8413. {
  8414. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8415. {
  8416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8417. goto end;
  8418. }
  8419. }// END FOR GB_QUANTITY
  8420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8421. {
  8422. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8423. {
  8424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8425. goto end;
  8426. }
  8427. }// END FOR GENERAL_GUN_QUANTITY
  8428. for (int index = 0; index < AC_QUANTITY; index++)
  8429. {
  8430. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8431. {
  8432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8433. goto end;
  8434. }
  8435. }//END FOR AC_QUANTITY
  8436. }//END FOR AvailabilityTypeStr[Operative]
  8437. end:
  8438. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8439. {
  8440. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8441. }
  8442. else
  8443. {
  8444. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8445. }
  8446. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8447. {
  8448. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8449. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8450. }
  8451. else if(gunIndex == 0)
  8452. {
  8453. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8454. {
  8455. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8456. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8457. }
  8458. }
  8459. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8460. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8461. return result;
  8462. }
  8463. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8464. {
  8465. mtrace();
  8466. int valueInvalid = NO;
  8467. int result = FAIL;
  8468. char keystr[40]={0};
  8469. char valuestr[501]={0}; //value should be limited in 500 bytes
  8470. char comfirmstr[20]={0};
  8471. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8472. json_object *ChangeConfiguration;
  8473. ChangeConfiguration = json_tokener_parse(payload);
  8474. if(!is_error(ChangeConfiguration))
  8475. {
  8476. // Required data
  8477. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8478. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8479. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8480. {
  8481. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8482. }
  8483. else
  8484. {
  8485. valueInvalid = YES;
  8486. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8487. }
  8488. }
  8489. json_object_put(ChangeConfiguration);
  8490. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8491. {
  8492. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8493. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8494. }
  8495. else
  8496. {
  8497. int status = setKeyValue(keystr, valuestr);
  8498. switch(status)
  8499. {
  8500. case ConfigurationStatus_Accepted:
  8501. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8502. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8503. StoreConfigurationTable();
  8504. break;
  8505. case RebootRequired:
  8506. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8507. StoreConfigurationTable();
  8508. break;
  8509. case NotSupported:
  8510. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8511. break;
  8512. case ConfigurationStatus_Rejected:
  8513. default:
  8514. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8515. break;
  8516. }
  8517. }
  8518. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8519. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8520. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8521. {
  8522. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8523. SetOcppConnStatus(FALSE);
  8524. }
  8525. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8526. {
  8527. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8528. }
  8529. return result;
  8530. }
  8531. int handleClearCacheRequest(char *uuid, char *payload)
  8532. {
  8533. mtrace();
  8534. int result = FAIL;
  8535. char comfirmstr[20];
  8536. char rmFileCmd[100]={0};
  8537. struct stat stats;
  8538. DEBUG_INFO("handleClearCacheRequest...\n");
  8539. stat("/Storage/OCPP", &stats);
  8540. // Check for directory existence
  8541. if (S_ISDIR(stats.st_mode) == 1)
  8542. {}
  8543. else
  8544. {
  8545. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8546. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8547. system(rmFileCmd);
  8548. }
  8549. if(OCPP_cleanLocalCache())
  8550. {
  8551. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8552. }
  8553. else
  8554. {
  8555. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8556. }
  8557. sendClearCacheConfirmation(uuid, comfirmstr);
  8558. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8559. return result;
  8560. }
  8561. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8562. {
  8563. mtrace();
  8564. int result = FAIL;
  8565. int resultRename;
  8566. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8567. char chargingProfilePurposeStr[26]={0};
  8568. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8569. char tempchargingProfilePurposeStr[26]={0};
  8570. char str[100]={0};
  8571. char fname[200]={0};
  8572. char comfirmstr[20]={0};
  8573. char word[1600]={0};
  8574. int clearflag = FALSE;
  8575. int chargingProfileIdIsNULL = FALSE;
  8576. int connectorIsNULL = FALSE;
  8577. int chargingProfilePurposeIsNULL = FALSE;
  8578. int stackLevelIsNULL = FALSE;
  8579. //int GotoEnd = FALSE;
  8580. FILE *fptr1, *fptr2;
  8581. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8582. int n_chargingProfile=0;
  8583. int isEmptyFile = FALSE;
  8584. char sLineWord[1600]={0};
  8585. char chargingProfiles[10][100]={0};
  8586. int ChargeProfileCount = 0;
  8587. int ch;
  8588. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8589. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8590. json_object *ClearChargingProfile;
  8591. ClearChargingProfile = json_tokener_parse(payload);
  8592. if(!is_error(ClearChargingProfile))
  8593. {
  8594. // Optional data
  8595. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8596. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8597. else
  8598. chargingProfileIdIsNULL = TRUE;
  8599. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8600. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8601. else
  8602. connectorIsNULL = TRUE;
  8603. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8604. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8605. else
  8606. chargingProfilePurposeIsNULL = TRUE;
  8607. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8608. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8609. else
  8610. stackLevelIsNULL = TRUE;
  8611. }
  8612. json_object_put(ClearChargingProfile);
  8613. if(connectorIsNULL == FALSE)
  8614. {
  8615. switch(connectorIdInt)
  8616. {
  8617. case 0:
  8618. if(chargingProfilePurposeIsNULL == TRUE)
  8619. {
  8620. int l = 0;
  8621. strcpy(fname, ChargePointMaxProfile_JSON);
  8622. if((access(fname,F_OK))!=-1)
  8623. {
  8624. strcpy(chargingProfiles[l], fname);
  8625. l = l + 1;
  8626. }
  8627. strcpy(fname, TxDefaultProfile_0_JSON);
  8628. if((access(fname,F_OK))!=-1)
  8629. {
  8630. strcpy(chargingProfiles[l], fname);
  8631. l = l + 1;
  8632. }
  8633. ChargeProfileCount = l;
  8634. }
  8635. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8636. {
  8637. strcpy(fname, ChargePointMaxProfile_JSON);
  8638. if((access(fname,F_OK))!=-1)
  8639. {
  8640. strcpy(chargingProfiles[0], fname);
  8641. ChargeProfileCount = 1;
  8642. }
  8643. }
  8644. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8645. {
  8646. strcpy(fname, TxDefaultProfile_0_JSON);
  8647. if((access(fname,F_OK))!=-1)
  8648. {
  8649. strcpy(chargingProfiles[0], fname);
  8650. ChargeProfileCount = 1;
  8651. }
  8652. }
  8653. break;
  8654. default:
  8655. if(chargingProfilePurposeIsNULL == TRUE)
  8656. {
  8657. int m = 0;
  8658. memset(fname, 0, ARRAY_SIZE(fname));
  8659. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8660. if((access(fname,F_OK))!=-1)
  8661. {
  8662. strcpy(chargingProfiles[m], fname);
  8663. m = m + 1;
  8664. }
  8665. memset(fname, 0, ARRAY_SIZE(fname));
  8666. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8667. if((access(fname,F_OK))!=-1)
  8668. {
  8669. strcpy(chargingProfiles[m], fname);
  8670. m = m + 1;
  8671. }
  8672. ChargeProfileCount = m;
  8673. }
  8674. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8675. {
  8676. //strcpy(fname, TxDefaultProfile_1_JSON);
  8677. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8678. if((access(fname,F_OK))!=-1)
  8679. {
  8680. strcpy(chargingProfiles[0], fname);
  8681. ChargeProfileCount = 1;
  8682. }
  8683. }
  8684. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8685. {
  8686. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8687. if((access(fname,F_OK))!=-1)
  8688. {
  8689. strcpy(chargingProfiles[0], fname);
  8690. ChargeProfileCount = 1;
  8691. }
  8692. //strcpy(fname, TxProfile_1_JSON);
  8693. }
  8694. //strcpy(fname, ChargePointMaxProfile_JSON );
  8695. break;
  8696. }
  8697. }
  8698. else // Check all Charging Profiles
  8699. {
  8700. int i = 0;
  8701. char fnametemp[200]={0};
  8702. ChargeProfileCount = 0;
  8703. //Check ChargePointMaxProfile.json exit
  8704. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8705. {
  8706. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8707. i = i + 1;
  8708. }
  8709. //Check TxDefaultProfile_0.json exit
  8710. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8711. {
  8712. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8713. i = i + 1;
  8714. }
  8715. //Check TxDefaultProfile_%d.json
  8716. for(int j=1; j <= gunTotalNumber; j++)
  8717. {
  8718. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8719. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8720. if((access(fnametemp,F_OK))!=-1)
  8721. {
  8722. strcpy(chargingProfiles[i], fnametemp);
  8723. i = i + 1;
  8724. }
  8725. }
  8726. //Check TxProfile_%d.json
  8727. for(int j=1; j <= gunTotalNumber; j++)
  8728. {
  8729. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8730. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8731. if((access(fnametemp,F_OK))!=-1)
  8732. {
  8733. strcpy(chargingProfiles[i], fnametemp);
  8734. i = i + 1;
  8735. }
  8736. }
  8737. ChargeProfileCount = i;
  8738. }// End connectorIsNULL is TRUE
  8739. if(ChargeProfileCount == 0)
  8740. {
  8741. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8742. goto end;
  8743. }
  8744. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8745. {
  8746. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8747. goto end;
  8748. }
  8749. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8750. {
  8751. memset(str, 0, ARRAY_SIZE(str));
  8752. // clear temp file
  8753. sprintf(str,"rm -f %s",temp);
  8754. system(str);
  8755. for(int k=0; k < ChargeProfileCount; k++)
  8756. {
  8757. memset(str, 0, ARRAY_SIZE(str));
  8758. //clear file in C
  8759. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8760. system(str);
  8761. }
  8762. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8763. goto end;
  8764. }
  8765. else if(connectorIsNULL == TRUE)
  8766. {
  8767. for(int k=0; k < ChargeProfileCount; k++)
  8768. {
  8769. fptr1 = fopen(chargingProfiles[k], "r");
  8770. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8771. //Check Charging Profile Count
  8772. while(fscanf(fptr1, "%s", word) != EOF)
  8773. {
  8774. //DEBUG_INFO("word=%s\n",word);
  8775. if(strstr(word, "chargingProfileId")!= NULL)
  8776. {
  8777. //DEBUG_INFO("test chargingProfileId \n");
  8778. n_chargingProfile = n_chargingProfile + 1;
  8779. //DEBUG_INFO("chargingProfileId Found\n");
  8780. }
  8781. }
  8782. rewind(fptr1);
  8783. //search Charging Profile Element
  8784. //int i= 0;
  8785. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8786. {
  8787. json_object *tmpProfilee;
  8788. tmpProfilee = json_tokener_parse(sLineWord);
  8789. if(!is_error(tmpProfilee))
  8790. {
  8791. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8792. {
  8793. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8794. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8795. }
  8796. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8797. {
  8798. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8799. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8800. }
  8801. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8802. {
  8803. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8804. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8805. }
  8806. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8807. {
  8808. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8809. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8810. }
  8811. }
  8812. json_object_put(tmpProfilee);
  8813. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8814. {
  8815. //------- not write to fptr2-------//
  8816. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8817. //clearflag = TRUE;
  8818. }
  8819. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8820. {
  8821. //------- not write to fptr2-------//
  8822. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8823. }
  8824. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8825. {
  8826. //------- not write to fptr2-------//
  8827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8828. }
  8829. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8830. {
  8831. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8832. }
  8833. else
  8834. {
  8835. fprintf(fptr2, sLineWord);//writing data into file
  8836. }
  8837. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8838. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8839. if(clearflag == TRUE)
  8840. {
  8841. fclose(fptr1);
  8842. fclose(fptr2);
  8843. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8844. system(str);
  8845. // clear temp file
  8846. sprintf(str,"rm -f %s",temp);
  8847. system(str);
  8848. }
  8849. else
  8850. {
  8851. fclose(fptr1);
  8852. fclose(fptr2);
  8853. memset(str, 0, ARRAY_SIZE(str));
  8854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8855. system(str);
  8856. resultRename = rename(temp, chargingProfiles[k]);
  8857. if(resultRename == 0)
  8858. {
  8859. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8860. }
  8861. else
  8862. {
  8863. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8864. }
  8865. if(comfirmstr[0]== 0)
  8866. {
  8867. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8868. }
  8869. //Check chargingProfile is empty file
  8870. /*------ Read the file ----------------*/
  8871. fptr1=fopen(chargingProfiles[k],"r");
  8872. ch=fgetc(fptr1);
  8873. rewind(fptr1);
  8874. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8875. if(ch!=EOF)
  8876. {
  8877. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8878. {
  8879. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8880. if(sLineWord[0]=='\0')
  8881. {
  8882. isEmptyFile = TRUE;
  8883. break;
  8884. }
  8885. else
  8886. {
  8887. isEmptyFile = FALSE;
  8888. break;
  8889. }
  8890. }
  8891. }
  8892. else
  8893. isEmptyFile = TRUE;
  8894. fclose(fptr1);
  8895. if(isEmptyFile == TRUE)
  8896. {
  8897. memset(str, 0, ARRAY_SIZE(str));
  8898. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8899. system(str);
  8900. }
  8901. }
  8902. }// End of while(int k=0; k < ChargePointCount; k++)
  8903. }
  8904. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8905. {
  8906. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8907. for(int k=0; k < ChargeProfileCount; k++)
  8908. {
  8909. fptr1 = fopen(chargingProfiles[k], "r");
  8910. fptr2 = fopen(temp, "w+");
  8911. //Check Charging Profile Count
  8912. while(fscanf(fptr1, "%s", word) != EOF)
  8913. {
  8914. //DEBUG_INFO("word=%s\n",word);
  8915. if(strstr(word, "chargingProfileId")!= NULL)
  8916. {
  8917. n_chargingProfile = n_chargingProfile + 1;
  8918. }
  8919. }
  8920. rewind(fptr1);
  8921. //search Charging Profile Element
  8922. //int i= 0;
  8923. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8924. {
  8925. json_object *tmpProfilee;
  8926. tmpProfilee = json_tokener_parse(sLineWord);
  8927. if(!is_error(tmpProfilee))
  8928. {
  8929. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8930. {
  8931. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8932. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8933. }
  8934. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8935. {
  8936. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8937. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8938. }
  8939. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8940. {
  8941. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8942. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8943. }
  8944. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8945. {
  8946. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8947. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8948. }
  8949. }
  8950. json_object_put(tmpProfilee);
  8951. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8952. {
  8953. //------- not write to fptr2-------//
  8954. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8955. //clearflag = TRUE;
  8956. }
  8957. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8958. {
  8959. //------- not write to fptr2-------//
  8960. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8961. }
  8962. else if(stackLevelIsNULL == TRUE)
  8963. {
  8964. //Clear Whole File
  8965. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8966. clearflag = TRUE;
  8967. break;
  8968. }
  8969. else
  8970. {
  8971. fprintf(fptr2, sLineWord);//writing data into file
  8972. }
  8973. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8974. }
  8975. if(clearflag == TRUE)
  8976. {
  8977. fclose(fptr1);
  8978. fclose(fptr2);
  8979. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8980. system(str);
  8981. // clear temp file
  8982. sprintf(str,"rm -f %s",temp);
  8983. system(str);
  8984. }
  8985. else
  8986. {
  8987. fclose(fptr1);
  8988. fclose(fptr2);
  8989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8990. system(str);
  8991. resultRename = rename(temp, chargingProfiles[k]);
  8992. if(resultRename == 0)
  8993. {
  8994. DEBUG_INFO("File ChargingProfile renamed successfully");
  8995. }
  8996. else
  8997. {
  8998. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8999. }
  9000. if(comfirmstr[0]== 0)
  9001. {
  9002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9003. }
  9004. //Check chargingProfile is empty file
  9005. /*------ Read the file ----------------*/
  9006. fptr1=fopen(chargingProfiles[k],"r");
  9007. ch=fgetc(fptr1);
  9008. rewind(fptr1);
  9009. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9010. if(ch!=EOF)
  9011. {
  9012. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9013. {
  9014. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9015. if(sLineWord[0]=='\0')
  9016. {
  9017. isEmptyFile = TRUE;
  9018. break;
  9019. }
  9020. else
  9021. {
  9022. isEmptyFile = FALSE;
  9023. break;
  9024. }
  9025. }
  9026. }
  9027. else
  9028. isEmptyFile = TRUE;
  9029. fclose(fptr1);
  9030. if(isEmptyFile == TRUE)
  9031. {
  9032. memset(str, 0, ARRAY_SIZE(str));
  9033. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9034. system(str);
  9035. }
  9036. /*------- End of reading ---------------*/
  9037. }
  9038. } // while(int k=0; k < ChargeProfileCount; k++)
  9039. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9040. end:
  9041. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9042. {
  9043. if(connectorIdInt == 0)
  9044. {
  9045. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9046. {
  9047. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9048. }
  9049. }
  9050. else
  9051. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9052. }
  9053. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9054. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9055. return result;
  9056. }
  9057. void createFirmwareVersionByDataTransfer(void)
  9058. {
  9059. json_object *FirmwareDataTransfer = json_object_new_object();
  9060. // AC & DC model
  9061. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9062. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9063. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9064. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9065. // DC model
  9066. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9067. {
  9068. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9069. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9070. (gunType[3] != GUN_TYPE_UNKNOWN))
  9071. {
  9072. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9073. }
  9074. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9075. {
  9076. // DS DM DW
  9077. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9078. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9079. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9080. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9081. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9082. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9083. }
  9084. else
  9085. {
  9086. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9087. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9088. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9089. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9094. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9095. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9096. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9097. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9098. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9099. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9100. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9101. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9102. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9103. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9104. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9105. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9106. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9107. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9108. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9109. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9110. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9111. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9112. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9113. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9114. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9115. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9116. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9117. }
  9118. }
  9119. // 4G model
  9120. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9121. {
  9122. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9123. }
  9124. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9125. json_object_put(FirmwareDataTransfer);
  9126. }
  9127. int handleDataTransferRequest(char *uuid, char *payload)
  9128. {
  9129. mtrace();
  9130. json_object *response = json_object_new_object();
  9131. int result = FAIL;
  9132. char tempvendorId[255]={0};
  9133. char tempmessageId[50]={0};
  9134. char tempdata[512]={0};
  9135. char message[2048]={0};
  9136. DEBUG_INFO("handleDataTransferRequest...\n");
  9137. if((uuid != NULL) && (payload != NULL))
  9138. {
  9139. json_object *DataTransfer;
  9140. DataTransfer = json_tokener_parse(payload);
  9141. if(!is_error(DataTransfer))
  9142. {
  9143. // Required data
  9144. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9145. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9146. // Optional data
  9147. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9148. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9149. if(json_object_object_get(DataTransfer, "data") != NULL)
  9150. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9151. result = PASS;
  9152. }
  9153. json_object_put(DataTransfer);
  9154. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9155. {
  9156. // Send all moudle firmware version on EVSE
  9157. createFirmwareVersionByDataTransfer();
  9158. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9159. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9160. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9161. json_object_put(response);
  9162. }
  9163. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9164. {
  9165. system("/usr/bin/run_tmate_restart.sh &");
  9166. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9167. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9168. json_object_put(response);
  9169. }
  9170. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9171. {
  9172. json_object *data;
  9173. data = json_tokener_parse(tempdata);
  9174. if(!is_error(data))
  9175. {
  9176. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9177. {
  9178. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9179. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9180. if(json_object_object_get(data, "SOC") != NULL)
  9181. {
  9182. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9183. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9184. }
  9185. if(json_object_object_get(data, "Energy") != NULL)
  9186. {
  9187. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9188. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9189. }
  9190. if(json_object_object_get(data, "Duration") != NULL)
  9191. {
  9192. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9193. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9194. }
  9195. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9196. }
  9197. else
  9198. {
  9199. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9200. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9201. }
  9202. }
  9203. else
  9204. {
  9205. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9206. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9207. }
  9208. json_object_put(data);
  9209. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9210. json_object_put(response);
  9211. }
  9212. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9213. {
  9214. json_object *data;
  9215. data = json_tokener_parse(tempdata);
  9216. if(!is_error(data))
  9217. {
  9218. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9219. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9220. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9221. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9222. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9223. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9224. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9225. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9226. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9227. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9228. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9229. }
  9230. else
  9231. {
  9232. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9233. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9234. }
  9235. json_object_put(data);
  9236. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9237. json_object_put(response);
  9238. }
  9239. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9240. {
  9241. json_object *data;
  9242. data = json_tokener_parse(tempdata);
  9243. if(!is_error(data))
  9244. {
  9245. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9246. if(json_object_object_get(data, "idToken") != NULL)
  9247. {
  9248. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9249. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9250. }
  9251. if(json_object_object_get(data, "price") != NULL)
  9252. {
  9253. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9254. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9255. }
  9256. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9257. }
  9258. else
  9259. {
  9260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9261. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9262. }
  9263. json_object_put(data);
  9264. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9265. json_object_put(response);
  9266. }
  9267. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9268. {
  9269. json_object *data;
  9270. data = json_tokener_parse(tempdata);
  9271. if(!is_error(data))
  9272. {
  9273. if(json_object_object_get(data, "txId") != NULL)
  9274. {
  9275. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9276. for(int idx = 0;idx<gunTotalNumber;idx++)
  9277. {
  9278. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9279. {
  9280. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9281. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9282. if(json_object_object_get(data, "description") != NULL)
  9283. {
  9284. // California pricing V1.0
  9285. DEBUG_INFO("California pricing V1.0\n");
  9286. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9287. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9288. }
  9289. else
  9290. {
  9291. // California pricing V1.1
  9292. DEBUG_INFO("California pricing V1.1\n");
  9293. if(json_object_object_get(data, "timestamp") != NULL)
  9294. {
  9295. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9296. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9297. }
  9298. if(json_object_object_get(data, "meterValue") != NULL)
  9299. {
  9300. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9301. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9302. }
  9303. if(json_object_object_get(data, "cost") != NULL)
  9304. {
  9305. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9306. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9307. }
  9308. if(json_object_object_get(data, "state") != NULL)
  9309. {
  9310. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9311. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9312. }
  9313. if(json_object_object_get(data, "chargingPrice") != NULL)
  9314. {
  9315. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9316. {
  9317. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9318. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9319. }
  9320. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9321. {
  9322. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9323. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9324. }
  9325. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9326. {
  9327. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9328. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9329. }
  9330. }
  9331. if(json_object_object_get(data, "idlePrice") != NULL)
  9332. {
  9333. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9334. {
  9335. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9336. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9337. }
  9338. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9339. {
  9340. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9341. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9342. }
  9343. }
  9344. if(json_object_object_get(data, "nextPeriod") != NULL)
  9345. {
  9346. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9347. {
  9348. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9349. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9350. }
  9351. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9352. {
  9353. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9354. {
  9355. 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")));
  9356. 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"));
  9357. }
  9358. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9359. {
  9360. 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")));
  9361. 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"));
  9362. }
  9363. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9364. {
  9365. 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")));
  9366. 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"));
  9367. }
  9368. }
  9369. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9370. {
  9371. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9372. {
  9373. 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")));
  9374. 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"));
  9375. }
  9376. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9377. {
  9378. 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")));
  9379. 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"));
  9380. }
  9381. }
  9382. }
  9383. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9384. {
  9385. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9386. {
  9387. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9388. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9389. }
  9390. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9391. {
  9392. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9393. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9394. }
  9395. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9396. {
  9397. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9398. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9399. }
  9400. }
  9401. }
  9402. }
  9403. }
  9404. }
  9405. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9406. }
  9407. else
  9408. {
  9409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9410. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9411. }
  9412. json_object_put(data);
  9413. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9414. json_object_put(response);
  9415. }
  9416. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9417. {
  9418. json_object *data;
  9419. data = json_tokener_parse(tempdata);
  9420. if(!is_error(data))
  9421. {
  9422. if(json_object_object_get(data, "txId") != NULL)
  9423. {
  9424. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9425. for(int idx = 0;idx<gunTotalNumber;idx++)
  9426. {
  9427. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9428. {
  9429. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9430. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9431. if(json_object_object_get(data, "description") != NULL)
  9432. {
  9433. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9434. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9435. }
  9436. }
  9437. }
  9438. }
  9439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9440. }
  9441. else
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9445. }
  9446. json_object_put(data);
  9447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9448. json_object_put(response);
  9449. }
  9450. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9451. {
  9452. json_object *data;
  9453. data = json_tokener_parse(tempdata);
  9454. if(!is_error(data))
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9457. if(json_object_object_get(data, "Content_Type") != NULL)
  9458. {
  9459. 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))
  9460. {
  9461. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9462. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9463. {
  9464. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9465. }
  9466. }
  9467. else
  9468. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9469. }
  9470. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9471. }
  9472. else
  9473. {
  9474. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9475. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9476. }
  9477. json_object_put(data);
  9478. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9479. json_object_put(response);
  9480. }
  9481. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9482. {
  9483. json_object *data;
  9484. data = json_tokener_parse(tempdata);
  9485. if(!is_error(data))
  9486. {
  9487. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9488. if(json_object_object_get(data, "ConnectorId") != NULL)
  9489. {
  9490. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9491. }
  9492. if(json_object_object_get(data, "SerialNo") != NULL)
  9493. {
  9494. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9495. }
  9496. if(json_object_object_get(data, "Page_Index") != NULL)
  9497. {
  9498. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9499. }
  9500. if(json_object_object_get(data, "Duration") != NULL)
  9501. {
  9502. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9503. }
  9504. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9505. }
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9510. }
  9511. json_object_put(data);
  9512. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9513. json_object_put(response);
  9514. }
  9515. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9516. {
  9517. json_object *data;
  9518. data = json_tokener_parse(tempdata);
  9519. if(!is_error(data))
  9520. {
  9521. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9522. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9523. {
  9524. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9525. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9526. else
  9527. {
  9528. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9529. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9530. }
  9531. }
  9532. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9533. {
  9534. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9535. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9536. else
  9537. {
  9538. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9539. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9540. }
  9541. }
  9542. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9543. {
  9544. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9545. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9550. }
  9551. }
  9552. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9553. {
  9554. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9555. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9556. else
  9557. {
  9558. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9559. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9560. }
  9561. }
  9562. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9563. {
  9564. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9565. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9566. else
  9567. {
  9568. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9569. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9570. }
  9571. }
  9572. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9573. {
  9574. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9575. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9576. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9577. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9578. else
  9579. {
  9580. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9581. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9582. }
  9583. }
  9584. if(json_object_object_get(data, "isAuthentication") != NULL)
  9585. {
  9586. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9587. {
  9588. case 0:
  9589. case 1:
  9590. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9591. break;
  9592. default:
  9593. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9594. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9595. break;
  9596. }
  9597. }
  9598. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9599. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9600. }
  9601. else
  9602. {
  9603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9604. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9605. }
  9606. json_object_put(data);
  9607. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9608. json_object_put(response);
  9609. }
  9610. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9611. {
  9612. json_object *data;
  9613. data = json_tokener_parse(tempdata);
  9614. if(!is_error(data))
  9615. {
  9616. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9617. {
  9618. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9619. {
  9620. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9621. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9622. }
  9623. else
  9624. {
  9625. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9626. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9627. }
  9628. }
  9629. else
  9630. {
  9631. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9632. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9633. }
  9634. }
  9635. else
  9636. {
  9637. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9638. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9639. }
  9640. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9641. json_object_put(response);
  9642. }
  9643. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9644. {
  9645. json_object *data;
  9646. data = json_tokener_parse(tempdata);
  9647. if(!is_error(data))
  9648. {
  9649. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9650. if(json_object_object_get(data, "stationName") != NULL)
  9651. {
  9652. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9653. }
  9654. else
  9655. {
  9656. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9657. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9658. }
  9659. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9660. {
  9661. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9662. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9663. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9664. }
  9665. }
  9666. else
  9667. {
  9668. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9669. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9670. }
  9671. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9672. json_object_put(response);
  9673. }
  9674. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9675. {
  9676. json_object *data;
  9677. data = json_tokener_parse(tempdata);
  9678. if(!is_error(data))
  9679. {
  9680. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9681. if(json_object_object_get(data, "weatherId") != NULL)
  9682. {
  9683. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9684. }
  9685. else
  9686. {
  9687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9688. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9689. }
  9690. if(json_object_object_get(data, "Temperature") != NULL)
  9691. {
  9692. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9693. }
  9694. else
  9695. {
  9696. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9697. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9698. }
  9699. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9700. {
  9701. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9702. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9703. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9704. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9705. );
  9706. }
  9707. }
  9708. else
  9709. {
  9710. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9711. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9712. }
  9713. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9714. json_object_put(response);
  9715. }
  9716. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9717. {
  9718. json_object *data;
  9719. data = json_tokener_parse(tempdata);
  9720. if(!is_error(data))
  9721. {
  9722. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9723. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9724. {
  9725. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9726. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9727. }
  9728. else
  9729. {
  9730. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9731. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9732. }
  9733. }
  9734. else
  9735. {
  9736. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9737. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9738. }
  9739. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9740. json_object_put(response);
  9741. }
  9742. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9743. {
  9744. json_object *data;
  9745. data = json_tokener_parse(tempdata);
  9746. if(!is_error(data))
  9747. {
  9748. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9749. {
  9750. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9751. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9752. if(gun_index < gunTotalNumber)
  9753. {
  9754. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9755. {
  9756. json_object *responsedata = json_object_new_object();
  9757. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9758. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9759. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  9760. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9761. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9762. }
  9763. else
  9764. {
  9765. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9766. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9767. }
  9768. }
  9769. else
  9770. {
  9771. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9772. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9773. }
  9774. }
  9775. else
  9776. {
  9777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9778. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9779. }
  9780. }
  9781. else
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9784. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9785. }
  9786. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9787. json_object_put(response);
  9788. }
  9789. else
  9790. {
  9791. // Can not find valid message id
  9792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9793. }
  9794. }
  9795. else
  9796. {
  9797. // Payload is null
  9798. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9799. }
  9800. LWS_Send(message);
  9801. return result;
  9802. }
  9803. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9804. {
  9805. mtrace();
  9806. int result = FAIL;
  9807. int connectorIdInt, durationInt;
  9808. char chargingRateUnitStr[4]={0};
  9809. char comfirmstr[20];
  9810. int confirmPeriods = 0;
  9811. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9812. json_object *GetCompositeSchedule;
  9813. GetCompositeSchedule = json_tokener_parse(payload);
  9814. if(!is_error(GetCompositeSchedule))
  9815. {
  9816. // Required data
  9817. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9818. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9819. else
  9820. connectorIdInt = -1;
  9821. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9822. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9823. else
  9824. durationInt = 86400;
  9825. // Optional data
  9826. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9827. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9828. }
  9829. json_object_put(GetCompositeSchedule);
  9830. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9831. if((connectorIdInt == 0) ||
  9832. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9833. {
  9834. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9835. struct StructChargingProfile tmpProfile[1];
  9836. if(strstr(chargingRateUnitStr, "W") != NULL)
  9837. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9838. else
  9839. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9840. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9841. {
  9842. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9843. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9844. }
  9845. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9846. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9847. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9848. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9849. {
  9850. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9851. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9852. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9853. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9854. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9855. {
  9856. confirmPeriods = idx;
  9857. break;
  9858. }
  9859. }
  9860. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9861. {
  9862. confirmPeriods += 1;
  9863. }
  9864. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9865. }
  9866. else
  9867. {
  9868. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9869. }
  9870. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9871. return result;
  9872. }
  9873. int handleGetConfigurationRequest(char *uuid, char *payload)
  9874. {
  9875. mtrace();
  9876. int result = FAIL;
  9877. int MaxKeySupported = 0;
  9878. int n_keys = 0;
  9879. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9880. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9881. json_object *GetConfiguration;
  9882. GetConfiguration = json_tokener_parse(payload);
  9883. if(!is_error(GetConfiguration))
  9884. {
  9885. // Optional data
  9886. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9887. {
  9888. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9889. {
  9890. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9891. n_keys = idx + 1;
  9892. }
  9893. }
  9894. }
  9895. json_object_put(GetConfiguration);
  9896. UnknownKeynum = 0;
  9897. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9898. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9899. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9900. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9901. if(n_keys != 0)
  9902. {
  9903. for(int i=0;i<n_keys;i++)
  9904. {
  9905. getKeyValue(requestKey[i]);
  9906. }
  9907. }
  9908. else
  9909. {
  9910. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9911. getKeyValue("");
  9912. }
  9913. processUnkownKey();
  9914. sendGetConfigurationConfirmation(uuid);
  9915. return result;
  9916. }
  9917. static char fnamePlusPath[100]={0};
  9918. static char fnamePWithNoPath[60]={0};
  9919. void checkUploadLog(void)
  9920. {
  9921. FILE *fp;
  9922. /* Open the command for reading. */
  9923. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9924. if (fp == NULL) {
  9925. DEBUG_WARN("Failed to run command\n" );
  9926. exit(1);
  9927. }
  9928. int ftppathlen = 0;
  9929. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9930. int i = 0;
  9931. /* Read the output a line at a time - output it. */
  9932. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9933. if(i==0)
  9934. {
  9935. ftppathlen = strlen(fnamePlusPath);
  9936. DEBUG_INFO("%s\n", fnamePlusPath);
  9937. fnamePlusPath[ftppathlen]='\0';
  9938. break;
  9939. }
  9940. i= i+1;
  9941. }
  9942. /* close */
  9943. pclose(fp);
  9944. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9945. {
  9946. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9947. {
  9948. fnamePlusPath[k]='\0';
  9949. }
  9950. }
  9951. i=1;
  9952. //char fname[60]={0};
  9953. while(i < ftppathlen)
  9954. {
  9955. int len=ftppathlen-i;
  9956. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9957. {
  9958. DEBUG_INFO("compare '/' all right\n");
  9959. break;
  9960. }
  9961. i=i+1;
  9962. }
  9963. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9964. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9965. fnamePWithNoPath[i+1] = '\0';
  9966. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9967. {
  9968. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9969. {
  9970. fnamePWithNoPath[j]='\0';
  9971. }
  9972. }
  9973. FILE* fp1 = fopen(fnamePlusPath, "r");
  9974. if (fp1)
  9975. {
  9976. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9977. // file exists
  9978. fclose(fp1);
  9979. }
  9980. else
  9981. {
  9982. // file doesn't exist
  9983. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9984. }
  9985. }
  9986. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9987. {
  9988. mtrace();
  9989. int result = FAIL;
  9990. time_t CurrentTime;
  9991. struct tm *tm;
  9992. pthread_t th_Status;
  9993. CurrentTime = time(NULL);
  9994. tm = localtime(&CurrentTime);
  9995. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9996. 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);
  9997. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9998. if(!interLock.isGetDiagnosticGoing)
  9999. {
  10000. interLock.isGetDiagnosticGoing = 1;
  10001. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10002. sleep(1);
  10003. }
  10004. else
  10005. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10006. return result;
  10007. }
  10008. void* GetDiagnosticsProcess(void* data)
  10009. {
  10010. pthread_detach(pthread_self());
  10011. mtrace();
  10012. int retriesInt=0, retryIntervalInt=0;
  10013. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10014. 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};
  10015. int port=0;
  10016. int isSuccess = FALSE;
  10017. char cmdBuf[2048];
  10018. struct tm *tmNow;
  10019. time_t CurrentTime;
  10020. struct tm tmStart;
  10021. struct tm tmStop;
  10022. CurrentTime = time(NULL);
  10023. tmNow=localtime(&CurrentTime);
  10024. uint16_t targetYear, targetMonth;
  10025. json_object *GetDiagnostics;
  10026. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10027. GetDiagnostics = json_tokener_parse(data);
  10028. if(!is_error(GetDiagnostics))
  10029. {
  10030. // Required data
  10031. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10032. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10033. // Optional data
  10034. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10035. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10036. else
  10037. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10038. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10039. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10040. else
  10041. retryIntervalInt = 30;
  10042. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10043. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10044. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10045. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10046. }
  10047. json_object_put(GetDiagnostics);
  10048. // Pack log to compress file
  10049. 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) &&
  10050. (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))
  10051. {
  10052. // Pack system log
  10053. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10054. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10055. targetYear = tmStart.tm_year;
  10056. targetMonth = tmStart.tm_mon;
  10057. do
  10058. {
  10059. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10060. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10061. if(targetMonth+1>=13)
  10062. {
  10063. targetYear += 1;
  10064. targetMonth = 1;
  10065. }
  10066. else
  10067. {
  10068. targetMonth += 1;
  10069. }
  10070. }while((targetYear < (tmNow->tm_year+1900)) ||
  10071. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10072. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10073. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10074. system(cmdBuf);
  10075. // Pack charging & event log
  10076. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10077. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10078. targetYear = tmStart.tm_year;
  10079. targetMonth = tmStart.tm_mon;
  10080. do
  10081. {
  10082. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10083. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10084. if(targetMonth+1>=13)
  10085. {
  10086. targetYear += 1;
  10087. targetMonth = 1;
  10088. }
  10089. else
  10090. {
  10091. targetMonth += 1;
  10092. }
  10093. }while((targetYear < (tmNow->tm_year+1900)) ||
  10094. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10095. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10096. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10097. system(cmdBuf);
  10098. // Combine log file
  10099. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10100. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10101. }
  10102. else
  10103. {
  10104. system("exec /root/logPackTools 'log' 6");
  10105. }
  10106. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10107. system(cmdBuf);
  10108. checkUploadLog();
  10109. //****************location*******************/
  10110. if(strcmp(locationstr,"")==0)
  10111. {
  10112. DEBUG_INFO("location is <Empty>!\n");
  10113. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10114. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10115. goto end;
  10116. }
  10117. memset(protocol, 0, ARRAY_SIZE(protocol));
  10118. memset(user, 0, ARRAY_SIZE(user) );
  10119. memset(password, 0, ARRAY_SIZE(password));
  10120. memset(host, 0, ARRAY_SIZE(host));
  10121. memset(path, 0, ARRAY_SIZE(path));
  10122. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10123. memset(host1, 0, ARRAY_SIZE(host1));
  10124. memset(path1, 0, ARRAY_SIZE(path1));
  10125. /*location: ftp://user:password@host:port/path*/
  10126. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10127. if((access(fnamePlusPath,F_OK))!=-1)
  10128. {
  10129. DEBUG_INFO("fnamePlusPath exist.\n");
  10130. }
  10131. else
  10132. {
  10133. DEBUG_INFO("fnamePlusPath not exist!\n");
  10134. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10135. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10136. goto end;
  10137. }
  10138. if(strchr(locationstr,'@')==NULL)
  10139. {
  10140. sscanf(locationstr,
  10141. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10142. protocol, host, &port, path);
  10143. strcpy(user,"anonymous");
  10144. strcpy(password,"");
  10145. }
  10146. else
  10147. {
  10148. //DEBUG_INFO("pch=%s\n", pch);
  10149. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10150. protocol, user, password, host, &port, path);
  10151. }
  10152. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10153. {
  10154. DEBUG_INFO("protocol is not ftp/http ! \n");
  10155. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10156. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10157. goto end;
  10158. }
  10159. if(strncmp(locationstr,"http", 4) == 0)
  10160. {
  10161. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10162. sprintf(ftppath,"/%s", path);
  10163. do
  10164. {
  10165. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10166. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10167. sleep(3);
  10168. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10169. if(!isSuccess)
  10170. {
  10171. DEBUG_INFO("Diagnostics fail.\n");
  10172. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10173. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10174. sleep(retryIntervalInt);
  10175. }
  10176. else
  10177. {
  10178. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10179. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10181. }
  10182. retriesInt--;
  10183. }while((isSuccess == 0)&&(retriesInt >= 0));
  10184. }
  10185. else
  10186. {
  10187. sscanf(host,"%[^/]%s",host1, path1);
  10188. if(strlen(path) > 0)
  10189. sprintf(ftppath,"/%s", path);
  10190. else
  10191. sprintf(ftppath,"/%s", path1);
  10192. int ftppathlen=strlen(ftppath);
  10193. int i=1;
  10194. char filenametemp[50];
  10195. while(i < ftppathlen)
  10196. {
  10197. int len=ftppathlen-i;
  10198. if(ftppath[len]== 47) // '/' ascll code: 47
  10199. {
  10200. DEBUG_INFO("find '/' all right\n");
  10201. break;
  10202. }
  10203. i=i+1;
  10204. }
  10205. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10206. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10207. filenametemp[i+1] = 0;
  10208. if(port == 0)
  10209. port = 21;
  10210. do
  10211. {
  10212. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10213. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10214. sleep(3);
  10215. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10216. if(!isSuccess)
  10217. {
  10218. DEBUG_INFO("Diagnostics fail.\n");
  10219. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10220. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10221. sleep(retryIntervalInt);
  10222. }
  10223. else
  10224. {
  10225. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10228. }
  10229. retriesInt--;
  10230. }while((!isSuccess)&&(retriesInt >= 0));
  10231. }
  10232. end:
  10233. system("rm -f /mnt/*");
  10234. sleep(5);
  10235. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10237. interLock.isGetDiagnosticGoing = 0;
  10238. pthread_exit(NULL);
  10239. }
  10240. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10241. {
  10242. mtrace();
  10243. int result = FAIL;
  10244. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10245. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10246. {
  10247. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10248. locallistVersion = -1;
  10249. }
  10250. else
  10251. {
  10252. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10253. OCPP_getListVerion();
  10254. }
  10255. //from db.OCPP_getListVerion
  10256. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10257. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10258. sendGetLocalListVersionConfirmation(uuid,"");
  10259. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10260. return result;
  10261. }
  10262. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10263. {
  10264. mtrace();
  10265. int result = FAIL;
  10266. int connectorIdInt=-1;
  10267. int tempIndex = 0;
  10268. int connectorIdIsNULL, chargingProfileIsNULL;
  10269. char comfirmstr[20]={0};
  10270. char cmdBuf[512];
  10271. json_object *RemoteStartTransaction;
  10272. FILE *fp;
  10273. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10274. if(server_pending == TRUE)
  10275. {
  10276. return 0;
  10277. }
  10278. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10279. RemoteStartTransaction = json_tokener_parse(payload);
  10280. if(!is_error(RemoteStartTransaction))
  10281. {
  10282. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10283. {
  10284. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10285. }
  10286. else
  10287. {
  10288. connectorIdIsNULL = TRUE;
  10289. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10290. {
  10291. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10292. {
  10293. connectorIdIsNULL = FALSE;
  10294. connectorIdInt = (gun_index+1);
  10295. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10296. break;
  10297. }
  10298. }
  10299. }
  10300. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10301. {
  10302. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10303. // Required data
  10304. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10305. // Optional data
  10306. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10307. {
  10308. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10309. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10310. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10311. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10312. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10313. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10314. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10315. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10316. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10317. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10318. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10319. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10320. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10321. {
  10322. 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")));
  10323. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10324. 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"));
  10325. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10326. 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"));
  10327. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10328. 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")));
  10329. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10330. {
  10331. 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++)
  10332. {
  10333. 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"));
  10334. 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"));
  10335. 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)
  10336. 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"));
  10337. }
  10338. }
  10339. }
  10340. }
  10341. else
  10342. {
  10343. chargingProfileIsNULL = TRUE;
  10344. }
  10345. }
  10346. }
  10347. else
  10348. {
  10349. connectorIdIsNULL = TRUE;
  10350. }
  10351. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10352. {
  10353. DEBUG_WARN("Connector id is NULL\n.");
  10354. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10355. goto end;
  10356. }
  10357. /*
  10358. enum _SYSTEM_STATUS
  10359. {
  10360. S_BOOTING = 0,
  10361. S_IDLE, = 1
  10362. S_AUTHORIZING, = 2
  10363. S_REASSIGN_CHECK, = 3
  10364. S_REASSIGN, = 4
  10365. S_PRECHARGE, = 5
  10366. S_PREPARING_FOR_EV, = 6
  10367. S_PREPARING_FOR_EVSE, = 7
  10368. S_CHARGING, = 8
  10369. S_TERMINATING, = 9
  10370. S_COMPLETE, = 10
  10371. S_ALARM, = 11
  10372. S_FAULT = 12
  10373. }
  10374. */
  10375. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10376. {
  10377. //check Transaction active
  10378. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10379. {
  10380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10381. {
  10382. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10383. }
  10384. else
  10385. {
  10386. tempIndex = connectorIdInt -1;
  10387. }
  10388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10389. {
  10390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10391. {
  10392. 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))
  10393. {
  10394. //Reserved
  10395. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10396. }
  10397. 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))
  10398. {
  10399. //Reserved
  10400. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10402. goto end;
  10403. }
  10404. else
  10405. {
  10406. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10407. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10408. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10409. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10410. {
  10411. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. }//END FOR ELSE
  10416. }
  10417. }// END FOR CHAdeMO_QUANTITY
  10418. }
  10419. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10420. {
  10421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10422. {
  10423. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10424. }
  10425. else
  10426. {
  10427. tempIndex = connectorIdInt -1;
  10428. }
  10429. for (int index = 0; index < CCS_QUANTITY; index++)
  10430. {
  10431. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10432. {
  10433. 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))
  10434. {
  10435. //Reserved
  10436. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10437. }
  10438. 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))
  10439. {
  10440. //Reserved
  10441. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10443. goto end;
  10444. }
  10445. else
  10446. {
  10447. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10448. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10449. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10450. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10451. {
  10452. DEBUG_WARN("CCS connector not allow start\n.");
  10453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10454. goto end;
  10455. }
  10456. }// END FOR ELSE
  10457. }
  10458. }// END FOR CCS_QUANTITY
  10459. }
  10460. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10461. {
  10462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10463. {
  10464. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10465. }
  10466. else
  10467. {
  10468. tempIndex = connectorIdInt -1;
  10469. }
  10470. for (int index = 0; index < GB_QUANTITY; index++)
  10471. {
  10472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10473. {
  10474. 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))
  10475. {
  10476. //Reserved
  10477. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10478. }
  10479. 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))
  10480. {
  10481. //Reserved
  10482. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10483. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10484. goto end;
  10485. }
  10486. else
  10487. {
  10488. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10489. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10490. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10491. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10492. {
  10493. DEBUG_WARN("GB connector not allow start\n.");
  10494. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10495. goto end;
  10496. }
  10497. }// END FOR ELSE
  10498. }
  10499. } // END FOR GB_QUANTITY
  10500. }
  10501. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10502. {
  10503. tempIndex = connectorIdInt -1;
  10504. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10505. {
  10506. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10507. {
  10508. 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))
  10509. {
  10510. //Reserved
  10511. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10512. }
  10513. 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))
  10514. {
  10515. //Reserved
  10516. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10518. goto end;
  10519. }
  10520. else
  10521. {
  10522. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10523. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10524. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10525. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10526. {
  10527. DEBUG_WARN("GB connector not allow start\n.");
  10528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10529. goto end;
  10530. }
  10531. }// END FOR ELSE
  10532. }
  10533. } // END FOR GB_QUANTITY
  10534. }
  10535. else
  10536. {
  10537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10538. {
  10539. tempIndex = 2;
  10540. }
  10541. else
  10542. {
  10543. tempIndex = connectorIdInt -1;
  10544. }
  10545. for (int index = 0; index < AC_QUANTITY; index++)
  10546. {
  10547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10548. {
  10549. 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))
  10550. {
  10551. //Reserved
  10552. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10553. }
  10554. 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))
  10555. {
  10556. //Reserved
  10557. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10558. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10559. goto end;
  10560. }
  10561. else
  10562. {
  10563. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10564. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10565. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10566. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10567. {
  10568. DEBUG_WARN("AC connector not allow start\n.");
  10569. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10570. goto end;
  10571. }
  10572. }//END FOR ELSE
  10573. }
  10574. }// END FOR AC_QUANTITY
  10575. }
  10576. if(chargingProfileIsNULL == FALSE)
  10577. {
  10578. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10579. {
  10580. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10582. //memset idTag
  10583. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10584. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10585. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10586. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10587. // Save profile to file
  10588. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10589. system(cmdBuf);
  10590. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10591. fp = fopen(cmdBuf, "w");
  10592. 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));
  10593. fclose(fp);
  10594. }
  10595. else
  10596. {
  10597. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10599. }
  10600. }
  10601. else
  10602. {
  10603. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10604. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10605. //memset idTag
  10606. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10607. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10608. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10609. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10610. }
  10611. }
  10612. else
  10613. {
  10614. DEBUG_WARN("Connector id over\n.");
  10615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10616. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10617. }
  10618. end:
  10619. json_object_put(RemoteStartTransaction);
  10620. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10621. {
  10622. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10623. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10624. }
  10625. //OCPP send RemoteStartConfirmation by first.
  10626. sendRemoteStartConfirmation(uuid, comfirmstr);
  10627. return result;
  10628. }
  10629. int handleRemoteStartRequest(char *uuid, char *payload)
  10630. {
  10631. mtrace();
  10632. int result = PASS;
  10633. int connectorIdInt=-1;
  10634. int tempIndex = 0;
  10635. char comfirmstr[20]={0};
  10636. char cmdBuf[512];
  10637. json_object *RemoteStartTransaction;
  10638. FILE *fp;
  10639. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10640. if(server_pending == TRUE)
  10641. {
  10642. result = FAIL;
  10643. }
  10644. RemoteStartTransaction = json_tokener_parse(payload);
  10645. if(!is_error(RemoteStartTransaction))
  10646. {
  10647. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10648. {
  10649. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10650. }
  10651. else
  10652. {
  10653. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10654. {
  10655. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10656. {
  10657. connectorIdInt = (gun_index+1);
  10658. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10659. break;
  10660. }
  10661. }
  10662. }
  10663. if(connectorIdInt == 0)
  10664. {
  10665. DEBUG_WARN("Connector id shall not equal 0.\n");
  10666. result = FAIL;
  10667. }
  10668. else if(connectorIdInt == -1)
  10669. {
  10670. DEBUG_INFO("Connector id does not specific.\n");
  10671. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10672. {
  10673. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10674. // Required data
  10675. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10676. // Optional data
  10677. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10678. {
  10679. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10680. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10681. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10682. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10683. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10684. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10685. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10686. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10687. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10688. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10689. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10690. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10691. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10692. {
  10693. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10694. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10695. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10696. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10697. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10698. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10699. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10700. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10701. {
  10702. 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++)
  10703. {
  10704. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10705. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10706. 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)
  10707. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10708. }
  10709. }
  10710. }
  10711. }
  10712. else
  10713. {
  10714. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10715. }
  10716. }
  10717. }
  10718. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10719. {
  10720. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10721. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10722. // Required data
  10723. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10724. // Optional data
  10725. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10726. {
  10727. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10728. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10729. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10730. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10731. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10732. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10733. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10734. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10735. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10736. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10737. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10738. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10739. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10740. {
  10741. 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")));
  10742. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10743. 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"));
  10744. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10745. 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"));
  10746. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10747. 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")));
  10748. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10749. {
  10750. 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++)
  10751. {
  10752. 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"));
  10753. 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"));
  10754. 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)
  10755. 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"));
  10756. }
  10757. }
  10758. }
  10759. }
  10760. else
  10761. {
  10762. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10763. }
  10764. }
  10765. else
  10766. {
  10767. DEBUG_WARN("Connector id is over maximun value.\n");
  10768. result = FAIL;
  10769. }
  10770. }
  10771. if(result == PASS)
  10772. {
  10773. if(connectorIdInt > 0)
  10774. {
  10775. //check Transaction active
  10776. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10777. {
  10778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10779. {
  10780. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10781. }
  10782. else
  10783. {
  10784. tempIndex = connectorIdInt -1;
  10785. }
  10786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10787. {
  10788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10789. {
  10790. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10791. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10792. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10793. {
  10794. //Reserved
  10795. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10796. }
  10797. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10798. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10799. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10800. {
  10801. //Reserved
  10802. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10803. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10804. goto end;
  10805. }
  10806. else
  10807. {
  10808. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10809. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10810. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10811. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10812. {
  10813. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10815. goto end;
  10816. }
  10817. }//END FOR ELSE
  10818. }
  10819. }// END FOR CHAdeMO_QUANTITY
  10820. }
  10821. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10822. {
  10823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10824. {
  10825. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10826. }
  10827. else
  10828. {
  10829. tempIndex = connectorIdInt -1;
  10830. }
  10831. for (int index = 0; index < CCS_QUANTITY; index++)
  10832. {
  10833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10834. {
  10835. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10836. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10837. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10838. {
  10839. //Reserved
  10840. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10841. }
  10842. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10843. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10844. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10845. {
  10846. //Reserved
  10847. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10848. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10849. goto end;
  10850. }
  10851. else
  10852. {
  10853. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10854. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10855. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10856. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10857. {
  10858. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10860. goto end;
  10861. }
  10862. }// END FOR ELSE
  10863. }
  10864. }// END FOR CCS_QUANTITY
  10865. }
  10866. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10867. {
  10868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10869. {
  10870. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10871. }
  10872. else
  10873. {
  10874. tempIndex = connectorIdInt -1;
  10875. }
  10876. for (int index = 0; index < GB_QUANTITY; index++)
  10877. {
  10878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10879. {
  10880. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10881. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10882. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10883. {
  10884. //Reserved
  10885. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10886. }
  10887. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10888. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10889. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10890. {
  10891. //Reserved
  10892. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10893. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10894. goto end;
  10895. }
  10896. else
  10897. {
  10898. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10899. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10900. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10901. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10902. {
  10903. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10905. goto end;
  10906. }
  10907. }// END FOR ELSE
  10908. }
  10909. } // END FOR GB_QUANTITY
  10910. }
  10911. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10912. {
  10913. tempIndex = connectorIdInt -1;
  10914. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10915. {
  10916. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10917. {
  10918. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10919. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10920. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10921. {
  10922. //Reserved
  10923. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10924. }
  10925. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10926. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10927. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10928. {
  10929. //Reserved
  10930. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10931. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10932. goto end;
  10933. }
  10934. else
  10935. {
  10936. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10937. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10938. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10939. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10940. {
  10941. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10942. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10943. goto end;
  10944. }
  10945. }// END FOR ELSE
  10946. }
  10947. } // END FOR GB_QUANTITY
  10948. }
  10949. else
  10950. {
  10951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10952. {
  10953. tempIndex = 2;
  10954. }
  10955. else
  10956. {
  10957. tempIndex = connectorIdInt -1;
  10958. }
  10959. for (int index = 0; index < AC_QUANTITY; index++)
  10960. {
  10961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10962. {
  10963. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10964. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10965. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10966. {
  10967. //Reserved
  10968. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10969. }
  10970. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10971. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10972. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10973. {
  10974. //Reserved
  10975. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10977. goto end;
  10978. }
  10979. else
  10980. {
  10981. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10982. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10983. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10984. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10985. {
  10986. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10987. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10988. goto end;
  10989. }
  10990. }//END FOR ELSE
  10991. }
  10992. }// END FOR AC_QUANTITY
  10993. }
  10994. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10995. {
  10996. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10997. {
  10998. // Save profile to file
  10999. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11000. system(cmdBuf);
  11001. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11002. fp = fopen(cmdBuf, "w");
  11003. 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));
  11004. fclose(fp);
  11005. }
  11006. else
  11007. {
  11008. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11009. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11010. goto end;
  11011. }
  11012. }
  11013. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11014. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11015. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11016. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11017. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11018. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11019. }
  11020. else
  11021. {
  11022. uint8_t isHasIdleConnector = FALSE;
  11023. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11024. {
  11025. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11026. {
  11027. isHasIdleConnector = TRUE;
  11028. break;
  11029. }
  11030. }
  11031. if(isHasIdleConnector == TRUE)
  11032. {
  11033. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11034. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11035. {
  11036. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11037. {
  11038. // Save profile to file
  11039. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11040. system(cmdBuf);
  11041. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11042. fp = fopen(cmdBuf, "w");
  11043. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11044. fclose(fp);
  11045. refreshStartTimer(&clientTime.RemoteStartWait);
  11046. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11048. }
  11049. else
  11050. {
  11051. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11052. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11053. }
  11054. }
  11055. else
  11056. {
  11057. refreshStartTimer(&clientTime.RemoteStartWait);
  11058. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11060. }
  11061. }
  11062. else
  11063. {
  11064. DEBUG_INFO("There is not any connector is idle.\n");
  11065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11066. }
  11067. }
  11068. }
  11069. else
  11070. {
  11071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11072. }
  11073. end:
  11074. json_object_put(RemoteStartTransaction);
  11075. sendRemoteStartConfirmation(uuid, comfirmstr);
  11076. return result;
  11077. }
  11078. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11079. {
  11080. mtrace();
  11081. int result = FAIL;
  11082. int match = FALSE;
  11083. int GunNO = 0;
  11084. int tempIndex = 0;
  11085. int transactionIdInt=0;
  11086. int transactionIdIsNULL= TRUE;
  11087. char comfirmstr[20];
  11088. json_object *RemoteStopTransaction;
  11089. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11090. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11091. if(server_pending == TRUE)
  11092. {
  11093. return 0;
  11094. }
  11095. RemoteStopTransaction = json_tokener_parse(payload);
  11096. if(!is_error(RemoteStopTransaction))
  11097. {
  11098. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11099. {
  11100. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11101. transactionIdIsNULL = FALSE;
  11102. }
  11103. }
  11104. json_object_put(RemoteStopTransaction);
  11105. if(transactionIdIsNULL == FALSE)
  11106. {
  11107. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11108. {
  11109. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11110. {
  11111. //check Transaction active
  11112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11113. {
  11114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11115. {
  11116. tempIndex = ((gun_index==2) ? 1: 0);
  11117. }
  11118. else
  11119. {
  11120. tempIndex = gun_index;
  11121. }
  11122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11123. {
  11124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11125. {
  11126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11127. {
  11128. match = TRUE;
  11129. GunNO = gun_index;
  11130. }
  11131. }
  11132. }// END FOR CHAdeMO_QUANTITY
  11133. }
  11134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11135. {
  11136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11137. {
  11138. tempIndex = ((gun_index==2) ? 1: 0);
  11139. }
  11140. else
  11141. {
  11142. tempIndex = gun_index;
  11143. }
  11144. for (int index = 0; index < CCS_QUANTITY; index++)
  11145. {
  11146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11147. {
  11148. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11149. {
  11150. match = TRUE;
  11151. GunNO = gun_index;
  11152. }
  11153. }
  11154. }// END FOR CCS_QUANTITY
  11155. }
  11156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11157. {
  11158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11159. {
  11160. tempIndex = ((gun_index==2) ? 1: 0);
  11161. }
  11162. else
  11163. {
  11164. tempIndex = gun_index;
  11165. }
  11166. for (int index = 0; index < GB_QUANTITY; index++)
  11167. {
  11168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11169. {
  11170. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11171. {
  11172. match = TRUE;
  11173. GunNO = gun_index;
  11174. }
  11175. }
  11176. }// END FOR GB_QUANTITY
  11177. }
  11178. else if(gunType[gun_index] == GUN_TYPE_DO)
  11179. {
  11180. tempIndex = gun_index;
  11181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11182. {
  11183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11184. {
  11185. 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
  11186. {
  11187. match = TRUE;
  11188. GunNO = gun_index;
  11189. }
  11190. }
  11191. }// END FOR GB_QUANTITY
  11192. }
  11193. else
  11194. {
  11195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11196. {
  11197. tempIndex = 2;
  11198. }
  11199. else
  11200. {
  11201. tempIndex = gun_index;
  11202. }
  11203. for (int index = 0; index < AC_QUANTITY; index++)
  11204. {
  11205. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11206. {
  11207. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11208. {
  11209. match = TRUE;
  11210. GunNO = gun_index;
  11211. }
  11212. }
  11213. }// END FOR CHAdeMO_QUANTITY
  11214. } // END FOR AC ELSE
  11215. }// CHECK IF ResponseTransactionId == transactionIdInt
  11216. }//END FOR
  11217. if( match == TRUE)
  11218. {
  11219. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11221. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11222. }
  11223. else
  11224. {
  11225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11226. }
  11227. }
  11228. else
  11229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11230. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11231. return result;
  11232. }
  11233. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11234. {
  11235. mtrace();
  11236. int result = FAIL;
  11237. int connectorIdInt=0, reservationIdInt=0;
  11238. int tempIndex = 0;
  11239. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11240. char comfirmstr[20]={0};
  11241. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11242. int c = 0;
  11243. char *loc;
  11244. //char *ptr;
  11245. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11246. strcpy(sstrtemp, stringtrimspace(payload));
  11247. //***(1)connectorId ****/
  11248. c=0;
  11249. loc = strstr(sstrtemp, "connectorId");
  11250. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11251. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11252. {
  11253. sstr[c] = loc[strlen("connectorId")+2+c];
  11254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11255. c++;
  11256. }
  11257. sstr[c] = '\0';
  11258. connectorIdInt = atoi(sstr);
  11259. //***(2)expiryDate ****/
  11260. loc = strstr(sstrtemp, "expiryDate");
  11261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11262. c = 0;
  11263. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11264. {
  11265. sstr[c] = loc[3+strlen("expiryDate")+c];
  11266. c++;
  11267. }
  11268. sstr[c] = '\0';
  11269. strcpy(expiryDatestr, sstr);
  11270. //***(3)idTag ****/
  11271. loc = strstr(sstrtemp, "idTag");
  11272. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11273. c = 0;
  11274. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11275. {
  11276. sstr[c] = loc[3+strlen("idTag")+c];
  11277. c++;
  11278. }
  11279. sstr[c] = '\0';
  11280. strcpy(idTagstr, sstr);
  11281. //***(4)parentIdTag ****/
  11282. loc = strstr(sstrtemp, "parentIdTag");
  11283. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11284. c = 0;
  11285. if(loc == NULL)
  11286. {
  11287. strcpy(parentIdTagstr, "");
  11288. }
  11289. else
  11290. {
  11291. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11292. {
  11293. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11294. c++;
  11295. }
  11296. sstr[c] = '\0';
  11297. strcpy(parentIdTagstr, sstr);
  11298. }
  11299. //***(5)reservationId ****/
  11300. c=0;
  11301. loc = strstr(sstrtemp, "reservationId");
  11302. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11303. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11304. {
  11305. sstr[c] = loc[strlen("reservationId")+2+c];
  11306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11307. c++;
  11308. }
  11309. sstr[c] = '\0';
  11310. reservationIdInt = atoi(sstr);
  11311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11312. /*
  11313. enum SYSTEM_STATUS
  11314. {
  11315. SYS_MODE_BOOTING = 0,
  11316. SYS_MODE_IDLE = 1,
  11317. SYS_MODE_AUTHORIZING = 2,
  11318. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11319. SYS_MODE_REASSIGN = 4,
  11320. SYS_MODE_PREPARING = 5,
  11321. SYS_MODE_PREPARE_FOR_EV = 6,
  11322. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11323. SYS_MODE_CHARGING = 8,
  11324. SYS_MODE_TERMINATING = 9,
  11325. SYS_MODE_COMPLETE = 10,
  11326. SYS_MODE_ALARM = 11,
  11327. SYS_MODE_FAULT = 12,
  11328. SYS_MODE_RESERVATION = 13,
  11329. SYS_MODE_BOOKING = 14,
  11330. SYS_MODE_MAINTAIN = 15,
  11331. SYS_MODE_DEBUG = 16,
  11332. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11333. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11334. SYS_MODE_UPDATE = 19
  11335. };
  11336. */
  11337. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11338. {
  11339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11340. goto end;
  11341. }
  11342. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11343. {
  11344. //check Transaction active
  11345. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11346. {
  11347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11348. {
  11349. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11350. }
  11351. else
  11352. {
  11353. tempIndex = connectorIdInt -1;
  11354. }
  11355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11356. {
  11357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11358. {
  11359. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11360. {
  11361. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11362. {
  11363. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11364. {
  11365. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11367. }
  11368. 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'))
  11369. {
  11370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11371. }
  11372. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11373. {
  11374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11375. }
  11376. else
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11379. }
  11380. }
  11381. 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
  11382. {
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11384. }
  11385. }
  11386. else
  11387. {
  11388. //replace reservation
  11389. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11391. }
  11392. }
  11393. } // END FOR CHAdeMO_QUANTITY
  11394. }
  11395. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11396. {
  11397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11398. {
  11399. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11400. }
  11401. else
  11402. {
  11403. tempIndex = connectorIdInt -1;
  11404. }
  11405. for (int index = 0; index < CCS_QUANTITY; index++)
  11406. {
  11407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11408. {
  11409. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11410. {
  11411. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11412. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11413. {
  11414. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11415. {
  11416. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11418. }
  11419. 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'))
  11420. {
  11421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11422. }
  11423. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11424. {
  11425. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11426. }
  11427. else
  11428. {
  11429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11430. }
  11431. }
  11432. 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
  11433. {
  11434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11435. }
  11436. }
  11437. else
  11438. {
  11439. //replace reservation
  11440. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11442. }
  11443. }
  11444. } // END FOR CCS_QUANTITY
  11445. }
  11446. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11447. {
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11449. {
  11450. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11451. }
  11452. else
  11453. {
  11454. tempIndex = connectorIdInt -1;
  11455. }
  11456. for (int index = 0; index < GB_QUANTITY; index++)
  11457. {
  11458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11459. {
  11460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11461. {
  11462. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11463. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11464. {
  11465. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11466. {
  11467. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11469. }
  11470. 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'))
  11471. {
  11472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11473. }
  11474. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11475. {
  11476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11477. }
  11478. else
  11479. {
  11480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11481. }
  11482. }
  11483. 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
  11484. {
  11485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11486. }
  11487. }
  11488. else
  11489. {
  11490. //replace reservation
  11491. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11493. }
  11494. }
  11495. }// END FOR GB_QUANTITY
  11496. }
  11497. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11498. {
  11499. tempIndex = connectorIdInt -1;
  11500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11501. {
  11502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11503. {
  11504. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11505. {
  11506. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11507. 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
  11508. {
  11509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11510. {
  11511. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11513. }
  11514. 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'))
  11515. {
  11516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11517. }
  11518. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11519. {
  11520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11521. }
  11522. else
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11525. }
  11526. }
  11527. 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
  11528. {
  11529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11530. }
  11531. }
  11532. else
  11533. {
  11534. //replace reservation
  11535. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11537. }
  11538. }
  11539. }// END FOR GB_QUANTITY
  11540. }
  11541. else
  11542. {
  11543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11544. {
  11545. tempIndex = 2;
  11546. }
  11547. else
  11548. {
  11549. tempIndex = (connectorIdInt -1);
  11550. }
  11551. for (int index = 0; index < AC_QUANTITY; index++)
  11552. {
  11553. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11554. {
  11555. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11556. {
  11557. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11558. {
  11559. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11560. {
  11561. 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))
  11562. {
  11563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11564. }
  11565. else
  11566. {
  11567. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11569. }
  11570. }
  11571. 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'))
  11572. {
  11573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11574. }
  11575. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11576. {
  11577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11578. }
  11579. else
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11582. }
  11583. }
  11584. 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
  11585. {
  11586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11587. }
  11588. }
  11589. else
  11590. {
  11591. //replace reservation
  11592. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11594. }
  11595. }
  11596. } // END FOR AC_QUANTITY
  11597. }
  11598. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11599. }
  11600. else if(connectorIdInt == 0)
  11601. {
  11602. //check Transaction active
  11603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11604. {
  11605. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11606. {
  11607. 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'))
  11608. {
  11609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11610. goto end;
  11611. }
  11612. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11613. {
  11614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11615. goto end;
  11616. }
  11617. 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
  11618. {
  11619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11620. goto end;
  11621. }
  11622. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11623. {
  11624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11625. goto end;
  11626. }
  11627. }
  11628. }// END FOR CHAdeMO_QUANTITY
  11629. for (int index = 0; index < CCS_QUANTITY; index++)
  11630. {
  11631. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11632. {
  11633. 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'))
  11634. {
  11635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11636. goto end;
  11637. }
  11638. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11639. {
  11640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11641. goto end;
  11642. }
  11643. 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
  11644. {
  11645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11646. goto end;
  11647. }
  11648. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11649. {
  11650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11651. goto end;
  11652. }
  11653. }
  11654. } // END FOR CCS_QUANTITY
  11655. for (int index = 0; index < GB_QUANTITY; index++)
  11656. {
  11657. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11658. {
  11659. 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'))
  11660. {
  11661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11662. goto end;
  11663. }
  11664. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11665. {
  11666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11667. goto end;
  11668. }
  11669. 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
  11670. {
  11671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11672. goto end;
  11673. }
  11674. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11675. {
  11676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11677. goto end;
  11678. }
  11679. }
  11680. } // END FOR GB_QUANTITY
  11681. for (int index = 0; index < AC_QUANTITY; index++)
  11682. {
  11683. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11684. {
  11685. 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'))
  11686. {
  11687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11688. goto end;
  11689. }
  11690. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11691. {
  11692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11693. goto end;
  11694. }
  11695. 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
  11696. {
  11697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11698. goto end;
  11699. }
  11700. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11701. {
  11702. 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))
  11703. {
  11704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11705. goto end;
  11706. }
  11707. }
  11708. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11709. {
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11711. goto end;
  11712. }
  11713. }
  11714. }// END FOR AC_QUANTITY
  11715. //The connectorId is 0
  11716. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11718. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11719. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11720. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11721. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11722. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11723. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11724. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11725. result = TRUE;
  11726. return result;
  11727. }
  11728. else
  11729. {
  11730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11731. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11732. }
  11733. if(strcmp(comfirmstr,"Accepted") == 0)
  11734. {
  11735. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11736. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11737. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11738. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11739. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11740. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11741. result = TRUE;
  11742. return result;
  11743. }
  11744. end:
  11745. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11746. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11747. return result;
  11748. }
  11749. int handleResetRequest(char *uuid, char *payload)
  11750. {
  11751. mtrace();
  11752. int result = FAIL;
  11753. char sstr[10]={0},sstrtemp[30]={ 0 };
  11754. char typestr[10]={0};
  11755. char comfirmstr[20]={0};
  11756. int c = 0;
  11757. char *loc;
  11758. DEBUG_INFO("handleResetRequest...\n");
  11759. strcpy(sstrtemp, stringtrimspace(payload));
  11760. loc = strstr(sstrtemp, "type");
  11761. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11762. c = 0;
  11763. while (loc[3+strlen("type")+c] != '\"')
  11764. {
  11765. sstr[c] = loc[3+strlen("type")+c];
  11766. c++;
  11767. }
  11768. sstr[c] = '\0';
  11769. strcpy(typestr,sstr);
  11770. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11771. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11772. {
  11773. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11774. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11775. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11776. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11777. }
  11778. else
  11779. {
  11780. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11781. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11782. result = PASS;
  11783. }
  11784. sendResetConfirmation(uuid, comfirmstr);
  11785. return result;
  11786. }
  11787. int handleSendLocalListRequest(char *uuid, char *payload)
  11788. {
  11789. mtrace();
  11790. int result = FAIL;
  11791. char comfirmstr[20];
  11792. int checkState_Faulted = FALSE;
  11793. json_object *SendLocalList;
  11794. DEBUG_INFO("handleSendLocalListRequest...\n");
  11795. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11796. {
  11797. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11798. goto end;
  11799. }
  11800. //check Charge Point state
  11801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11802. {
  11803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11804. {
  11805. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11806. }
  11807. }
  11808. for (int index = 0; index < CCS_QUANTITY; index++)
  11809. {
  11810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11811. {
  11812. checkState_Faulted = TRUE; //OCPP Status
  11813. }
  11814. }
  11815. for (int index = 0; index < GB_QUANTITY; index++)
  11816. {
  11817. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11818. {
  11819. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11820. }
  11821. }
  11822. //check Charge Point state
  11823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11824. {
  11825. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11826. {
  11827. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11828. }
  11829. }
  11830. //check Charge Point state
  11831. for (int index = 0; index < AC_QUANTITY; index++)
  11832. {
  11833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11834. {
  11835. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11836. }
  11837. }
  11838. if(checkState_Faulted == TRUE)
  11839. {
  11840. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11841. goto end;
  11842. }
  11843. // Parsing payload
  11844. SendLocalList = json_tokener_parse(payload);
  11845. if(!is_error(SendLocalList))
  11846. {
  11847. // Required data
  11848. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11849. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11850. // Optional data
  11851. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11852. {
  11853. //Check UpdateType
  11854. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11855. {
  11856. //Local list full update
  11857. DEBUG_INFO("Local list full update.\n");
  11858. OCPP_getListVerion();
  11859. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11860. {
  11861. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11862. goto end;
  11863. }
  11864. OCPP_cleanLocalList();
  11865. }
  11866. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11867. {
  11868. //Local list different update
  11869. DEBUG_INFO("Local list different update.\n");
  11870. OCPP_getListVerion();
  11871. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11872. {
  11873. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11874. goto end;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11880. goto end;
  11881. }
  11882. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11883. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11884. {
  11885. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11886. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11887. {
  11888. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11889. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11890. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11891. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11892. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11893. }
  11894. // Add to db
  11895. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11896. {
  11897. //Local list full update
  11898. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11899. idx,
  11900. ShmOCPP16Data->SendLocalList.ListVersion,
  11901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11902. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11903. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11904. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11905. // update list
  11906. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11907. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11908. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11909. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11910. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11911. }
  11912. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11913. {
  11914. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11915. idx,
  11916. ShmOCPP16Data->SendLocalList.ListVersion,
  11917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11918. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11921. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11922. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11923. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11924. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11925. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11926. }
  11927. }
  11928. }
  11929. else
  11930. {
  11931. //Check UpdateType
  11932. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11933. {
  11934. //Local list full update
  11935. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11936. OCPP_cleanLocalList();
  11937. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11938. goto end;
  11939. }
  11940. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11941. {
  11942. //Local list different update
  11943. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11944. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11945. goto end;
  11946. }
  11947. }
  11948. result = PASS;
  11949. }
  11950. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11951. end:
  11952. json_object_put(SendLocalList);
  11953. sendSendLocalListConfirmation(uuid, comfirmstr);
  11954. return result;
  11955. }
  11956. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11957. {
  11958. mtrace();
  11959. int result = FAIL;
  11960. struct StructSetChargingProfile SetProfileReq = {0};
  11961. int tempchargingProfileIdInt;
  11962. int chargingSchedulePeriodCount = 0;
  11963. char comfirmstr[20]={0};
  11964. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11965. char rmFileCmd[128]={0};
  11966. int profileQuantity = 0;
  11967. json_object *SetChargingProfile;
  11968. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11969. SetChargingProfile = json_tokener_parse(payload);
  11970. if(!is_error(SetChargingProfile))
  11971. {
  11972. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11973. {
  11974. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11975. }
  11976. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11977. {
  11978. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11979. {
  11980. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11981. }
  11982. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11983. {
  11984. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11985. }
  11986. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11987. {
  11988. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11989. }
  11990. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11991. {
  11992. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11993. }
  11994. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11995. {
  11996. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11997. }
  11998. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11999. {
  12000. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12001. }
  12002. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12003. {
  12004. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12005. }
  12006. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12007. {
  12008. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12009. }
  12010. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12011. {
  12012. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12013. {
  12014. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12015. }
  12016. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12017. {
  12018. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12019. }
  12020. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12021. {
  12022. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12023. }
  12024. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12025. {
  12026. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12027. }
  12028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12029. {
  12030. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12031. if(chargingSchedulePeriodCount <= 10)
  12032. {
  12033. 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++)
  12034. {
  12035. 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)
  12036. {
  12037. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12038. }
  12039. 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)
  12040. {
  12041. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12042. }
  12043. 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)
  12044. {
  12045. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12046. }
  12047. }
  12048. }
  12049. }
  12050. }
  12051. }
  12052. }
  12053. // Profile periods quantity check
  12054. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12055. {
  12056. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12057. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12058. goto end;
  12059. }
  12060. // Check invalid limit
  12061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12062. {
  12063. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12064. {
  12065. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12066. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12067. {
  12068. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12069. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12070. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12071. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12072. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12073. goto end;
  12074. }
  12075. }
  12076. }
  12077. else
  12078. {
  12079. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12080. {
  12081. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  12082. {
  12083. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12084. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12085. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12086. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12087. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12088. goto end;
  12089. }
  12090. }
  12091. }
  12092. // Profile purpose info check
  12093. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12094. {
  12095. FILE *fp;
  12096. char dataLine[4096]={0};
  12097. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12098. if(SetProfileReq.ConnectorId != 0)
  12099. {
  12100. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12101. DEBUG_WARN("Profile connector id is not 0.\n");
  12102. goto end;
  12103. }
  12104. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12105. if (!fp)
  12106. {
  12107. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12108. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12109. }
  12110. else
  12111. {
  12112. while(fscanf(fp, "%s", dataLine) != EOF)
  12113. {
  12114. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12115. {
  12116. profileQuantity += 1;
  12117. }
  12118. }
  12119. }
  12120. fclose(fp);
  12121. }
  12122. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12123. {
  12124. FILE *fp;
  12125. char dataLine[4096]={0};
  12126. char filename[128]={0};
  12127. int tmpProfileQuantity;
  12128. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12129. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12130. {
  12131. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12132. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12133. goto end;
  12134. }
  12135. if(SetProfileReq.ConnectorId == 0)
  12136. {
  12137. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12138. {
  12139. tmpProfileQuantity = 0;
  12140. memset(filename, 0, ARRAY_SIZE(filename));
  12141. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12142. fp = fopen(filename, "r");
  12143. if (!fp)
  12144. {
  12145. DEBUG_INFO("%s does not create.\n", filename);
  12146. fp = fopen(filename, "w+");
  12147. }
  12148. else
  12149. {
  12150. while(fscanf(fp, "%s", dataLine) != EOF)
  12151. {
  12152. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12153. {
  12154. tmpProfileQuantity += 1;
  12155. }
  12156. }
  12157. }
  12158. fclose(fp);
  12159. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12160. }
  12161. }
  12162. else
  12163. {
  12164. memset(filename, 0, ARRAY_SIZE(filename));
  12165. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12166. fp = fopen(filename, "r");
  12167. if (!fp)
  12168. {
  12169. DEBUG_INFO("%s does not create.\n", filename);
  12170. fp = fopen(filename, "w+");
  12171. }
  12172. else
  12173. {
  12174. while(fscanf(fp, "%s", dataLine) != EOF)
  12175. {
  12176. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12177. {
  12178. profileQuantity += 1;
  12179. }
  12180. }
  12181. }
  12182. fclose(fp);
  12183. }
  12184. }
  12185. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12186. {
  12187. int isMatchTransactiodId= FALSE;
  12188. FILE *fp;
  12189. char dataLine[4096]={0};
  12190. char filename[128]={0};
  12191. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12192. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12193. if(SetProfileReq.ConnectorId == 0)
  12194. {
  12195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12196. DEBUG_WARN("Profile connector id is 0.\n");
  12197. goto end;
  12198. }
  12199. int tempIndex = 0;
  12200. //check Transaction active
  12201. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12202. {
  12203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12204. {
  12205. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12206. }
  12207. else
  12208. {
  12209. tempIndex = SetProfileReq.ConnectorId -1;
  12210. }
  12211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12212. {
  12213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12214. {
  12215. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12216. {
  12217. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12218. {
  12219. isMatchTransactiodId = TRUE;
  12220. break;
  12221. }
  12222. }
  12223. }
  12224. }
  12225. }
  12226. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12227. {
  12228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12229. {
  12230. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12231. }
  12232. else
  12233. {
  12234. tempIndex = SetProfileReq.ConnectorId -1;
  12235. }
  12236. for (int index = 0; index < CCS_QUANTITY; index++)
  12237. {
  12238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12239. {
  12240. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12241. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12242. {
  12243. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12244. {
  12245. isMatchTransactiodId = TRUE;
  12246. break;
  12247. }
  12248. }
  12249. }
  12250. }
  12251. }
  12252. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12253. {
  12254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12255. {
  12256. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12257. }
  12258. else
  12259. {
  12260. tempIndex = SetProfileReq.ConnectorId -1;
  12261. }
  12262. for (int index = 0; index < GB_QUANTITY; index++)
  12263. {
  12264. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12265. {
  12266. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12267. {
  12268. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12269. {
  12270. isMatchTransactiodId = TRUE;
  12271. break;
  12272. }
  12273. }
  12274. }
  12275. }
  12276. }
  12277. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12278. {
  12279. tempIndex = SetProfileReq.ConnectorId -1;
  12280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12281. {
  12282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12283. {
  12284. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12285. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12286. {
  12287. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12288. {
  12289. isMatchTransactiodId = TRUE;
  12290. break;
  12291. }
  12292. }
  12293. }
  12294. }
  12295. }
  12296. else
  12297. {
  12298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12299. {
  12300. tempIndex = 2;
  12301. }
  12302. else
  12303. {
  12304. tempIndex = (SetProfileReq.ConnectorId -1);
  12305. }
  12306. for (int index = 0; index < AC_QUANTITY; index++)
  12307. {
  12308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12309. {
  12310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12311. {
  12312. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12313. {
  12314. isMatchTransactiodId = TRUE;
  12315. break;
  12316. }
  12317. }
  12318. }
  12319. }
  12320. }
  12321. //check Transaction active
  12322. if(isMatchTransactiodId == FALSE)
  12323. {
  12324. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12325. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12326. goto end;
  12327. }
  12328. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12329. {
  12330. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12331. DEBUG_WARN("Connector id is over max gun number.\n");
  12332. goto end;
  12333. }
  12334. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12335. fp = fopen(filename, "r");
  12336. if (!fp)
  12337. {
  12338. DEBUG_INFO("%s does not create.\n", filename);
  12339. fp = fopen(filename, "w+");
  12340. }
  12341. else
  12342. {
  12343. //Check Charging Profile Count
  12344. while(fscanf(fp, "%s", dataLine) != EOF)
  12345. {
  12346. //DEBUG_INFO("word=%s\n",word);
  12347. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12348. {
  12349. profileQuantity += 1;
  12350. }
  12351. }
  12352. }
  12353. fclose(fp);
  12354. }
  12355. // Check ChargeProfileMaxStackLevel
  12356. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12357. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12358. {
  12359. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12360. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12361. goto end;
  12362. }
  12363. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12364. {
  12365. FILE *fp;
  12366. char dataLine[4096]={0};
  12367. char fnametemp[128]={0};
  12368. int tmpProfileQuantity;
  12369. //Check ChargePointMaxProfile.json exit
  12370. profileQuantity = 0;
  12371. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12372. {
  12373. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12374. //Check Charging Profile Count
  12375. tmpProfileQuantity = 0;
  12376. while(fscanf(fp, "%s", dataLine) != EOF)
  12377. {
  12378. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12379. {
  12380. profileQuantity += 1;
  12381. tmpProfileQuantity += 1;
  12382. }
  12383. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12384. }
  12385. fclose(fp);
  12386. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12387. }
  12388. //Check TxDefaultProfile_%d.json
  12389. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12390. {
  12391. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12392. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12393. if((access(fnametemp,F_OK))!=-1)
  12394. {
  12395. fp = fopen(fnametemp, "r");
  12396. //Check Charging Profile Count
  12397. tmpProfileQuantity = 0;
  12398. while(fscanf(fp, "%s", dataLine) != EOF)
  12399. {
  12400. //DEBUG_INFO("word=%s\n",word);
  12401. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12402. {
  12403. profileQuantity += 1;
  12404. tmpProfileQuantity += 1;
  12405. }
  12406. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12407. }
  12408. fclose(fp);
  12409. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12410. }
  12411. }
  12412. //Check TxProfile_%d.json
  12413. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12414. {
  12415. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12416. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12417. if((access(fnametemp,F_OK))!=-1)
  12418. {
  12419. fp = fopen(fnametemp, "r");
  12420. //Check Charging Profile Count
  12421. tmpProfileQuantity = 0;
  12422. while(fscanf(fp, "%s", dataLine) != EOF)
  12423. {
  12424. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12425. {
  12426. profileQuantity += 1;
  12427. tmpProfileQuantity += 1;
  12428. }
  12429. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12430. }
  12431. fclose(fp);
  12432. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12433. }
  12434. }
  12435. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12436. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12437. {
  12438. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12439. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12440. goto end;
  12441. }
  12442. }
  12443. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12444. //**********************************Write to File********************************************************/
  12445. {
  12446. FILE *infile;
  12447. FILE *outfile;
  12448. char dataLine[4096]={0};
  12449. char filename[128]={0};
  12450. int chkChar=0;
  12451. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12452. {
  12453. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12454. {
  12455. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12456. }
  12457. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12458. {
  12459. if(SetProfileReq.ConnectorId==0)
  12460. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12461. else
  12462. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12463. }
  12464. else
  12465. {
  12466. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12467. }
  12468. infile = fopen (filename, "r");
  12469. outfile = fopen (tempfile, "w");
  12470. chkChar = fgetc(infile);
  12471. rewind(infile);
  12472. if(chkChar == EOF)
  12473. {
  12474. // Profile is empty
  12475. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12476. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12477. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12478. fclose(infile);
  12479. fclose(outfile);
  12480. sprintf(rmFileCmd,"rm -f %s",filename);
  12481. system(rmFileCmd);
  12482. rename(tempfile, filename);
  12483. }
  12484. else
  12485. {
  12486. // Profile is not empty
  12487. int ChargingProfileAdded = FALSE;
  12488. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12489. {
  12490. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12491. json_object *tmpChargingProfile;
  12492. tmpChargingProfile = json_tokener_parse(dataLine);
  12493. if(!is_error(SetChargingProfile))
  12494. {
  12495. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12496. {
  12497. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12498. {
  12499. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12500. }
  12501. }
  12502. }
  12503. json_object_put(tmpChargingProfile);
  12504. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12505. {
  12506. if(ChargingProfileAdded == FALSE)
  12507. {
  12508. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12509. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12510. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12511. ChargingProfileAdded = TRUE;
  12512. }
  12513. }
  12514. else
  12515. {
  12516. fprintf(outfile,"%s\n",dataLine);
  12517. if(ChargingProfileAdded == FALSE)
  12518. {
  12519. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12520. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12521. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12522. ChargingProfileAdded = TRUE;
  12523. }
  12524. }
  12525. } // end of while loop
  12526. fclose(infile);
  12527. fclose(outfile);
  12528. sprintf(rmFileCmd,"rm -f %s",filename);
  12529. system(rmFileCmd);
  12530. rename(tempfile, filename);
  12531. }
  12532. }
  12533. sleep(1);
  12534. result = TRUE;
  12535. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12536. }
  12537. end:
  12538. json_object_put(SetChargingProfile);
  12539. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12540. {
  12541. if(SetProfileReq.ConnectorId == 0)
  12542. {
  12543. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12544. {
  12545. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12546. }
  12547. }
  12548. else
  12549. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12550. }
  12551. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12552. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12553. return result;
  12554. }
  12555. int handleTriggerMessageRequest(char *uuid, char *payload)
  12556. {
  12557. mtrace();
  12558. int result = FAIL;
  12559. int connectorIdIsNULL = FALSE;
  12560. int connectorIdInt =0;
  12561. char sstr[40]={0},sstrtemp[100]={ 0 };
  12562. char requestedMessagestr[40]={0};
  12563. char comfirmstr[20]={0};
  12564. int c = 0;
  12565. char *loc;
  12566. DEBUG_INFO("handleTriggerMessageRequest\n");
  12567. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12568. strcpy(sstrtemp, stringtrimspace(payload));
  12569. c = 0;
  12570. loc = strstr(sstrtemp, "requestedMessage");
  12571. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12572. {
  12573. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12574. c++;
  12575. }
  12576. sstr[c] = '\0';
  12577. strcpy(requestedMessagestr, sstr);
  12578. c = 0;
  12579. loc = strstr(sstrtemp, "connectorId");
  12580. if(loc == NULL)
  12581. {
  12582. connectorIdIsNULL = TRUE;
  12583. }
  12584. else
  12585. {
  12586. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12587. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12588. {
  12589. sstr[c] = loc[strlen("connectorId")+2+c];
  12590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12591. c++;
  12592. }
  12593. sstr[c] = '\0';
  12594. connectorIdInt = atoi(sstr);
  12595. }
  12596. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12597. {
  12598. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12599. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12600. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12601. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12602. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12603. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12604. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12605. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12606. {
  12607. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12608. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12609. return TRUE;
  12610. }
  12611. else
  12612. {
  12613. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12614. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12615. }
  12616. }
  12617. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12618. {
  12619. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12620. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12621. return TRUE;
  12622. }
  12623. //==========================
  12624. // Trigger message
  12625. //==========================
  12626. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12627. {
  12628. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12629. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12630. {
  12631. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12632. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12633. }
  12634. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12635. }
  12636. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12637. {
  12638. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12639. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12640. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12641. }
  12642. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12643. {
  12644. //sendBootNotificationRequest();
  12645. server_sign = FALSE;
  12646. }
  12647. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12648. {
  12649. refreshStartTimer(&clientTime.Heartbeat);
  12650. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12651. }
  12652. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12653. {
  12654. if(connectorIdIsNULL == FALSE)
  12655. {
  12656. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12657. {
  12658. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12659. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12660. }
  12661. }
  12662. else
  12663. {
  12664. for(int idx=0;idx< gunTotalNumber;idx++)
  12665. {
  12666. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12667. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12668. }
  12669. }
  12670. }
  12671. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12672. {
  12673. if(connectorIdIsNULL == FALSE)
  12674. {
  12675. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12676. {
  12677. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12678. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12679. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12680. }
  12681. }
  12682. else
  12683. {
  12684. for(int idx=0;idx< gunTotalNumber;idx++)
  12685. {
  12686. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12687. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12688. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12689. }
  12690. }
  12691. }
  12692. return result;
  12693. }
  12694. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12695. {
  12696. mtrace();
  12697. int result = FAIL;
  12698. int connectorIdInt =0;
  12699. char comfirmstr[20]={0};
  12700. int tempIndex = 0;
  12701. json_object *UnlockConnector;
  12702. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12703. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12704. UnlockConnector = json_tokener_parse(payload);
  12705. if(!is_error(UnlockConnector))
  12706. {
  12707. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12708. {
  12709. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12710. }
  12711. }
  12712. json_object_put(UnlockConnector);
  12713. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12714. if(gunTotalNumber == 0)
  12715. {
  12716. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12717. goto end;
  12718. }
  12719. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12720. {
  12721. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12722. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12723. goto end;
  12724. }
  12725. else
  12726. {
  12727. //check Transaction active
  12728. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12729. {
  12730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12731. {
  12732. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12733. }
  12734. else
  12735. {
  12736. tempIndex = connectorIdInt -1;
  12737. }
  12738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12739. {
  12740. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12741. {
  12742. //stop Transaction
  12743. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12744. }
  12745. }
  12746. }
  12747. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12748. {
  12749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12750. {
  12751. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12752. }
  12753. else
  12754. {
  12755. tempIndex = connectorIdInt -1;
  12756. }
  12757. for (int index = 0; index < CCS_QUANTITY; index++)
  12758. {
  12759. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12760. {
  12761. //stop Transaction
  12762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12763. }
  12764. }
  12765. }
  12766. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12767. {
  12768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12769. {
  12770. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12771. }
  12772. else
  12773. {
  12774. tempIndex = connectorIdInt -1;
  12775. }
  12776. for (int index = 0; index < GB_QUANTITY; index++)
  12777. {
  12778. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12779. {
  12780. //stop Transaction
  12781. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12782. }
  12783. }
  12784. }
  12785. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12786. {
  12787. tempIndex = connectorIdInt -1;
  12788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12789. {
  12790. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12791. {
  12792. //stop Transaction
  12793. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12794. }
  12795. }
  12796. }
  12797. else
  12798. {
  12799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12800. {
  12801. tempIndex = 2;
  12802. }
  12803. else
  12804. {
  12805. tempIndex = connectorIdInt-1;
  12806. }
  12807. for (int index = 0; index < AC_QUANTITY; index++)
  12808. {
  12809. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12810. {
  12811. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12812. }
  12813. }
  12814. }
  12815. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12816. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12817. result = TRUE;
  12818. return result;
  12819. }
  12820. end:
  12821. //json_object_put(obj); --- remove temporally
  12822. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12823. return result;
  12824. }
  12825. static char UpdateFirmwarepayloadData[300]={0};
  12826. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12827. {
  12828. mtrace();
  12829. int result = FAIL;
  12830. pthread_t t;
  12831. sendUpdateFirmwareConfirmation(uuid);
  12832. memset(UpdateFirmwarepayloadData, 0, 300);
  12833. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12834. if(!interLock.isUpdateFirmwareGoing)
  12835. {
  12836. interLock.isUpdateFirmwareGoing = 1;
  12837. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12838. sleep(1);
  12839. }
  12840. else
  12841. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12842. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12843. return result;
  12844. }
  12845. void *UpdateFirmwareProcess(void *data)
  12846. {
  12847. pthread_detach(pthread_self());
  12848. mtrace();
  12849. int retriesInt =0, retryIntervalInt=0;
  12850. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12851. int port=0;
  12852. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12853. int isSuccess = 0;
  12854. char ftpbuf[1024];
  12855. char temp[1024];
  12856. char * pch;
  12857. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12858. json_object *UpdateFirmware;
  12859. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12860. if(!is_error(UpdateFirmware))
  12861. {
  12862. // Required data
  12863. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12864. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12865. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12866. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12867. // Optional data
  12868. if(json_object_object_get(UpdateFirmware, "retries"))
  12869. {
  12870. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12871. }
  12872. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12873. {
  12874. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12875. }
  12876. }
  12877. json_object_put(UpdateFirmware);
  12878. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12879. memset(path, 0, ARRAY_SIZE(path));
  12880. // Wait retrieveData
  12881. if(strlen(retrieveDatestr) > 10)
  12882. {
  12883. do
  12884. {
  12885. sleep(1);
  12886. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12887. }
  12888. // Ready to download
  12889. system("rm -f /mnt/*");
  12890. if(strncmp(locationstr,"http", 4) == 0)
  12891. {
  12892. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12893. sprintf(ftppath,"/%s", path);
  12894. DEBUG_INFO("locationstr: %s\n", locationstr);
  12895. DEBUG_INFO("protocol: %s\n",protocol);
  12896. DEBUG_INFO("host: %s\n",host);
  12897. DEBUG_INFO("path: %s\n",path);
  12898. DEBUG_INFO("ftppath: %s\n",ftppath);
  12899. int ftppathlen=strlen(ftppath);
  12900. int i=1;
  12901. char filenametemp[50];
  12902. while(i < ftppathlen)
  12903. {
  12904. int len=ftppathlen-i;
  12905. if(ftppath[len]== 47) // '/' ascll code: 47
  12906. {
  12907. DEBUG_INFO("compare '/' all right\n");
  12908. break;
  12909. }
  12910. i=i+1;
  12911. }
  12912. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12913. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12914. filenametemp[i+1] = 0;
  12915. do
  12916. {
  12917. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12918. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12919. sleep(1);
  12920. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12921. if(!isSuccess)
  12922. {
  12923. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12924. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12925. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12926. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12927. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12928. }
  12929. else
  12930. {
  12931. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12932. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12933. }
  12934. retriesInt--;
  12935. }while((isSuccess == 0)&&(retriesInt >= 0));
  12936. }
  12937. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12938. {
  12939. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12940. memset(temp, 0, ARRAY_SIZE(temp));
  12941. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12942. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12943. int ftppathlen=strlen(ftpbuf);
  12944. int i=1;
  12945. char filenametemp[50];
  12946. while(i < ftppathlen)
  12947. {
  12948. int len=ftppathlen-i;
  12949. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12950. {
  12951. DEBUG_INFO(" compare '/' all right\n");
  12952. break;
  12953. }
  12954. i=i+1;
  12955. }
  12956. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12957. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12958. filenametemp[i+1] = 0;
  12959. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12960. pch=strchr(temp,'@');
  12961. if(pch==NULL)
  12962. {
  12963. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12964. protocol, host, &port, path);
  12965. strcpy(user,"anonymous");
  12966. strcpy(password,"");
  12967. }
  12968. else
  12969. {
  12970. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12971. protocol, user, password, host, &port, path);
  12972. }
  12973. sscanf(host,"%[^/]%s",host1, path1);
  12974. sprintf(ftppath,"%s", path1);
  12975. //DEBUG_INFO("protocol =%s\n",protocol);
  12976. //DEBUG_INFO("user =%s\n",user);
  12977. //DEBUG_INFO("password =%s\n",password);
  12978. //DEBUG_INFO("host1 =%s\n",host1);
  12979. //DEBUG_INFO("port =%d\n",port);
  12980. //DEBUG_INFO("path1 =%s\n",path1);
  12981. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12982. //ftpFile(host, user, password, port, ftppath, fname);
  12983. //download firmware pthred
  12984. if(port == 0)
  12985. {
  12986. port = 21;
  12987. }
  12988. do
  12989. {
  12990. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12991. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12992. sleep(1);
  12993. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12994. if(!isSuccess)
  12995. {
  12996. //BulldogUtil.sleepMs(interval*1000);
  12997. DEBUG_INFO("Update firmware request and download file fail.\n");
  12998. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12999. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13000. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13001. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13002. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13003. }
  13004. else
  13005. {
  13006. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13007. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13008. }
  13009. retriesInt--;
  13010. }while((!isSuccess)&&(retriesInt >= 0));
  13011. }
  13012. else
  13013. {
  13014. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13015. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13016. sleep(1);
  13017. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13018. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13019. }
  13020. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13021. interLock.isUpdateFirmwareGoing = 0;
  13022. pthread_exit(NULL);
  13023. }
  13024. int handleCertificateSignedRequest(char *uuid, char *payload)
  13025. {
  13026. mtrace();
  13027. int result = PASS;
  13028. json_object *CertificateSigned;
  13029. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13030. CertificateSigned = json_tokener_parse(payload);
  13031. if(!is_error(CertificateSigned))
  13032. {
  13033. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13034. }
  13035. json_object_put(CertificateSigned);
  13036. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13037. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13038. fclose(fp);
  13039. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13040. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13041. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13042. sendCertificateSignedConfirmation(uuid);
  13043. return result;
  13044. }
  13045. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13046. {
  13047. mtrace();
  13048. int result = PASS;
  13049. json_object *DeleteCertificate;
  13050. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13051. DeleteCertificate = json_tokener_parse(payload);
  13052. if(!is_error(DeleteCertificate))
  13053. {
  13054. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13055. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13056. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13057. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13058. }
  13059. json_object_put(DeleteCertificate);
  13060. /*
  13061. * TODO: Delete certificateSigned process
  13062. */
  13063. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13064. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13065. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13066. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13067. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13068. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13069. sendDeleteCertificateConfirmation(uuid);
  13070. return result;
  13071. }
  13072. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13073. {
  13074. mtrace();
  13075. int result = PASS;
  13076. json_object *ExtendedTriggerMessage;
  13077. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13078. ExtendedTriggerMessage = json_tokener_parse(payload);
  13079. if(!is_error(ExtendedTriggerMessage))
  13080. {
  13081. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13082. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13083. {
  13084. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13085. }
  13086. else
  13087. {
  13088. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13089. }
  13090. }
  13091. json_object_put(ExtendedTriggerMessage);
  13092. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13093. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13094. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13095. {
  13096. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13097. }
  13098. else
  13099. {
  13100. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13101. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13102. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13103. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13104. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13105. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13106. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13107. {
  13108. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13109. }
  13110. else
  13111. {
  13112. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13113. }
  13114. }
  13115. sendExtendedTriggerMessageConfirmation(uuid);
  13116. //==========================
  13117. // Trigger message
  13118. //==========================
  13119. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13120. {
  13121. //sendBootNotificationRequest();
  13122. server_sign = FALSE;
  13123. }
  13124. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13125. {
  13126. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13127. }
  13128. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13129. {
  13130. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13131. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13132. {
  13133. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13134. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13135. }
  13136. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13137. }
  13138. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13139. {
  13140. refreshStartTimer(&clientTime.Heartbeat);
  13141. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13142. }
  13143. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13144. {
  13145. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13146. {
  13147. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13148. }
  13149. else
  13150. {
  13151. for(int idx=0;idx< gunTotalNumber;idx++)
  13152. {
  13153. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13154. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13155. }
  13156. }
  13157. }
  13158. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13159. {
  13160. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13161. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13162. {
  13163. 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\" &");
  13164. }
  13165. }
  13166. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13167. {
  13168. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13169. {
  13170. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13171. }
  13172. else
  13173. {
  13174. for(int idx=0;idx< gunTotalNumber;idx++)
  13175. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13176. }
  13177. }
  13178. return result;
  13179. }
  13180. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13181. {
  13182. mtrace();
  13183. int result = PASS;
  13184. json_object *GetInstalledCertificateIds;
  13185. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13186. GetInstalledCertificateIds = json_tokener_parse(payload);
  13187. if(!is_error(GetInstalledCertificateIds))
  13188. {
  13189. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13190. }
  13191. json_object_put(GetInstalledCertificateIds);
  13192. /*
  13193. * TODO: Return installed certificate process
  13194. */
  13195. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13196. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13197. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13198. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13199. sendGetInstalledCertificateIdsConfirmation(uuid);
  13200. return result;
  13201. }
  13202. int handleGetLogRequest(char *uuid, char *payload)
  13203. {
  13204. mtrace();
  13205. int result = PASS;
  13206. json_object *GetLog;
  13207. DEBUG_INFO("handleGetLogRequest...\n");
  13208. GetLog = json_tokener_parse(payload);
  13209. if(!is_error(GetLog))
  13210. {
  13211. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13212. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13213. if(json_object_object_get(GetLog, "retries") != NULL)
  13214. {
  13215. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13216. }
  13217. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13218. {
  13219. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13220. }
  13221. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13222. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13223. {
  13224. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13225. }
  13226. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13227. {
  13228. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13229. }
  13230. }
  13231. json_object_put(GetLog);
  13232. /*
  13233. * TODO: Upload log process
  13234. */
  13235. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13236. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13237. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13238. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13239. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13240. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13241. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13242. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13243. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13244. sendGetLogConfirmation(uuid);
  13245. return result;
  13246. }
  13247. int handleInstallCertificateRequest(char *uuid, char *payload)
  13248. {
  13249. mtrace();
  13250. int result = PASS;
  13251. json_object *InstallCertificate;
  13252. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13253. InstallCertificate = json_tokener_parse(payload);
  13254. if(!is_error(InstallCertificate))
  13255. {
  13256. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13257. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13258. /*
  13259. * TODO: Install certificate process
  13260. */
  13261. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13262. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13263. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13264. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13265. sendInstallCertificateConfirmation(uuid);
  13266. }
  13267. json_object_put(InstallCertificate);
  13268. return result;
  13269. }
  13270. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13271. {
  13272. mtrace();
  13273. int result = PASS;
  13274. json_object *SignedUpdateFirmware;
  13275. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13276. SignedUpdateFirmware = json_tokener_parse(payload);
  13277. if(!is_error(SignedUpdateFirmware))
  13278. {
  13279. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13280. {
  13281. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13282. }
  13283. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13284. {
  13285. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13286. }
  13287. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13288. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13289. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13290. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13291. {
  13292. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13293. }
  13294. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13295. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13296. }
  13297. json_object_put(SignedUpdateFirmware);
  13298. /*
  13299. * TODO: Upgrade firmware process
  13300. */
  13301. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13302. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13303. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13304. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13305. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13306. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13307. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13308. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13309. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13310. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13311. sendInstallCertificateConfirmation(uuid);
  13312. return result;
  13313. }
  13314. int handleUnknownRequest(char *uuid, char *payload)
  13315. {
  13316. mtrace();
  13317. int result = PASS;
  13318. DEBUG_INFO("handleUnknownRequest...\n");
  13319. sendUnknownConfirmation(uuid);
  13320. result = PASS;
  13321. return result;
  13322. }
  13323. //==========================================
  13324. // Handle server response routine
  13325. //==========================================
  13326. void handleAuthorizeResponse(char *payload, int gun_index)
  13327. {
  13328. mtrace();
  13329. char expiryDatestr[30]={0};
  13330. char parentIdTagstr[20]={0};
  13331. char statusstr[20]={0};
  13332. int expiryDateISNULL=FALSE;
  13333. int parentIdTagISNULL=FALSE;
  13334. DEBUG_INFO("handleAuthorizeResponse...\n");
  13335. json_object *Authorize;
  13336. Authorize = json_tokener_parse(payload);
  13337. if(!is_error(Authorize))
  13338. {
  13339. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13340. {
  13341. // Required data
  13342. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13343. // Optional data
  13344. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13345. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13346. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13347. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13348. }
  13349. }
  13350. json_object_put(Authorize);
  13351. if(expiryDateISNULL == FALSE)
  13352. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13353. if(parentIdTagISNULL == FALSE)
  13354. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13355. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13356. //Update idTag information to authorization cache if supproted
  13357. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13358. {
  13359. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13360. }
  13361. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13362. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13363. authorizeRetryTimes = 0;
  13364. }
  13365. void handleBootNotificationResponse(char *payload, int gun_index)
  13366. {
  13367. mtrace();
  13368. char statusStr[12]={0};
  13369. char currentTimeStr[30]={0};
  13370. int intervalInt = 0;
  13371. DEBUG_INFO("handleBootNotificationResponse...\n");
  13372. json_object *BootNotification;
  13373. BootNotification = json_tokener_parse(payload);
  13374. if(!is_error(BootNotification))
  13375. {
  13376. // Required data
  13377. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13378. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13379. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13380. }
  13381. json_object_put(BootNotification);
  13382. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13383. BootNotificationInterval = intervalInt;
  13384. //write back to ShmOCPP16Data->BootNotification
  13385. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13386. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13387. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13388. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13389. {
  13390. if((intervalInt == 0) || (intervalInt >= 10))
  13391. {
  13392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13393. HeartBeatWaitTime = intervalInt;
  13394. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13395. }
  13396. server_sign = TRUE;
  13397. server_pending =FALSE;
  13398. }
  13399. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13400. {
  13401. server_pending = TRUE;
  13402. }
  13403. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13404. srand(time(NULL));
  13405. refreshStartTimer(&clientTime.Heartbeat);
  13406. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13407. SetOcppConnStatus(TRUE);
  13408. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13409. }
  13410. void handleDataTransferResponse(char *payload, int gun_index)
  13411. {
  13412. json_object *DataTransfer = json_tokener_parse(payload);
  13413. if(!is_error(DataTransfer))
  13414. {
  13415. // Required data
  13416. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13417. // Optional data
  13418. if(json_object_object_get(DataTransfer, "data") != NULL)
  13419. {
  13420. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13421. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13422. if(!is_error(Data))
  13423. {
  13424. if(json_object_object_get(Data, "msgId") != NULL)
  13425. {
  13426. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13427. {
  13428. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13429. }
  13430. }
  13431. }
  13432. json_object_put(Data);
  13433. }
  13434. }
  13435. json_object_put(DataTransfer);
  13436. }
  13437. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13438. {
  13439. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13440. //struct json_object *obj;
  13441. // obj = json_tokener_parse(payload);
  13442. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13443. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13444. //No fields are defined.
  13445. }
  13446. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13447. {
  13448. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13449. //struct json_object *obj;
  13450. // obj = json_tokener_parse(payload);
  13451. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13452. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13453. //No fields are defined.
  13454. }
  13455. void handleHeartbeatResponse(char *payload, int gun_index)
  13456. {
  13457. mtrace();
  13458. DEBUG_INFO("handleHeartbeatResponse...\n");
  13459. json_object *Heartbeat;
  13460. Heartbeat = json_tokener_parse(payload);
  13461. if(!is_error(Heartbeat))
  13462. {
  13463. // Required data
  13464. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13465. }
  13466. json_object_put(Heartbeat);
  13467. if(FirstHeartBeat == 0)
  13468. {
  13469. FirstHeartBeat = 1;
  13470. DEBUG_INFO("FirstHeartBeat \n");
  13471. }
  13472. HeartBeatWithNOResponse = 0;
  13473. refreshStartTimer(&clientTime.Heartbeat);
  13474. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13475. }
  13476. void handleMeterValuesResponse(char *payload, int gun_index)
  13477. {
  13478. mtrace();
  13479. DEBUG_INFO("handleMeterValuesResponse...\n");
  13480. isQueueSendable = 1;
  13481. }
  13482. void handleStartTransactionResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. //int transactionIdInt = 0;
  13486. FILE *outfile;
  13487. char data[100]={0};
  13488. DEBUG_INFO("handleStartTransactionResponse...\n");
  13489. json_object *StartTransaction;
  13490. StartTransaction = json_tokener_parse(payload);
  13491. if(!is_error(StartTransaction))
  13492. {
  13493. // Required data
  13494. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13495. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13496. // Optional data
  13497. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13498. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13499. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13500. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13501. }
  13502. json_object_put(StartTransaction);
  13503. isQueueSendable = 1;
  13504. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13505. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13506. //-----------Start : write to the Queue TransactionId file -----------------//
  13507. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13508. {}
  13509. else
  13510. {
  13511. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13512. if(log == NULL)
  13513. {
  13514. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13515. return ;
  13516. }
  13517. else
  13518. {
  13519. fclose(log);
  13520. }
  13521. }
  13522. // open file for writing
  13523. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13524. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13525. {
  13526. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13527. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13528. fputs(data, outfile);
  13529. fclose (outfile);
  13530. }
  13531. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13532. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13533. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13534. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13535. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13536. }
  13537. void handleStatusNotificationResponse(char *payload, int gun_index)
  13538. {
  13539. mtrace();
  13540. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13541. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13543. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13544. }
  13545. void handleStopTransactionnResponse(char *payload, int gun_index)
  13546. {
  13547. mtrace();
  13548. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13549. json_object *StopTransaction;
  13550. StopTransaction = json_tokener_parse(payload);
  13551. if(!is_error(StopTransaction))
  13552. {
  13553. // Optional data
  13554. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13555. {
  13556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13557. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13559. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13561. }
  13562. }
  13563. json_object_put(StopTransaction);
  13564. isQueueSendable = 1;
  13565. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13566. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13567. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13568. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13569. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13570. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13571. }
  13572. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13573. {
  13574. mtrace();
  13575. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13576. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13577. }
  13578. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13579. {
  13580. mtrace();
  13581. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13582. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13583. }
  13584. void handleSignCertificateResponse(char *payload, int gun_index)
  13585. {
  13586. mtrace();
  13587. DEBUG_INFO("handleSignCertificateResponse...\n");
  13588. json_object *SignCertificate;
  13589. SignCertificate = json_tokener_parse(payload);
  13590. if(!is_error(SignCertificate))
  13591. {
  13592. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13593. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13594. }
  13595. json_object_put(SignCertificate);
  13596. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13597. }
  13598. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13599. {
  13600. mtrace();
  13601. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13602. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13603. }
  13604. //==========================================
  13605. // Handle Error routine
  13606. //==========================================
  13607. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13608. {
  13609. mtrace();
  13610. #ifdef SystemLogMessage
  13611. DEBUG_INFO("errorCode: %s\n", errorCode);
  13612. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13613. DEBUG_INFO("errorDetails: %s\n", payload);
  13614. #endif
  13615. }
  13616. //===============================================
  13617. // Common routine
  13618. //===============================================
  13619. int initialConfigurationTable(void)
  13620. {
  13621. //clock_t start_t, end_t, total_t;
  13622. FILE *fp;
  13623. FILE *outfile;
  13624. char str[512]={0};
  13625. char sstr[256]={0};
  13626. int c = 0;
  13627. char *loc;
  13628. int confVersion = 13;
  13629. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13630. //start_t = clock();
  13631. //printf("Starting of the program, start_t = %ld\n", start_t);
  13632. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13633. // Check configuration file size is correct
  13634. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13635. {
  13636. struct stat st;
  13637. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13638. if(st.st_size < 3100)
  13639. {
  13640. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13641. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13642. }
  13643. }
  13644. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13645. {
  13646. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13647. if(outfile == NULL)
  13648. {
  13649. DEBUG_INFO("Error opening file\n");
  13650. return FALSE;
  13651. }
  13652. /*Core Profile*/
  13653. //AllowOfflineTxForUnknownId
  13654. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13658. //AuthorizationCacheEnabled
  13659. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13663. //AuthorizeRemoteTxRequests
  13664. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13668. //BlinkRepeat
  13669. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13673. //ClockAlignedDataInterval
  13674. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13678. //ConnectionTimeOut
  13679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13683. //GetConfigurationMaxKeys
  13684. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13688. // HeartbeatInterval
  13689. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13693. // LightIntensity
  13694. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13698. // LocalAuthorizeOffline
  13699. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13703. // LocalPreAuthorize
  13704. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13708. // MaxEnergyOnInvalidId
  13709. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13713. // MeterValuesAlignedData
  13714. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13718. else
  13719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13721. // MeterValuesAlignedDataMaxLength
  13722. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13726. else
  13727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13729. // MeterValuesSampledData
  13730. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13734. else
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13737. // MeterValuesSampledDataMaxLength
  13738. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13742. else
  13743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13745. // MeterValueSampleInterval
  13746. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13750. // MinimumStatusDuration
  13751. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13754. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13756. // NumberOfConnectors
  13757. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13760. {
  13761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13762. }
  13763. else
  13764. {
  13765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13766. }
  13767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13768. // ResetRetries
  13769. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13773. // ConnectorPhaseRotation
  13774. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13778. // ConnectorPhaseRotationMaxLength
  13779. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13783. // StopTransactionOnEVSideDisconnect
  13784. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13788. // StopTransactionOnInvalidId
  13789. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13793. // StopTxnAlignedData
  13794. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13798. // StopTxnAlignedDataMaxLength
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13803. // StopTxnSampledData
  13804. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13808. else
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13811. // StopTxnSampledDataMaxLength
  13812. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13815. {
  13816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13817. }
  13818. else
  13819. {
  13820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13821. }
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13823. // SupportedFeatureProfiles
  13824. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13828. // SupportedFeatureProfilesMaxLength
  13829. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13833. // TransactionMessageAttempts
  13834. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13837. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13839. // TransactionMessageRetryInterval
  13840. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13843. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13845. // UnlockConnectorOnEVSideDisconnect
  13846. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13850. // WebSocketPingInterval
  13851. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13855. // QueueOffLineMeterValues
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13860. // AuthorizationKey
  13861. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13865. // SecurityProfile
  13866. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13870. // DefaultPrice
  13871. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13875. // CustomDisplayCostAndPrice
  13876. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13880. // CustomIdleFeeAfterStop
  13881. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13885. // TimeOffset
  13886. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13890. // NextTimeOffsetTransitionDateTime
  13891. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13895. // TimeOffsetNextTransition
  13896. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13900. // SystemUptimeSec
  13901. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13905. // FreeVend
  13906. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13910. // FreeVendIdtag
  13911. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13915. // OcppServer
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13918. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13920. // MaintainServer
  13921. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13923. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13925. // StatusNotificationPeriodically
  13926. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13930. // StatusNotificationInterval
  13931. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13935. // Configuration Version
  13936. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13940. //* Local Auth List Management Profile*/
  13941. #if 0
  13942. //For OCTT Test Case
  13943. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13946. #endif
  13947. #if 1
  13948. //LocalAuthListEnabled
  13949. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13953. #endif
  13954. //LocalAuthListMaxLength
  13955. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13959. //SendLocalListMaxLength
  13960. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13964. //ReserveConnectorZeroSupported
  13965. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13969. //* Smart Charging Profile */
  13970. //ChargeProfileMaxStackLevel
  13971. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13975. // ChargingScheduleAllowedChargingRateUnit
  13976. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13980. // ChargingScheduleMaxPeriods
  13981. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13985. // ConnectorSwitch3to1PhaseSupported
  13986. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13990. // MaxChargingProfilesInstalled
  13991. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13995. fclose(outfile);
  13996. }
  13997. else
  13998. {
  13999. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14000. char keystr[60]={0};
  14001. char readonlystr[10]={0};
  14002. char valuestr[256]={0};
  14003. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14004. if(fp == NULL) {
  14005. DEBUG_INFO("Error opening file");
  14006. return FALSE;
  14007. }
  14008. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14009. {
  14010. //DEBUG_INFO("Get Configuration \n");
  14011. if(strlen(str) > 0)
  14012. {
  14013. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14014. //*************************key*********************************/
  14015. if(strstr(str, "key") != NULL)
  14016. {
  14017. loc = strstr(str, "key");
  14018. c = 0;
  14019. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14020. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14021. {
  14022. sstr[c] = loc[strlen("key")+3+c];
  14023. c++;
  14024. }
  14025. sstr[c] = '\0';
  14026. strcpy(keystr,sstr);
  14027. }
  14028. //*************************readonly*********************************/
  14029. if(strstr(str, "readonly") != NULL)
  14030. {
  14031. loc = strstr(str, "readonly");
  14032. c = 0;
  14033. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14034. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14035. {
  14036. sstr[c] = loc[strlen("readonly")+2+c];
  14037. c++;
  14038. }
  14039. sstr[c] = '\0';
  14040. strcpy(readonlystr,sstr);
  14041. }
  14042. //*************************value*********************************/
  14043. if(strstr(str, "value") != NULL)
  14044. {
  14045. loc = strstr(str, "value");
  14046. c = 0;
  14047. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14048. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14049. {
  14050. sstr[c] = loc[strlen("value")+3+c];
  14051. c++;
  14052. }
  14053. sstr[c] = '\0';
  14054. strcpy(valuestr,sstr);
  14055. }
  14056. // DEBUG_INFO("keystr=%s\n",keystr);
  14057. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14058. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14059. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14060. {
  14061. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14064. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14065. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14066. }
  14067. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14068. {
  14069. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14070. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14072. }
  14073. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14074. {
  14075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14077. }
  14078. if(strcmp(keystr, "BlinkRepeat") == 0)
  14079. {
  14080. //Charger.BlinkRepeat = Integer.parseInt(value);
  14081. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14083. }
  14084. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14085. {
  14086. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14088. }
  14089. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14090. {
  14091. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14093. }
  14094. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14095. {
  14096. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14098. }
  14099. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14100. {
  14101. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14103. HeartBeatWaitTime = atoi(valuestr);
  14104. }
  14105. if(strcmp(keystr, "LightIntensity") == 0)
  14106. {
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14109. }
  14110. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14111. {
  14112. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14114. }
  14115. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14116. {
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14119. }
  14120. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14121. {
  14122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14124. }
  14125. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14126. {
  14127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14129. }
  14130. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14131. {
  14132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14134. }
  14135. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14136. {
  14137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14139. }
  14140. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14141. {
  14142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14144. }
  14145. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14146. {
  14147. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14149. }
  14150. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14151. {
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14154. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14155. }
  14156. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14157. {
  14158. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14160. }
  14161. if(strcmp(keystr, "ResetRetries") == 0)
  14162. {
  14163. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14165. }
  14166. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14167. {
  14168. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14170. }
  14171. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14172. {
  14173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14175. }
  14176. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14177. {
  14178. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14180. }
  14181. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14182. {
  14183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14185. }
  14186. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14187. {
  14188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14190. }
  14191. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14192. {
  14193. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14195. }
  14196. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14197. {
  14198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14200. }
  14201. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14202. {
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14205. }
  14206. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14207. {
  14208. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14210. }
  14211. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14212. {
  14213. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14215. }
  14216. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14217. {
  14218. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14220. TransactionMessageAttemptsValue = atoi(valuestr);
  14221. }
  14222. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14223. {
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14226. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14227. }
  14228. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14229. {
  14230. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14232. }
  14233. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14234. {
  14235. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14237. }
  14238. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14239. {
  14240. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14242. }
  14243. if(strcmp(keystr, "AuthorizationKey") == 0)
  14244. {
  14245. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14248. }
  14249. if(strcmp(keystr, "SecurityProfile") == 0)
  14250. {
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14253. }
  14254. if(strcmp(keystr, "DefaultPrice") == 0)
  14255. {
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14258. }
  14259. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14260. {
  14261. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14263. }
  14264. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14265. {
  14266. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14268. }
  14269. if(strcmp(keystr, "TimeOffset") == 0)
  14270. {
  14271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14273. }
  14274. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14275. {
  14276. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14278. }
  14279. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14280. {
  14281. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14283. }
  14284. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14285. {
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14288. }
  14289. if(strcmp(keystr, "FreeVend") == 0)
  14290. {
  14291. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14293. }
  14294. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14295. {
  14296. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14298. }
  14299. if(strcmp(keystr, "OcppServer") == 0)
  14300. {
  14301. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14302. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14303. }
  14304. if(strcmp(keystr, "MaintainServer") == 0)
  14305. {
  14306. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14307. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14308. }
  14309. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14310. {
  14311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14313. }
  14314. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14315. {
  14316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14318. }
  14319. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14320. {
  14321. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14323. }
  14324. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14325. {
  14326. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14328. }
  14329. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14330. {
  14331. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14333. }
  14334. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14335. {
  14336. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14338. }
  14339. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14340. {
  14341. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14343. }
  14344. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14345. {
  14346. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14348. }
  14349. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14350. {
  14351. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14353. }
  14354. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14355. {
  14356. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14358. }
  14359. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14360. {
  14361. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14363. }
  14364. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14365. {
  14366. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14368. }
  14369. }
  14370. }
  14371. fclose(fp);
  14372. }
  14373. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14374. {
  14375. return PASS;
  14376. }
  14377. else
  14378. {
  14379. return FAIL;
  14380. }
  14381. }
  14382. void StoreConfigurationTable(void)
  14383. {
  14384. FILE *outfile;
  14385. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14386. if(outfile == NULL)
  14387. {
  14388. DEBUG_INFO("Error opening file");
  14389. return ;
  14390. }
  14391. /*Core Profile*/
  14392. //AllowOfflineTxForUnknownId
  14393. /*
  14394. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14395. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14398. */
  14399. //DEBUG_INFO("data=%s\n",data);
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14401. //AuthorizationCacheEnabled
  14402. /*
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14406. */
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14408. //AuthorizeRemoteTxRequests
  14409. /*
  14410. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14413. */
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14415. //BlinkRepeat
  14416. /*
  14417. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14420. */
  14421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14422. //ClockAlignedDataInterval
  14423. /*
  14424. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14427. */
  14428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14429. //ConnectionTimeOut
  14430. /*
  14431. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14434. */
  14435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14436. //GetConfigurationMaxKeys
  14437. /*
  14438. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14441. */
  14442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14443. // HeartbeatInterval
  14444. /*
  14445. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14448. */
  14449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14450. // LightIntensity
  14451. /*
  14452. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14455. */
  14456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14457. // LocalAuthorizeOffline
  14458. /*
  14459. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14462. */
  14463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14464. // LocalPreAuthorize
  14465. /*
  14466. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14469. */
  14470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14471. // MaxEnergyOnInvalidId
  14472. /*
  14473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14476. */
  14477. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14479. // MeterValuesAlignedData
  14480. /*
  14481. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14484. */
  14485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14486. // MeterValuesAlignedDataMaxLength
  14487. /*
  14488. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14491. */
  14492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14493. // MeterValuesSampledData
  14494. /*
  14495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14498. */
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14500. // MeterValuesSampledDataMaxLength
  14501. /*
  14502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14505. */
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14507. // MeterValueSampleInterval
  14508. /*
  14509. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14512. */
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14514. // MinimumStatusDuration
  14515. /*
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14519. */
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14521. // NumberOfConnectors
  14522. /*
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14526. {
  14527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14528. }
  14529. else
  14530. {
  14531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14532. }
  14533. */
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14535. // ResetRetries
  14536. /*
  14537. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14540. */
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14542. // ConnectorPhaseRotation
  14543. /*
  14544. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14547. */
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14549. // ConnectorPhaseRotationMaxLength
  14550. /*
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14556. // StopTransactionOnEVSideDisconnect
  14557. /*
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14563. // StopTransactionOnInvalidId
  14564. /*
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14570. // StopTxnAlignedData
  14571. /*
  14572. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14577. // StopTxnAlignedDataMaxLength
  14578. /*
  14579. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14584. // StopTxnSampledData
  14585. /*
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14591. // StopTxnSampledDataMaxLength
  14592. /*
  14593. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14598. // SupportedFeatureProfiles
  14599. /*
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14605. // SupportedFeatureProfilesMaxLength
  14606. /*
  14607. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14612. // TransactionMessageAttempts
  14613. /*
  14614. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14619. // TransactionMessageRetryInterval
  14620. /*
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14626. // UnlockConnectorOnEVSideDisconnect
  14627. /*
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14633. // WebSocketPingInterval
  14634. /*
  14635. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14640. // QueueOffLineMeterValues
  14641. /*
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14647. // AuthorizationKey
  14648. /*
  14649. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14652. */
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14654. // SecurityProfile
  14655. /*
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14661. // DefaultPrice
  14662. /*
  14663. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14668. // CustomDisplayCostAndPrice
  14669. /*
  14670. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14673. */
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14675. // CustomIdleFeeAfterStop
  14676. /*
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14682. // TimeOffset
  14683. /*
  14684. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14689. // NextTimeOffsetTransitionDateTime
  14690. /*
  14691. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14694. */
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14696. // TimeOffsetNextTransition
  14697. /*
  14698. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14701. */
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14703. // SystemUptimeSec
  14704. /*
  14705. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14708. */
  14709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14710. // FreeVend
  14711. /*
  14712. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14715. */
  14716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14717. // FreeVendIdtag
  14718. /*
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14722. */
  14723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14724. // OcppServer
  14725. /*
  14726. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14729. */
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14731. // MaintainServer
  14732. /*
  14733. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14736. */
  14737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14738. // StatusNotificationPeriodically
  14739. /*
  14740. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14743. */
  14744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14745. // StatusNotificationInterval
  14746. /*
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14750. */
  14751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14752. // ConfigurationVersion
  14753. /*
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14757. */
  14758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14759. //* Local Auth List Management Profile*/
  14760. //LocalAuthListEnabled
  14761. /*
  14762. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14765. */
  14766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14767. //LocalAuthListMaxLength
  14768. /*
  14769. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14772. */
  14773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14774. //SendLocalListMaxLength
  14775. /*
  14776. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14779. */
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14781. //ReserveConnectorZeroSupported
  14782. /*
  14783. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14786. */
  14787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14788. //* Smart Charging Profile */
  14789. //ChargeProfileMaxStackLevel
  14790. /*
  14791. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14794. */
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14796. // ChargingScheduleAllowedChargingRateUnit
  14797. /*
  14798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14801. */
  14802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14803. // ChargingScheduleMaxPeriods
  14804. /*
  14805. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14808. */
  14809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14810. // ConnectorSwitch3to1PhaseSupported
  14811. /*
  14812. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14815. */
  14816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14817. // MaxChargingProfilesInstalled
  14818. /*
  14819. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14822. */
  14823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14824. fclose(outfile);
  14825. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14826. }
  14827. void getKeyValue(char *keyReq)
  14828. {
  14829. int isEmpty = FALSE;
  14830. int isKnowKey = FALSE;
  14831. DEBUG_INFO("keyReq = %s\n", keyReq);
  14832. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14833. isEmpty = TRUE;
  14834. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14835. {
  14836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14847. isKnowKey = TRUE;
  14848. }
  14849. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14850. {
  14851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14856. }
  14857. else
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14860. }
  14861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14862. isKnowKey = TRUE;
  14863. }
  14864. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14865. {
  14866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14871. }
  14872. else
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14875. }
  14876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14877. isKnowKey = TRUE;
  14878. }
  14879. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14937. isKnowKey = TRUE;
  14938. }
  14939. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14952. isKnowKey = TRUE;
  14953. }
  14954. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14961. }
  14962. else
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14965. }
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14967. isKnowKey = TRUE;
  14968. }
  14969. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14970. {
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14974. {
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14976. }
  14977. else
  14978. {
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14980. }
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14982. isKnowKey = TRUE;
  14983. }
  14984. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14985. {
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14989. {
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14991. }
  14992. else
  14993. {
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14995. }
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14997. isKnowKey = TRUE;
  14998. }
  14999. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15000. {
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15004. {
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15006. }
  15007. else
  15008. {
  15009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15010. }
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15012. isKnowKey = TRUE;
  15013. }
  15014. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15019. {
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15021. }
  15022. else
  15023. {
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15025. }
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15027. isKnowKey = TRUE;
  15028. }
  15029. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15030. {
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15034. {
  15035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15036. }
  15037. else
  15038. {
  15039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15040. }
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15042. isKnowKey = TRUE;
  15043. }
  15044. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15045. {
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15049. {
  15050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15051. }
  15052. else
  15053. {
  15054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15055. }
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15057. isKnowKey = TRUE;
  15058. }
  15059. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15060. {
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15064. {
  15065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15066. }
  15067. else
  15068. {
  15069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15070. }
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15072. isKnowKey = TRUE;
  15073. }
  15074. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15075. {
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15079. {
  15080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15081. }
  15082. else
  15083. {
  15084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15085. }
  15086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15087. isKnowKey = TRUE;
  15088. }
  15089. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15094. {
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15096. }
  15097. else
  15098. {
  15099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15100. }
  15101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15102. isKnowKey = TRUE;
  15103. }
  15104. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15109. {
  15110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15111. }
  15112. else
  15113. {
  15114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15115. }
  15116. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15118. isKnowKey = TRUE;
  15119. }
  15120. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15121. {
  15122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15125. {
  15126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15127. }
  15128. else
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15131. }
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15133. isKnowKey = TRUE;
  15134. }
  15135. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15136. {
  15137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15140. {
  15141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15142. }
  15143. else
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15146. }
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15148. isKnowKey = TRUE;
  15149. }
  15150. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15151. {
  15152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15155. {
  15156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15157. }
  15158. else
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15161. }
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15163. isKnowKey = TRUE;
  15164. }
  15165. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15166. {
  15167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15170. {
  15171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15172. }
  15173. else
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15176. }
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15178. isKnowKey = TRUE;
  15179. }
  15180. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15181. {
  15182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15185. {
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15187. }
  15188. else
  15189. {
  15190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15191. }
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15193. isKnowKey = TRUE;
  15194. }
  15195. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15196. {
  15197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15200. {
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15202. }
  15203. else
  15204. {
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15206. }
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15208. isKnowKey = TRUE;
  15209. }
  15210. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15211. {
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15215. {
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15217. }
  15218. else
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15221. }
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15223. isKnowKey = TRUE;
  15224. }
  15225. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15226. {
  15227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15230. {
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15232. }
  15233. else
  15234. {
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15236. }
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15238. isKnowKey = TRUE;
  15239. }
  15240. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15241. {
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15245. {
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15247. }
  15248. else
  15249. {
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15251. }
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15253. isKnowKey = TRUE;
  15254. }
  15255. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15256. {
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15260. {
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15262. }
  15263. else
  15264. {
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15266. }
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15268. isKnowKey = TRUE;
  15269. }
  15270. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15271. {
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15275. {
  15276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15277. }
  15278. else
  15279. {
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15281. }
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15283. isKnowKey = TRUE;
  15284. }
  15285. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15286. {
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15290. {
  15291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15292. }
  15293. else
  15294. {
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15296. }
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15298. isKnowKey = TRUE;
  15299. }
  15300. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15301. {
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15305. {
  15306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15307. }
  15308. else
  15309. {
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15311. }
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15313. isKnowKey = TRUE;
  15314. }
  15315. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15316. {
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15320. {
  15321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15322. }
  15323. else
  15324. {
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15326. }
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15328. isKnowKey = TRUE;
  15329. }
  15330. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15335. {
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15337. }
  15338. else
  15339. {
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15341. }
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15343. isKnowKey = TRUE;
  15344. }
  15345. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15350. {
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15352. }
  15353. else
  15354. {
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15356. }
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15358. isKnowKey = TRUE;
  15359. }
  15360. /*
  15361. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15362. {
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15366. {
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15368. }
  15369. else
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15372. }
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15374. isKnowKey = TRUE;
  15375. }*/
  15376. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15377. {
  15378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15381. {
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15383. }
  15384. else
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15387. }
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15389. isKnowKey = TRUE;
  15390. }
  15391. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15392. {
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15396. {
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15398. }
  15399. else
  15400. {
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15402. }
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15404. isKnowKey = TRUE;
  15405. }
  15406. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15407. {
  15408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15413. }
  15414. else
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15417. }
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15419. isKnowKey = TRUE;
  15420. }
  15421. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15422. {
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15426. {
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15428. }
  15429. else
  15430. {
  15431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15432. }
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15434. isKnowKey = TRUE;
  15435. }
  15436. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15437. {
  15438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15441. {
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15443. }
  15444. else
  15445. {
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15447. }
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15449. isKnowKey = TRUE;
  15450. }
  15451. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15452. {
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15456. {
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15458. }
  15459. else
  15460. {
  15461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15462. }
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15464. isKnowKey = TRUE;
  15465. }
  15466. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15467. {
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15471. {
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15473. }
  15474. else
  15475. {
  15476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15477. }
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15479. isKnowKey = TRUE;
  15480. }
  15481. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15482. {
  15483. struct sysinfo s_info;
  15484. int error = sysinfo(&s_info);
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15488. {
  15489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15490. }
  15491. else
  15492. {
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15494. }
  15495. if(error != 0)
  15496. {
  15497. DEBUG_WARN("System uptime get error: %d\n", error);
  15498. }
  15499. else
  15500. {
  15501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15502. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15503. }
  15504. isKnowKey = TRUE;
  15505. }
  15506. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15507. {
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15511. {
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15513. }
  15514. else
  15515. {
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15517. }
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15519. isKnowKey = TRUE;
  15520. }
  15521. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15522. {
  15523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15526. {
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15528. }
  15529. else
  15530. {
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15532. }
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15534. isKnowKey = TRUE;
  15535. }
  15536. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15537. {
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15541. {
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15543. }
  15544. else
  15545. {
  15546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15547. }
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15549. isKnowKey = TRUE;
  15550. }
  15551. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15552. {
  15553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15556. {
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15558. }
  15559. else
  15560. {
  15561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15562. }
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15564. isKnowKey = TRUE;
  15565. }
  15566. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15567. {
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15571. {
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15573. }
  15574. else
  15575. {
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15577. }
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15579. isKnowKey = TRUE;
  15580. }
  15581. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15586. {
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15588. }
  15589. else
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15592. }
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15594. isKnowKey = TRUE;
  15595. }
  15596. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15601. {
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15603. }
  15604. else
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15607. }
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15609. isKnowKey = TRUE;
  15610. }
  15611. #if 1
  15612. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15616. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15619. }
  15620. else
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15623. }
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15625. isKnowKey = TRUE;
  15626. }
  15627. #endif
  15628. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15629. {
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15632. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15633. {
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15635. }
  15636. else
  15637. {
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15639. }
  15640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15641. isKnowKey = TRUE;
  15642. }
  15643. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15644. {
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15647. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15648. {
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15650. }
  15651. else
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15654. }
  15655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15656. isKnowKey = TRUE;
  15657. }
  15658. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15659. {
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15662. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15663. {
  15664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15665. }
  15666. else
  15667. {
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15669. }
  15670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15671. isKnowKey = TRUE;
  15672. }
  15673. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15674. {
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15677. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15678. {
  15679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15680. }
  15681. else
  15682. {
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15684. }
  15685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15686. isKnowKey = TRUE;
  15687. }
  15688. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15689. {
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15692. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15693. {
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15695. }
  15696. else
  15697. {
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15699. }
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15701. isKnowKey = TRUE;
  15702. }
  15703. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15704. {
  15705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15707. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15708. {
  15709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15710. }
  15711. else
  15712. {
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15714. }
  15715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15716. isKnowKey = TRUE;
  15717. }
  15718. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15719. {
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15722. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15723. {
  15724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15725. }
  15726. else
  15727. {
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15729. }
  15730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15731. isKnowKey = TRUE;
  15732. }
  15733. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15734. {
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15737. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15738. {
  15739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15740. }
  15741. else
  15742. {
  15743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15744. }
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15746. isKnowKey = TRUE;
  15747. }
  15748. //=========================================================
  15749. if(!isEmpty && !isKnowKey)
  15750. {
  15751. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15752. strcpy(unknownkey[UnknownKeynum], keyReq);
  15753. UnknownKeynum = UnknownKeynum + 1;
  15754. }
  15755. }
  15756. void processUnkownKey(void)
  15757. {
  15758. DEBUG_INFO("processUnkownKey...\n");
  15759. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15760. for(int index=0; index < UnknownKeynum; index++)
  15761. {
  15762. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15763. {
  15764. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15765. }
  15766. }
  15767. }
  15768. int setKeyValue(char *key, char *value)
  15769. {
  15770. int isSuccess = NotSupported;
  15771. int check_ascii=0;
  15772. char str[501]={0};
  15773. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15774. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15775. {
  15776. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15778. {
  15779. strcpy(str, (const char*)value);
  15780. for(int i = 0; str[i]; i++){
  15781. str[i] = tolower(str[i]);
  15782. }
  15783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15784. isSuccess = ConfigurationStatus_Accepted;
  15785. }
  15786. else
  15787. {
  15788. isSuccess = ConfigurationStatus_Rejected;
  15789. }
  15790. }
  15791. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15792. {
  15793. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15795. {
  15796. strcpy(str, (const char*)value);
  15797. for(int i = 0; str[i]; i++){
  15798. str[i] = tolower(str[i]);
  15799. }
  15800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15803. }
  15804. else
  15805. {
  15806. isSuccess = ConfigurationStatus_Rejected;
  15807. }
  15808. }
  15809. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15810. {
  15811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15812. {
  15813. strcpy(str, (const char*)value);
  15814. for(int i = 0; str[i]; i++)
  15815. {
  15816. str[i] = tolower(str[i]);
  15817. }
  15818. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15820. isSuccess = ConfigurationStatus_Accepted;
  15821. }
  15822. else
  15823. {
  15824. isSuccess = ConfigurationStatus_Rejected;
  15825. }
  15826. }
  15827. if(strcmp(key, "BlinkRepeat") == 0)
  15828. {
  15829. //Charger.BlinkRepeat = Integer.parseInt(value);
  15830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15831. {
  15832. check_ascii = value[0];
  15833. if( (check_ascii < 48) || (check_ascii > 57) )
  15834. {
  15835. isSuccess = ConfigurationStatus_Rejected;
  15836. }
  15837. else
  15838. {
  15839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15840. isSuccess = ConfigurationStatus_Accepted;
  15841. }
  15842. }
  15843. else
  15844. {
  15845. isSuccess = ConfigurationStatus_Rejected;
  15846. }
  15847. }
  15848. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15849. {
  15850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15851. {
  15852. check_ascii = value[0];
  15853. if( (check_ascii < 48) || (check_ascii > 57) )
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. else
  15858. {
  15859. if((atoi(value) == 0) || (atoi(value) >= 5))
  15860. {
  15861. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15863. isSuccess = ConfigurationStatus_Accepted;
  15864. }
  15865. else
  15866. isSuccess = ConfigurationStatus_Rejected;
  15867. }
  15868. }
  15869. else
  15870. {
  15871. isSuccess = ConfigurationStatus_Rejected;
  15872. }
  15873. }
  15874. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15875. {
  15876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15877. {
  15878. check_ascii = value[0];
  15879. if( (check_ascii < 48) || (check_ascii > 57) )
  15880. {
  15881. isSuccess = ConfigurationStatus_Rejected;
  15882. }
  15883. else
  15884. {
  15885. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15887. isSuccess = ConfigurationStatus_Accepted;
  15888. }
  15889. }
  15890. else
  15891. {
  15892. isSuccess = ConfigurationStatus_Rejected;
  15893. }
  15894. }
  15895. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15896. {
  15897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15898. {
  15899. check_ascii = value[0];
  15900. if( (check_ascii < 48) || (check_ascii > 57) )
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. else
  15905. {
  15906. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15908. isSuccess = ConfigurationStatus_Accepted;
  15909. }
  15910. }
  15911. else
  15912. {
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. }
  15916. if(strcmp(key, "HeartbeatInterval") == 0)
  15917. {
  15918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15919. {
  15920. check_ascii = value[0];
  15921. if( (check_ascii < 48) || (check_ascii > 57) )
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. else
  15926. {
  15927. if((atoi(value) == 0) || (atoi(value) >= 10))
  15928. {
  15929. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15931. HeartBeatWaitTime = atoi(value);
  15932. isSuccess = ConfigurationStatus_Accepted;
  15933. }
  15934. else
  15935. {
  15936. isSuccess = ConfigurationStatus_Rejected;
  15937. }
  15938. }
  15939. }
  15940. else
  15941. {
  15942. isSuccess = ConfigurationStatus_Rejected;
  15943. }
  15944. }
  15945. if(strcmp(key, "LightIntensity") == 0)
  15946. {
  15947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15948. {
  15949. check_ascii = value[0];
  15950. if( (check_ascii < 48) || (check_ascii > 57) )
  15951. {
  15952. isSuccess = ConfigurationStatus_Rejected;
  15953. }
  15954. else
  15955. {
  15956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15957. isSuccess = ConfigurationStatus_Accepted;
  15958. }
  15959. }
  15960. else
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15966. {
  15967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15968. {
  15969. strcpy(str, (const char*)value);
  15970. for(int i = 0; str[i]; i++)
  15971. {
  15972. str[i] = tolower(str[i]);
  15973. }
  15974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15975. isSuccess = ConfigurationStatus_Accepted;
  15976. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15977. }
  15978. else
  15979. {
  15980. isSuccess = ConfigurationStatus_Rejected;
  15981. }
  15982. }
  15983. if(strcmp(key, "LocalPreAuthorize") == 0)
  15984. {
  15985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15986. {
  15987. strcpy(str, (const char*)value);
  15988. for(int i = 0; str[i]; i++)
  15989. {
  15990. str[i] = tolower(str[i]);
  15991. }
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15993. isSuccess = ConfigurationStatus_Accepted;
  15994. }
  15995. else
  15996. {
  15997. isSuccess = ConfigurationStatus_Rejected;
  15998. }
  15999. }
  16000. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16001. {
  16002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16003. {
  16004. check_ascii = value[0];
  16005. if( (check_ascii < 48) || (check_ascii > 57) )
  16006. {
  16007. isSuccess = ConfigurationStatus_Rejected;
  16008. }
  16009. else
  16010. {
  16011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. }
  16015. else
  16016. {
  16017. isSuccess = ConfigurationStatus_Rejected;
  16018. }
  16019. }
  16020. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16021. {
  16022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16023. {
  16024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16025. isSuccess = ConfigurationStatus_Accepted;
  16026. }
  16027. else
  16028. {
  16029. isSuccess = ConfigurationStatus_Rejected;
  16030. }
  16031. }
  16032. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16033. {
  16034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16035. {
  16036. check_ascii = value[0];
  16037. if( (check_ascii < 48) || (check_ascii > 57) )
  16038. {
  16039. isSuccess = ConfigurationStatus_Rejected;
  16040. }
  16041. else
  16042. {
  16043. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16045. isSuccess = ConfigurationStatus_Accepted;
  16046. }
  16047. }
  16048. else
  16049. {
  16050. isSuccess = ConfigurationStatus_Rejected;
  16051. }
  16052. }
  16053. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16054. {
  16055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16056. {
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16058. isSuccess = ConfigurationStatus_Accepted;
  16059. }
  16060. else
  16061. {
  16062. isSuccess = ConfigurationStatus_Rejected;
  16063. }
  16064. }
  16065. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16066. {
  16067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16068. {
  16069. check_ascii = value[0];
  16070. if( (check_ascii < 48) || (check_ascii > 57) )
  16071. {
  16072. isSuccess = ConfigurationStatus_Rejected;
  16073. }
  16074. else
  16075. {
  16076. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16078. isSuccess = ConfigurationStatus_Accepted;
  16079. }
  16080. }
  16081. else
  16082. {
  16083. isSuccess = ConfigurationStatus_Rejected;
  16084. }
  16085. }
  16086. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16087. {
  16088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16089. {
  16090. check_ascii = value[0];
  16091. if( (check_ascii < 48) || (check_ascii > 57) )
  16092. {
  16093. isSuccess = ConfigurationStatus_Rejected;
  16094. }
  16095. else
  16096. {
  16097. if((atoi(value) == 0) || (atoi(value) >= 3))
  16098. {
  16099. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16101. isSuccess = ConfigurationStatus_Accepted;
  16102. }
  16103. else
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. }
  16108. }
  16109. else
  16110. {
  16111. isSuccess = ConfigurationStatus_Rejected;
  16112. }
  16113. }
  16114. if(strcmp(key, "MinimumStatusDuration") == 0)
  16115. {
  16116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16117. {
  16118. check_ascii = value[0];
  16119. if( (check_ascii < 48) || (check_ascii > 57) )
  16120. {
  16121. isSuccess = ConfigurationStatus_Rejected;
  16122. }
  16123. else
  16124. {
  16125. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16126. {
  16127. isSuccess = ConfigurationStatus_Rejected;
  16128. }
  16129. else
  16130. {
  16131. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16133. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16134. isSuccess = ConfigurationStatus_Accepted;
  16135. }
  16136. }
  16137. }
  16138. else
  16139. {
  16140. isSuccess = ConfigurationStatus_Rejected;
  16141. }
  16142. }
  16143. if(strcmp(key, "NumberOfConnectors") == 0)
  16144. {
  16145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16146. {
  16147. check_ascii = value[0];
  16148. if( (check_ascii < 48) || (check_ascii > 57) )
  16149. {
  16150. isSuccess = ConfigurationStatus_Rejected;
  16151. }
  16152. else
  16153. {
  16154. //Charger.ResetRetries = Integer.parseInt(value);
  16155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16156. isSuccess = ConfigurationStatus_Accepted;
  16157. }
  16158. }
  16159. else
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. }
  16164. if(strcmp(key, "ResetRetries") == 0)
  16165. {
  16166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16167. {
  16168. check_ascii = value[0];
  16169. if( (check_ascii < 48) || (check_ascii > 57) )
  16170. {
  16171. isSuccess = ConfigurationStatus_Rejected;
  16172. }
  16173. else
  16174. {
  16175. //Charger.ResetRetries = Integer.parseInt(value);
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16177. isSuccess = ConfigurationStatus_Accepted;
  16178. }
  16179. }
  16180. else
  16181. {
  16182. isSuccess = ConfigurationStatus_Rejected;
  16183. }
  16184. }
  16185. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16186. {
  16187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16188. {
  16189. strcpy(str, (const char*)value);
  16190. for(int i = 0; str[i]; i++)
  16191. {
  16192. str[i] = tolower(str[i]);
  16193. }
  16194. if(strcmp(str, "notapplicable")== 0)
  16195. {
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16197. isSuccess = ConfigurationStatus_Accepted;
  16198. }
  16199. else if(strcmp(str, "unknown")== 0)
  16200. {
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16202. isSuccess = ConfigurationStatus_Accepted;
  16203. }
  16204. else if(strcmp(str, "rst")== 0)
  16205. {
  16206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16207. isSuccess = ConfigurationStatus_Accepted;
  16208. }
  16209. else if(strcmp(str, "rts")== 0)
  16210. {
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16212. isSuccess = ConfigurationStatus_Accepted;
  16213. }
  16214. else if(strcmp(str, "srt")== 0)
  16215. {
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16217. isSuccess = ConfigurationStatus_Accepted;
  16218. }
  16219. else if(strcmp(str, "str")== 0)
  16220. {
  16221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16222. isSuccess = ConfigurationStatus_Accepted;
  16223. }
  16224. else if(strcmp(str, "trs")== 0)
  16225. {
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. }
  16229. else if(strcmp(str, "tsr")== 0)
  16230. {
  16231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16232. isSuccess = ConfigurationStatus_Accepted;
  16233. }
  16234. else
  16235. {
  16236. isSuccess = ConfigurationStatus_Rejected;
  16237. }
  16238. }
  16239. else
  16240. {
  16241. isSuccess = ConfigurationStatus_Rejected;
  16242. }
  16243. }
  16244. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16245. {
  16246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16247. {
  16248. check_ascii = value[0];
  16249. if( (check_ascii < 48) || (check_ascii > 57) )
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. else
  16254. {
  16255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16256. isSuccess = ConfigurationStatus_Accepted;
  16257. }
  16258. }
  16259. else
  16260. {
  16261. isSuccess = ConfigurationStatus_Rejected;
  16262. }
  16263. }
  16264. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16265. {
  16266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16267. {
  16268. strcpy(str, (const char*)value);
  16269. for(int i = 0; str[i]; i++)
  16270. {
  16271. str[i] = tolower(str[i]);
  16272. }
  16273. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16275. isSuccess = ConfigurationStatus_Accepted;
  16276. }
  16277. else
  16278. {
  16279. isSuccess = ConfigurationStatus_Rejected;
  16280. }
  16281. }
  16282. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16283. {
  16284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16285. {
  16286. strcpy(str, (const char*)value);
  16287. for(int i = 0; str[i]; i++)
  16288. {
  16289. str[i] = tolower(str[i]);
  16290. }
  16291. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16293. isSuccess = ConfigurationStatus_Accepted;
  16294. }
  16295. else
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. }
  16300. if(strcmp(key, "StopTxnAlignedData") == 0)
  16301. {
  16302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16303. {
  16304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16305. isSuccess = ConfigurationStatus_Accepted;
  16306. }
  16307. else
  16308. {
  16309. isSuccess = ConfigurationStatus_Rejected;
  16310. }
  16311. }
  16312. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16313. {
  16314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16315. {
  16316. check_ascii = value[0];
  16317. if( (check_ascii < 48) || (check_ascii > 57) )
  16318. {
  16319. isSuccess = ConfigurationStatus_Rejected;
  16320. }
  16321. else
  16322. {
  16323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16324. isSuccess = ConfigurationStatus_Accepted;
  16325. }
  16326. }
  16327. else
  16328. {
  16329. isSuccess = ConfigurationStatus_Rejected;
  16330. }
  16331. }
  16332. if(strcmp(key, "StopTxnSampledData") == 0)
  16333. {
  16334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16335. {
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16337. isSuccess = ConfigurationStatus_Accepted;
  16338. }
  16339. else
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. }
  16344. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16345. {
  16346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16347. {
  16348. check_ascii = value[0];
  16349. if( (check_ascii < 48) || (check_ascii > 57) )
  16350. {
  16351. isSuccess = ConfigurationStatus_Rejected;
  16352. }
  16353. else
  16354. {
  16355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16356. isSuccess = ConfigurationStatus_Accepted;
  16357. }
  16358. }
  16359. else
  16360. {
  16361. isSuccess = ConfigurationStatus_Rejected;
  16362. }
  16363. }
  16364. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16365. {
  16366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16367. {
  16368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16369. isSuccess = ConfigurationStatus_Accepted;
  16370. }
  16371. else
  16372. {
  16373. isSuccess = ConfigurationStatus_Rejected;
  16374. }
  16375. }
  16376. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16377. {
  16378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16379. {
  16380. check_ascii = value[0];
  16381. if( (check_ascii < 48) || (check_ascii > 57) )
  16382. {
  16383. isSuccess = ConfigurationStatus_Rejected;
  16384. }
  16385. else
  16386. {
  16387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16388. isSuccess = ConfigurationStatus_Accepted;
  16389. }
  16390. }
  16391. else
  16392. {
  16393. isSuccess = ConfigurationStatus_Rejected;
  16394. }
  16395. }
  16396. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16397. {
  16398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16399. {
  16400. check_ascii = value[0];
  16401. if( (check_ascii < 48) || (check_ascii > 57) )
  16402. {
  16403. isSuccess = ConfigurationStatus_Rejected;
  16404. }
  16405. else
  16406. {
  16407. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16409. TransactionMessageAttemptsValue = atoi(value);
  16410. isSuccess = ConfigurationStatus_Accepted;
  16411. }
  16412. }
  16413. else
  16414. {
  16415. isSuccess = ConfigurationStatus_Rejected;
  16416. }
  16417. }
  16418. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16419. {
  16420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16421. {
  16422. check_ascii = value[0];
  16423. if( (check_ascii < 48) || (check_ascii > 57) )
  16424. {
  16425. isSuccess = ConfigurationStatus_Rejected;
  16426. }
  16427. else
  16428. {
  16429. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16431. TransactionMessageRetryIntervalValue = atoi(value);
  16432. isSuccess = ConfigurationStatus_Accepted;
  16433. }
  16434. }
  16435. else
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. }
  16440. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16441. {
  16442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16443. {
  16444. strcpy(str, (const char*)value);
  16445. for(int i = 0; str[i]; i++)
  16446. {
  16447. str[i] = tolower(str[i]);
  16448. }
  16449. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16451. isSuccess = ConfigurationStatus_Accepted;
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "WebSocketPingInterval") == 0)
  16459. {
  16460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16461. {
  16462. check_ascii = value[0];
  16463. if( (check_ascii < 48) || (check_ascii > 57) )
  16464. {
  16465. isSuccess = ConfigurationStatus_Rejected;
  16466. }
  16467. else
  16468. {
  16469. if((atoi(value) == 0) || (atoi(value) >= 10))
  16470. {
  16471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16472. isSuccess = ConfigurationStatus_Accepted;
  16473. }
  16474. else
  16475. isSuccess = ConfigurationStatus_Rejected;
  16476. }
  16477. }
  16478. else
  16479. {
  16480. isSuccess = ConfigurationStatus_Rejected;
  16481. }
  16482. }
  16483. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16484. {
  16485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16486. {
  16487. strcpy(str, (const char*)value);
  16488. for(int i = 0; str[i]; i++)
  16489. {
  16490. str[i] = tolower(str[i]);
  16491. }
  16492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16493. isSuccess = ConfigurationStatus_Accepted;
  16494. }
  16495. else
  16496. {
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. if(strcmp(key, "AuthorizationKey") == 0)
  16501. {
  16502. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16503. {
  16504. strcpy(str, (const char*)value);
  16505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16506. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16507. isSuccess = ConfigurationStatus_Accepted;
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "SecurityProfile") == 0)
  16515. {
  16516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16517. {
  16518. check_ascii = value[0];
  16519. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16520. {
  16521. isSuccess = ConfigurationStatus_Rejected;
  16522. }
  16523. else if(check_ascii == 0x33)
  16524. {
  16525. isSuccess = NotSupported;
  16526. }
  16527. else
  16528. {
  16529. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16530. {
  16531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16532. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16533. isSuccess = ConfigurationStatus_Accepted;
  16534. }
  16535. else
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. }
  16539. else
  16540. {
  16541. isSuccess = ConfigurationStatus_Rejected;
  16542. }
  16543. }
  16544. if(strcmp(key, "DefaultPrice") == 0)
  16545. {
  16546. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16547. {
  16548. strcpy(str, (const char*)value);
  16549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16550. isSuccess = ConfigurationStatus_Accepted;
  16551. }
  16552. else
  16553. {
  16554. isSuccess = ConfigurationStatus_Rejected;
  16555. }
  16556. }
  16557. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16558. {
  16559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16560. {
  16561. strcpy(str, (const char*)value);
  16562. for(int i = 0; str[i]; i++)
  16563. {
  16564. str[i] = tolower(str[i]);
  16565. }
  16566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16567. isSuccess = ConfigurationStatus_Accepted;
  16568. }
  16569. else
  16570. {
  16571. isSuccess = ConfigurationStatus_Rejected;
  16572. }
  16573. }
  16574. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16575. {
  16576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16577. {
  16578. strcpy(str, (const char*)value);
  16579. for(int i = 0; str[i]; i++)
  16580. {
  16581. str[i] = tolower(str[i]);
  16582. }
  16583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16584. isSuccess = ConfigurationStatus_Accepted;
  16585. }
  16586. else
  16587. {
  16588. isSuccess = ConfigurationStatus_Rejected;
  16589. }
  16590. }
  16591. if(strcmp(key, "TimeOffset") == 0)
  16592. {
  16593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16594. {
  16595. strcpy(str, (const char*)value);
  16596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16597. isSuccess = ConfigurationStatus_Accepted;
  16598. }
  16599. else
  16600. {
  16601. isSuccess = ConfigurationStatus_Rejected;
  16602. }
  16603. }
  16604. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16605. {
  16606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16607. {
  16608. strcpy(str, (const char*)value);
  16609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16610. isSuccess = ConfigurationStatus_Accepted;
  16611. }
  16612. else
  16613. {
  16614. isSuccess = ConfigurationStatus_Rejected;
  16615. }
  16616. }
  16617. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16618. {
  16619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16620. {
  16621. strcpy(str, (const char*)value);
  16622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16623. isSuccess = ConfigurationStatus_Accepted;
  16624. }
  16625. else
  16626. {
  16627. isSuccess = ConfigurationStatus_Rejected;
  16628. }
  16629. }
  16630. if(strcmp(key, "SystemUptimeSec") == 0)
  16631. {
  16632. isSuccess = NotSupported;
  16633. }
  16634. if(strcmp(key, "FreeVend") == 0)
  16635. {
  16636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16637. {
  16638. strcpy(str, (const char*)value);
  16639. for(int i = 0; str[i]; i++)
  16640. {
  16641. str[i] = tolower(str[i]);
  16642. }
  16643. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16645. isSuccess = ConfigurationStatus_Accepted;
  16646. }
  16647. else
  16648. {
  16649. isSuccess = ConfigurationStatus_Rejected;
  16650. }
  16651. }
  16652. if(strcmp(key, "FreeVendIdtag") == 0)
  16653. {
  16654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16655. {
  16656. strcpy(str, (const char*)value);
  16657. if(strlen(str) <= 20)
  16658. {
  16659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16660. isSuccess = ConfigurationStatus_Accepted;
  16661. }
  16662. else
  16663. {
  16664. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16665. isSuccess = ConfigurationStatus_Rejected;
  16666. }
  16667. }
  16668. else
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. }
  16673. if(strcmp(key, "OcppServer") == 0)
  16674. {
  16675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16676. {
  16677. strcpy(str, (const char*)value);
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16679. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16680. isSuccess = ConfigurationStatus_Accepted;
  16681. }
  16682. else
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. }
  16687. if(strcmp(key, "MaintainServer") == 0)
  16688. {
  16689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16690. {
  16691. strcpy(str, (const char*)value);
  16692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16693. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16694. isSuccess = ConfigurationStatus_Accepted;
  16695. }
  16696. else
  16697. {
  16698. isSuccess = ConfigurationStatus_Rejected;
  16699. }
  16700. }
  16701. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16702. {
  16703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16704. {
  16705. strcpy(str, (const char*)value);
  16706. for(int i = 0; str[i]; i++)
  16707. {
  16708. str[i] = tolower(str[i]);
  16709. }
  16710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16711. isSuccess = ConfigurationStatus_Accepted;
  16712. }
  16713. else
  16714. {
  16715. isSuccess = ConfigurationStatus_Rejected;
  16716. }
  16717. }
  16718. if(strcmp(key, "StatusNotificationInterval") == 0)
  16719. {
  16720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16721. {
  16722. check_ascii = value[0];
  16723. if( (check_ascii < 48) || (check_ascii > 57) )
  16724. {
  16725. isSuccess = ConfigurationStatus_Rejected;
  16726. }
  16727. else
  16728. {
  16729. if((atoi(value) == 0) || (atoi(value) >= 10))
  16730. {
  16731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16732. isSuccess = ConfigurationStatus_Accepted;
  16733. }
  16734. else
  16735. isSuccess = ConfigurationStatus_Rejected;
  16736. }
  16737. }
  16738. else
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. }
  16743. #if 0
  16744. //For OCPP Test Case
  16745. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16746. {
  16747. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16748. {
  16749. strcpy(str, (const char*)value);
  16750. for(int i = 0; str[i]; i++)
  16751. {
  16752. str[i] = tolower(str[i]);
  16753. }
  16754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16755. isSuccess = ConfigurationStatus_Accepted;
  16756. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16757. }
  16758. else
  16759. {
  16760. isSuccess = ConfigurationStatus_Rejected;
  16761. }
  16762. }
  16763. #endif
  16764. #if 1
  16765. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16766. {
  16767. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16768. {
  16769. strcpy(str, (const char*)value);
  16770. for(int i = 0; str[i]; i++)
  16771. {
  16772. str[i] = tolower(str[i]);
  16773. }
  16774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16775. isSuccess = ConfigurationStatus_Accepted;
  16776. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16777. }
  16778. else
  16779. {
  16780. isSuccess = ConfigurationStatus_Rejected;
  16781. }
  16782. }
  16783. #endif
  16784. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16785. {
  16786. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16787. {
  16788. check_ascii = value[0];
  16789. if( (check_ascii < 48) || (check_ascii > 57) )
  16790. {
  16791. isSuccess = ConfigurationStatus_Rejected;
  16792. }
  16793. else
  16794. {
  16795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16796. isSuccess = ConfigurationStatus_Accepted;
  16797. }
  16798. }
  16799. else
  16800. {
  16801. isSuccess = ConfigurationStatus_Rejected;
  16802. }
  16803. }
  16804. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16805. {
  16806. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16807. {
  16808. check_ascii = value[0];
  16809. if( (check_ascii < 48) || (check_ascii > 57) )
  16810. {
  16811. isSuccess = ConfigurationStatus_Rejected;
  16812. }
  16813. else
  16814. {
  16815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16816. isSuccess = ConfigurationStatus_Accepted;
  16817. }
  16818. }
  16819. else
  16820. {
  16821. isSuccess = ConfigurationStatus_Rejected;
  16822. }
  16823. }
  16824. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16825. {
  16826. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16827. {
  16828. strcpy(str, (const char*)value);
  16829. for(int i = 0; str[i]; i++)
  16830. {
  16831. str[i] = tolower(str[i]);
  16832. }
  16833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16834. isSuccess = ConfigurationStatus_Accepted;
  16835. }
  16836. else
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. }
  16841. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16842. {
  16843. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16844. {
  16845. check_ascii = value[0];
  16846. if( (check_ascii < 48) || (check_ascii > 57) )
  16847. {
  16848. isSuccess = ConfigurationStatus_Rejected;
  16849. }
  16850. else
  16851. {
  16852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16853. isSuccess = ConfigurationStatus_Accepted;
  16854. }
  16855. }
  16856. else
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. }
  16861. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16862. {
  16863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16864. {
  16865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. else
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. }
  16873. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16874. {
  16875. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16876. {
  16877. check_ascii = value[0];
  16878. if( (check_ascii < 48) || (check_ascii > 57) )
  16879. {
  16880. isSuccess = ConfigurationStatus_Rejected;
  16881. }
  16882. else
  16883. {
  16884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16885. isSuccess = ConfigurationStatus_Accepted;
  16886. }
  16887. }
  16888. else
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. }
  16893. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16894. {
  16895. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16896. {
  16897. strcpy(str, (const char*)value);
  16898. for(int i = 0; str[i]; i++)
  16899. {
  16900. str[i] = tolower(str[i]);
  16901. }
  16902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16903. isSuccess = ConfigurationStatus_Accepted;
  16904. }
  16905. else
  16906. {
  16907. isSuccess = ConfigurationStatus_Rejected;
  16908. }
  16909. }
  16910. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16911. {
  16912. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16913. {
  16914. check_ascii = value[0];
  16915. if( (check_ascii < 48) || (check_ascii > 57) )
  16916. {
  16917. isSuccess = ConfigurationStatus_Rejected;
  16918. }
  16919. else
  16920. {
  16921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16922. isSuccess = ConfigurationStatus_Accepted;
  16923. }
  16924. }
  16925. else
  16926. {
  16927. isSuccess = ConfigurationStatus_Rejected;
  16928. }
  16929. }
  16930. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16931. return isSuccess;
  16932. }
  16933. int TransactionMessageAttemptsGet(void)
  16934. {
  16935. return TransactionMessageAttemptsValue;
  16936. }
  16937. int FirstHeartBeatResponse(void)
  16938. {
  16939. return FirstHeartBeat;
  16940. }
  16941. int TransactionMessageRetryIntervalGet(void)
  16942. {
  16943. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16944. }
  16945. int ReadHttpStatus(int sock)
  16946. {
  16947. //char c;
  16948. char buff[1024]="",*ptr=buff+1;
  16949. int bytes_received, status;
  16950. DEBUG_INFO("Begin Response ..\n");
  16951. while((bytes_received = recv(sock, ptr, 1, 0))){
  16952. if(bytes_received==-1){
  16953. perror("ReadHttpStatus");
  16954. exit(1);
  16955. }
  16956. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16957. ptr++;
  16958. }
  16959. *ptr=0;
  16960. ptr=buff+1;
  16961. sscanf(ptr,"%*s %d ", &status);
  16962. DEBUG_INFO("%s\n",ptr);
  16963. DEBUG_INFO("status=%d\n",status);
  16964. DEBUG_INFO("End Response ..\n");
  16965. return (bytes_received>0)?status:0;
  16966. }
  16967. //the only filed that it parsed is 'Content-Length'
  16968. int ParseHeader(int sock)
  16969. {
  16970. //char c;
  16971. char buff[1024]="",*ptr=buff+4;
  16972. int bytes_received;
  16973. DEBUG_INFO("Begin HEADER ..\n");
  16974. while((bytes_received = recv(sock, ptr, 1, 0))){
  16975. if(bytes_received==-1){
  16976. perror("Parse Header");
  16977. exit(1);
  16978. }
  16979. if(
  16980. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16981. (ptr[-1]=='\r') && (*ptr=='\n' )
  16982. ) break;
  16983. ptr++;
  16984. }
  16985. *ptr=0;
  16986. ptr=buff+4;
  16987. //printf("%s",ptr);
  16988. if(bytes_received){
  16989. ptr=strstr(ptr,"Content-Length:");
  16990. if(ptr){
  16991. sscanf(ptr,"%*s %d",&bytes_received);
  16992. }else
  16993. bytes_received=-1; //unknown size
  16994. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16995. }
  16996. DEBUG_INFO("End HEADER ..\n");
  16997. return bytes_received ;
  16998. }
  16999. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17000. {
  17001. int result = TRUE;
  17002. char rmFileCmd[100]={0};
  17003. char FilePath[100]={0};
  17004. char ftpbuf[200];
  17005. int systemresult;
  17006. sprintf(FilePath,"/mnt/%s",filename);
  17007. system("ping 8.8.8.8 &");
  17008. if((access(FilePath,F_OK))!=-1)
  17009. {
  17010. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17011. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17012. system(rmFileCmd);
  17013. }
  17014. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17015. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17016. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17017. systemresult = system(ftpbuf);
  17018. if(systemresult != 0)
  17019. {
  17020. DEBUG_INFO("http DownLoad error!\n");
  17021. result = FALSE;
  17022. }
  17023. system("pkill ping");
  17024. return result;
  17025. }
  17026. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17027. {
  17028. int result = TRUE;
  17029. char rmFileCmd[100]={0};
  17030. char FilePath[100]={0};
  17031. char ftpbuf[200];
  17032. int systemresult;
  17033. sprintf(FilePath,"/mnt/%s",filename);
  17034. system("ping 8.8.8.8 &");
  17035. if((access(FilePath,F_OK))!=-1)
  17036. {
  17037. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17038. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17039. system(rmFileCmd);
  17040. }
  17041. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17042. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17043. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17044. systemresult = system(ftpbuf);
  17045. if(systemresult != 0)
  17046. {
  17047. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17048. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17049. systemresult = system(ftpbuf);
  17050. if(systemresult != 0)
  17051. {
  17052. DEBUG_WARN("wget error!\n");
  17053. result = FALSE;
  17054. }
  17055. }
  17056. system("pkill ping");
  17057. return result;
  17058. }
  17059. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17060. {
  17061. char rmFileCmd[100]={0};
  17062. char FilePath[100]={0};
  17063. char buf[512];
  17064. int systemresult = 0;
  17065. //DEBUG_INFO("filename=%s\n",filename);
  17066. //DEBUG_INFO("url=%s\n",url);
  17067. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17068. if((access(FilePath,F_OK))!=-1)
  17069. {
  17070. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17071. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17072. system(rmFileCmd);
  17073. }
  17074. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17075. if(fp == NULL)
  17076. {
  17077. DEBUG_INFO("log is NULL\n");
  17078. return FALSE;
  17079. }
  17080. else
  17081. {
  17082. fprintf(fp, "%s\n", url);
  17083. fprintf(fp, "%s\n", filename);
  17084. fclose(fp);
  17085. }
  17086. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17087. if(phpFP == NULL)
  17088. {
  17089. DEBUG_INFO("PHP upload fail.\n");
  17090. return FALSE;
  17091. }
  17092. else
  17093. {
  17094. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17095. {
  17096. if(strstr(buf, "result") != NULL)
  17097. {
  17098. sscanf(buf, "result: %d", &systemresult);
  17099. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17100. }
  17101. }
  17102. pclose(phpFP);
  17103. }
  17104. if(systemresult != 1)
  17105. {
  17106. DEBUG_INFO("HTTP upload error!\n");
  17107. return FALSE;
  17108. }
  17109. return TRUE;
  17110. }
  17111. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17112. {
  17113. int result = FALSE;
  17114. char ftpbuf[200];
  17115. int systemresult;
  17116. /*
  17117. // Domaind name transfer to IP address
  17118. struct hostent* server;
  17119. char *IPbuffer;
  17120. server = gethostbyname(location);
  17121. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17122. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17123. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17124. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17125. systemresult = system(ftpbuf);
  17126. if(systemresult != 0)
  17127. {
  17128. DEBUG_INFO("ftpput error!\n");
  17129. }
  17130. else
  17131. {
  17132. result = TRUE;
  17133. DEBUG_INFO("ftpput OK!\n");
  17134. }
  17135. return result;
  17136. }
  17137. int GetOcppServerURL()
  17138. {
  17139. int result = FALSE;
  17140. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17141. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17142. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17143. struct yuarel url;
  17144. char urlStr[512];
  17145. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17146. {
  17147. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17148. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17149. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17150. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17151. if(yuarel_parse(&url, urlStr) != -1)
  17152. {
  17153. sprintf(OcppProtocol, "%s", url.scheme);
  17154. sprintf(OcppHost, "%s", url.host);
  17155. if(url.path == NULL)
  17156. OcppTempPath[0] = '\0';
  17157. else
  17158. {
  17159. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17160. {
  17161. sprintf(OcppTempPath, "%s/", url.path);
  17162. }
  17163. else
  17164. {
  17165. sprintf(OcppTempPath, "%s", url.path);
  17166. }
  17167. }
  17168. if(url.port == 0)
  17169. {
  17170. if(strcmp(OcppProtocol, "wss") == 0)
  17171. OcppPort = 443;
  17172. else
  17173. OcppPort = 80;
  17174. }
  17175. else
  17176. OcppPort = url.port;
  17177. result = TRUE;
  17178. }
  17179. }
  17180. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17181. {
  17182. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17183. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17184. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17185. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17186. if(yuarel_parse(&url, urlStr) != -1)
  17187. {
  17188. sprintf(OcppProtocol, "%s", url.scheme);
  17189. sprintf(OcppHost, "%s", url.host);
  17190. if(url.path == NULL)
  17191. OcppTempPath[0] = '\0';
  17192. else
  17193. sprintf(OcppTempPath, "%s", url.path);
  17194. if(url.port == 0)
  17195. {
  17196. if(strcmp(OcppProtocol, "wss") == 0)
  17197. OcppPort = 443;
  17198. else
  17199. OcppPort = 80;
  17200. }
  17201. else
  17202. OcppPort = url.port;
  17203. result = TRUE;
  17204. }
  17205. }
  17206. else
  17207. {
  17208. strcpy(OcppHost,"");
  17209. }
  17210. return result;
  17211. }
  17212. int GetOcppPath()
  17213. {
  17214. int result = FALSE;
  17215. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17216. {
  17217. if(OcppTempPath == NULL)
  17218. {
  17219. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17220. }
  17221. else
  17222. {
  17223. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17224. }
  17225. result = TRUE;
  17226. goto End;
  17227. }
  17228. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17229. {
  17230. if(OcppTempPath == NULL)
  17231. {
  17232. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17233. }
  17234. else
  17235. {
  17236. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17237. }
  17238. result = TRUE;
  17239. goto End;
  17240. }
  17241. else
  17242. {
  17243. strcpy(OcppPath,"");
  17244. }
  17245. End:
  17246. return result;
  17247. }
  17248. int GetOcppPort()
  17249. {
  17250. return OcppPort;
  17251. }
  17252. int GetOcppConnStatus(void)
  17253. {
  17254. return ShmOCPP16Data->OcppConnStatus;
  17255. }
  17256. void SetOcppConnStatus(uint8_t status)
  17257. {
  17258. ShmOCPP16Data->OcppConnStatus = status;
  17259. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17260. }
  17261. int GetHeartBeatWithNOResponse(void)
  17262. {
  17263. return HeartBeatWithNOResponse;
  17264. }
  17265. void SetHeartBeatWithNOResponse(void)
  17266. {
  17267. HeartBeatWithNOResponse = 0;
  17268. }
  17269. void GetStartTransactionIdTag(int gun_index)
  17270. {
  17271. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17272. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17273. }
  17274. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17275. {
  17276. char ch;
  17277. FILE *fptr1;
  17278. int temptransactionId;
  17279. char str[100]={0};
  17280. temptransactionId = 0;
  17281. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17282. {
  17283. DEBUG_INFO("IdTag is empty.\n");
  17284. return temptransactionId;
  17285. }
  17286. /*------ Read the file ----------------*/
  17287. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17288. if (!fptr1)
  17289. {
  17290. DEBUG_INFO("QueueTransactionId file open error.\n");
  17291. //printf(" File not found or unable to open the input file!!\n");
  17292. return temptransactionId;
  17293. }
  17294. ch=fgetc(fptr1);
  17295. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17296. rewind(fptr1);
  17297. if(ch!=EOF)
  17298. {
  17299. // printf("%c",ch);
  17300. while (fgets(str, 100, fptr1) != NULL)
  17301. {
  17302. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17303. if(str[0]=='\0')
  17304. {
  17305. break;
  17306. }
  17307. char *revbuf[8] = {0}; // Variable store string split
  17308. int num = 0;// Quantity after string split
  17309. DEBUG_INFO("Transaction queue data= %s\n", str);
  17310. splitstring(str,",",revbuf,&num); // String split
  17311. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17312. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17313. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17314. DEBUG_INFO("------------------------------\n");
  17315. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17316. {
  17317. if(isStopTransaction)
  17318. {
  17319. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17320. {
  17321. temptransactionId = atoi(revbuf[2]);
  17322. //break;
  17323. }
  17324. }
  17325. else
  17326. {
  17327. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17328. {
  17329. temptransactionId = atoi(revbuf[2]);
  17330. //break;
  17331. }
  17332. }
  17333. }
  17334. }
  17335. }
  17336. else
  17337. DEBUG_INFO("EOF\n");
  17338. fclose(fptr1);
  17339. /*------- End of reading ---------------*/
  17340. return temptransactionId;
  17341. }
  17342. void SetTransactionIdZero(int transactionId)
  17343. {
  17344. char ch;
  17345. FILE *fptr1, *fptr2;
  17346. int temptransactionId = 0;
  17347. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17348. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17349. if (!fptr1)
  17350. {
  17351. //printf(" File not found or unable to open the input file!!\n");
  17352. return ;
  17353. }
  17354. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17355. if (!fptr2)
  17356. {
  17357. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17358. fclose(fptr1);
  17359. return ;
  17360. }
  17361. ch=fgetc(fptr1);
  17362. rewind(fptr1);
  17363. if(ch!=EOF)
  17364. {
  17365. // copy all contents to the temporary file except the specific line
  17366. while (fgets(str, 100, fptr1) != NULL)
  17367. {
  17368. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17369. if(str[0]=='\0')
  17370. {
  17371. break;
  17372. }
  17373. char *revbuf[8] = {0};
  17374. int num = 0;
  17375. strcpy(strtemp, str);
  17376. splitstring(str,",",revbuf,&num);
  17377. if(revbuf[2][0] != '\0')
  17378. {
  17379. temptransactionId = atoi(revbuf[2]);
  17380. if(transactionId != temptransactionId)
  17381. {
  17382. fprintf(fptr2, "%s\n", strtemp);
  17383. }
  17384. }
  17385. }
  17386. }
  17387. fclose(fptr1);
  17388. fclose(fptr2);
  17389. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17390. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17391. /*------ Read the file ----------------*/
  17392. }
  17393. int InternetDisconnect(void)
  17394. {
  17395. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17396. }
  17397. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17398. void storeTempStopTransaction(int gun_index)
  17399. {
  17400. char guid[37]={0};
  17401. int tempIndex = 0;
  17402. char TempStopTransaction[256];
  17403. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17404. DEBUG_INFO("storeTempStopTransaction...\n");
  17405. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17406. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17407. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17408. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17410. {
  17411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17412. {
  17413. tempIndex = ((gun_index==2) ? 1: 0);
  17414. }
  17415. else
  17416. {
  17417. tempIndex = gun_index;
  17418. }
  17419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17420. {
  17421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17422. {
  17423. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17424. }
  17425. }// END OF CHAdeMO_QUANTITY
  17426. }
  17427. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17428. {
  17429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17430. {
  17431. tempIndex = ((gun_index==2) ? 1: 0);
  17432. }
  17433. else
  17434. {
  17435. tempIndex = gun_index;
  17436. }
  17437. for (int index = 0; index < CCS_QUANTITY; index++)
  17438. {
  17439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17440. {
  17441. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17442. }
  17443. }// END OF CCS_QUANTITY
  17444. }
  17445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17446. {
  17447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17448. {
  17449. tempIndex = ((gun_index==2) ? 1: 0);
  17450. }
  17451. else
  17452. {
  17453. tempIndex = gun_index;
  17454. }
  17455. for (int index = 0; index < GB_QUANTITY; index++)
  17456. {
  17457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17458. {
  17459. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17460. }
  17461. }// END OF GB_QUANTITY
  17462. }
  17463. else if(gunType[gun_index] == GUN_TYPE_DO)
  17464. {
  17465. tempIndex = gun_index;
  17466. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17467. {
  17468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17469. {
  17470. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17471. }
  17472. }
  17473. }
  17474. else
  17475. {
  17476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17477. {
  17478. tempIndex = 2;
  17479. }
  17480. else
  17481. {
  17482. tempIndex = gun_index;
  17483. }
  17484. for (int index = 0; index < AC_QUANTITY; index++)
  17485. {
  17486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17487. {
  17488. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17489. }
  17490. }// END OF AC_QUANTITY
  17491. }
  17492. //Stop Transaction Time
  17493. struct timeval tmnow;
  17494. struct tm *tm;
  17495. char buf[28];//, usec_buf[6];
  17496. gettimeofday(&tmnow, NULL);
  17497. time_t t;
  17498. t = time(NULL);
  17499. /*UTC time and date*/
  17500. tm = gmtime(&t);
  17501. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17503. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17505. random_uuid(guid);
  17506. /***********************************transactionData******************************************************/
  17507. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17509. //=================================
  17510. //1. Transaction_Begin
  17511. //=================================
  17512. //============================== Energy.Active.Import.Interval ===========================================
  17513. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17514. {
  17515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17518. 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*/]);
  17519. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17520. 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))
  17521. {
  17522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17523. }
  17524. else
  17525. {
  17526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17527. }
  17528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17530. }
  17531. //=================================
  17532. //2. Transaction_End
  17533. //=================================
  17534. //2.1====================================== Current.Import L1 ==============================================
  17535. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17536. {
  17537. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17538. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17539. {
  17540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17541. {
  17542. tempIndex = ((gun_index==2) ? 1: 0);
  17543. }
  17544. else
  17545. {
  17546. tempIndex = gun_index;
  17547. }
  17548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17549. {
  17550. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17551. {
  17552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17553. }
  17554. }// End of for CHAdeMO_QUANTITY
  17555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17556. }
  17557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17558. {
  17559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17560. {
  17561. tempIndex = ((gun_index==2) ? 1: 0);
  17562. }
  17563. else
  17564. {
  17565. tempIndex = gun_index;
  17566. }
  17567. for (int index = 0; index < CCS_QUANTITY; index++)
  17568. {
  17569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17570. {
  17571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17572. }
  17573. }// End of for CCS_QUANTITY
  17574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17575. }
  17576. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17577. {
  17578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17579. {
  17580. tempIndex = ((gun_index==2) ? 1: 0);
  17581. }
  17582. else
  17583. {
  17584. tempIndex = gun_index;
  17585. }
  17586. for (int index = 0; index < GB_QUANTITY; index++)
  17587. {
  17588. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17589. {
  17590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17591. }
  17592. }// End of for GB_QUANTITY
  17593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17594. }
  17595. else if(gunType[gun_index] == GUN_TYPE_DO)
  17596. {
  17597. tempIndex = gun_index;
  17598. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17599. {
  17600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17601. {
  17602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17603. }
  17604. }
  17605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17606. }
  17607. else
  17608. {
  17609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17610. {
  17611. tempIndex = 2;
  17612. }
  17613. else
  17614. {
  17615. tempIndex = gun_index;
  17616. }
  17617. for (int index = 0; index < AC_QUANTITY; index++)
  17618. {
  17619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17622. }
  17623. }// End of for AC_QUANTITY
  17624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17625. }
  17626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17629. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17632. }
  17633. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17634. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17635. {
  17636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17638. {
  17639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17640. {
  17641. tempIndex = ((gun_index==2) ? 1: 0);
  17642. }
  17643. else
  17644. {
  17645. tempIndex = gun_index;
  17646. }
  17647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17648. {
  17649. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17650. {
  17651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17652. }
  17653. }// END OF CHAdeMO_QUANTITY
  17654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17655. }
  17656. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17657. {
  17658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17659. {
  17660. tempIndex = ((gun_index==2) ? 1: 0);
  17661. }
  17662. else
  17663. {
  17664. tempIndex = gun_index;
  17665. }
  17666. for (int index = 0; index < CCS_QUANTITY; index++)
  17667. {
  17668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17669. {
  17670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17671. }
  17672. }// END OF CCS_QUANTITY
  17673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17674. }
  17675. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17676. {
  17677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17678. {
  17679. tempIndex = ((gun_index==2) ? 1: 0);
  17680. }
  17681. else
  17682. {
  17683. tempIndex = gun_index;
  17684. }
  17685. for (int index = 0; index < GB_QUANTITY; index++)
  17686. {
  17687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17688. {
  17689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17690. }
  17691. }// END OF GB_QUANTITY
  17692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17693. }
  17694. else if(gunType[gun_index] == GUN_TYPE_DO)
  17695. {
  17696. tempIndex = gun_index;
  17697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17702. }
  17703. }
  17704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17705. }
  17706. else
  17707. {
  17708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17709. {
  17710. tempIndex = 2;
  17711. }
  17712. else
  17713. {
  17714. tempIndex = gun_index;
  17715. }
  17716. for (int index = 0; index < AC_QUANTITY; index++)
  17717. {
  17718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17719. {
  17720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17721. }
  17722. }// END OF AC_QUANTITY
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17724. }
  17725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17728. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17731. }
  17732. //2.3====================================== Power.Active.Import =========================================
  17733. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17734. {
  17735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17737. {
  17738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17739. {
  17740. tempIndex = ((gun_index==2) ? 1: 0);
  17741. }
  17742. else
  17743. {
  17744. tempIndex = gun_index;
  17745. }
  17746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17747. {
  17748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17749. {
  17750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17751. }
  17752. } // End for CHAdeMO_QUANTITY
  17753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17754. }
  17755. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17756. {
  17757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17758. {
  17759. tempIndex = ((gun_index==2) ? 1: 0);
  17760. }
  17761. else
  17762. {
  17763. tempIndex = gun_index;
  17764. }
  17765. for (int index = 0; index < CCS_QUANTITY; index++)
  17766. {
  17767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17768. {
  17769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17770. }
  17771. } // END for CCS_QUANTITY
  17772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17773. }
  17774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17775. {
  17776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17777. {
  17778. tempIndex = ((gun_index==2) ? 1: 0);
  17779. }
  17780. else
  17781. {
  17782. tempIndex = gun_index;
  17783. }
  17784. for (int index = 0; index < GB_QUANTITY; index++)
  17785. {
  17786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17787. {
  17788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17789. }
  17790. }// END for GB_QUANTITY
  17791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17792. }
  17793. else if(gunType[gun_index] == GUN_TYPE_DO)
  17794. {
  17795. tempIndex = gun_index;
  17796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17797. {
  17798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17799. {
  17800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17801. }
  17802. }
  17803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17804. }
  17805. else
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17808. {
  17809. tempIndex = 2;
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < AC_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17818. {
  17819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17820. }
  17821. } // END for AC_QUANTITY
  17822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17823. }
  17824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17827. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17830. }
  17831. //2.4====================================== Voltage L1 ====================================================
  17832. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17833. {
  17834. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17836. {
  17837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17838. {
  17839. tempIndex = ((gun_index==2) ? 1: 0);
  17840. }
  17841. else
  17842. {
  17843. tempIndex = gun_index;
  17844. }
  17845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17846. {
  17847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17848. {
  17849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17850. }
  17851. } // END OF FOR CHAdeMO_QUANTITY
  17852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17853. }
  17854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17855. {
  17856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17857. {
  17858. tempIndex = ((gun_index==2) ? 1: 0);
  17859. }
  17860. else
  17861. {
  17862. tempIndex = gun_index;
  17863. }
  17864. for (int index = 0; index < CCS_QUANTITY; index++)
  17865. {
  17866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17867. {
  17868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17869. }
  17870. } // END OF FOR CCS_QUANTITY
  17871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17872. }
  17873. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17874. {
  17875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17876. {
  17877. tempIndex = ((gun_index==2) ? 1: 0);
  17878. }
  17879. else
  17880. {
  17881. tempIndex = gun_index;
  17882. }
  17883. for (int index = 0; index < GB_QUANTITY; index++)
  17884. {
  17885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17886. {
  17887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17888. }
  17889. } // END OF FOR GB_QUANTITY
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17891. }
  17892. else if(gunType[gun_index] == GUN_TYPE_DO)
  17893. {
  17894. tempIndex = gun_index;
  17895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17896. {
  17897. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17898. {
  17899. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17900. }
  17901. }
  17902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17903. }
  17904. else
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17907. {
  17908. tempIndex = 2;
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < AC_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17917. {
  17918. 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
  17919. }
  17920. } // END OF FOR AC_QUANTITY
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17922. }
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17926. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17929. }
  17930. //2.5============================================== End SoC =========================================================
  17931. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17932. {
  17933. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17934. 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))
  17935. {
  17936. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17937. {
  17938. tempIndex = ((gun_index==2) ? 1: 0);
  17939. }
  17940. else
  17941. {
  17942. tempIndex = gun_index;
  17943. }
  17944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17945. {
  17946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17947. {
  17948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17949. {
  17950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17951. }
  17952. }
  17953. }
  17954. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17955. {
  17956. for (int index = 0; index < CCS_QUANTITY; index++)
  17957. {
  17958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17959. {
  17960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17961. }
  17962. }
  17963. }
  17964. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17965. {
  17966. for (int index = 0; index < GB_QUANTITY; index++)
  17967. {
  17968. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17969. {
  17970. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17971. }
  17972. }
  17973. }
  17974. else if(gunType[gun_index] == GUN_TYPE_DO)
  17975. {
  17976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17977. {
  17978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17979. {
  17980. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17981. }
  17982. }
  17983. }
  17984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17990. } // END FOR DC CASE
  17991. }
  17992. //2.6====================================== Current.Import L2 ==============================================
  17993. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17994. {
  17995. // AC 3 phase L2 current
  17996. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17997. {
  17998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17999. {
  18000. tempIndex = 2;
  18001. }
  18002. else
  18003. {
  18004. tempIndex = gun_index;
  18005. }
  18006. for (int index = 0; index < AC_QUANTITY; index++)
  18007. {
  18008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18009. {
  18010. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18011. }
  18012. }// End of for AC_QUANTITY
  18013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18014. }
  18015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18020. }
  18021. //2.7====================================== Current.Import L3 ==============================================
  18022. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18023. {
  18024. // AC 3 phase L3 current
  18025. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18026. {
  18027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18028. {
  18029. tempIndex = 2;
  18030. }
  18031. else
  18032. {
  18033. tempIndex = gun_index;
  18034. }
  18035. for (int index = 0; index < AC_QUANTITY; index++)
  18036. {
  18037. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18038. {
  18039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18040. }
  18041. }// End of for AC_QUANTITY
  18042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18043. }
  18044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18049. }
  18050. //2.9====================================== Voltage L2 ====================================================
  18051. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18052. {
  18053. // AC 3 phase L2 volatge
  18054. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18055. {
  18056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18057. {
  18058. tempIndex = 2;
  18059. }
  18060. else
  18061. {
  18062. tempIndex = gun_index;
  18063. }
  18064. for (int index = 0; index < AC_QUANTITY; index++)
  18065. {
  18066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18067. {
  18068. 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
  18069. }
  18070. } // END OF FOR AC_QUANTITY
  18071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18072. }
  18073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18078. }
  18079. //2.10====================================== Voltage L3 ====================================================
  18080. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18081. {
  18082. // AC 3 phase L3 volatge
  18083. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18084. {
  18085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18086. {
  18087. tempIndex = 2;
  18088. }
  18089. else
  18090. {
  18091. tempIndex = gun_index;
  18092. }
  18093. for (int index = 0; index < AC_QUANTITY; index++)
  18094. {
  18095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18096. {
  18097. 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
  18098. }
  18099. } // END OF FOR AC_QUANTITY
  18100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18101. }
  18102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18107. }
  18108. //====================== Start SoC ================================
  18109. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18110. {
  18111. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18112. 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))
  18113. {
  18114. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18115. {
  18116. tempIndex = ((gun_index==2) ? 1: 0);
  18117. }
  18118. else
  18119. {
  18120. tempIndex = gun_index;
  18121. }
  18122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18123. {
  18124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18125. {
  18126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18127. {
  18128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18129. }
  18130. }
  18131. }
  18132. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18133. {
  18134. for (int index = 0; index < CCS_QUANTITY; index++)
  18135. {
  18136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18137. {
  18138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18139. }
  18140. }
  18141. }
  18142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18143. {
  18144. for (int index = 0; index < GB_QUANTITY; index++)
  18145. {
  18146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18147. {
  18148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18149. }
  18150. }
  18151. }
  18152. else if(gunType[gun_index] == GUN_TYPE_DO)
  18153. {
  18154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18155. {
  18156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18157. {
  18158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18159. }
  18160. }
  18161. }
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18168. } // END FOR DC CASE
  18169. }
  18170. //======================================== Message create ==============================================
  18171. json_object *StopTransaction = json_object_new_object();
  18172. json_object *transactionDatas = json_object_new_array();
  18173. json_object *sampledValues = json_object_new_array();
  18174. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18175. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18176. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18177. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18178. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18179. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18180. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18181. {
  18182. json_object *transactionData = json_object_new_object();
  18183. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18184. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18185. {
  18186. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18187. {
  18188. json_object *sampledValue = json_object_new_object();
  18189. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18190. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18191. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18192. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18193. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18194. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18195. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18196. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18197. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18198. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18199. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18200. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18201. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18202. json_object_array_add(sampledValues, sampledValue);
  18203. }
  18204. }
  18205. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18206. json_object_array_add(transactionDatas, transactionData);
  18207. }
  18208. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18209. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18210. ,MESSAGE_TYPE_CALL
  18211. ,guid
  18212. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18213. json_object_put(StopTransaction);
  18214. // Check File "TempStopTransaction" Exist
  18215. if((access(TempStopTransaction,F_OK))!=-1)
  18216. {
  18217. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18218. fclose(fopen(TempStopTransaction, "w"));
  18219. }
  18220. else
  18221. {
  18222. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18223. FILE *log = fopen(TempStopTransaction, "w+");
  18224. if(log == NULL)
  18225. {
  18226. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18227. return ;
  18228. }
  18229. else
  18230. {
  18231. fclose(log);
  18232. }
  18233. }
  18234. //Add TempStopTransaction | Update TempStopTransaction
  18235. // open file for writing
  18236. FILE *outfile;
  18237. outfile = fopen (TempStopTransaction, "a");
  18238. //DEBUG_INFO("data = %s\n", queuedata);
  18239. fputs(queuedata, outfile);
  18240. fputs("\n", outfile);
  18241. fclose (outfile);
  18242. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18243. OCPP_updatePeriodEnergy(gun_index);
  18244. }
  18245. void checkTempStopTransaction(int gun_index)
  18246. {
  18247. FILE *fptr1;
  18248. char ch;
  18249. char str[QUEUE_MESSAGE_LENGTH]={0};
  18250. char guid[37]={0};
  18251. char tempdata[65]={0};
  18252. char connectorStr[2]={0};
  18253. char TempStopTransaction[256];
  18254. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18255. fptr1 = fopen(TempStopTransaction, "r");
  18256. //TempStopTransaction格式: 槍號,StopTransaction封包
  18257. if (!fptr1)
  18258. {
  18259. //printf(" File not found or unable to open the input file!!\n");
  18260. return ;
  18261. }
  18262. ch=fgetc(fptr1);
  18263. //printf(" Now the content of the file %s is : \n",fname);
  18264. rewind(fptr1);
  18265. if(ch!=EOF)
  18266. {
  18267. // copy all contents to the temporary file except the specific line
  18268. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18269. {
  18270. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18271. if(str[0]=='\0')
  18272. {
  18273. break;
  18274. }
  18275. //TempStopTransaction格式: 槍號,StopTransaction封包
  18276. strncpy(connectorStr, str, 1);
  18277. if(atoi(connectorStr) != (gun_index+1))
  18278. {
  18279. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18280. fclose(fptr1);
  18281. return ;
  18282. }
  18283. //random_uuid(guid);
  18284. strncpy(guid, str+6, 36); //copy guid
  18285. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18286. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18287. {
  18288. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18289. }
  18290. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18291. OCPP_insert_transaction_msg(NO, str);
  18292. memset(str,0,ARRAY_SIZE(str));
  18293. }
  18294. }
  18295. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18296. fclose(fptr1);
  18297. remove(TempStopTransaction); // remove the original file
  18298. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18299. }
  18300. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18301. {
  18302. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18303. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18304. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18305. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18306. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18307. }
  18308. int GetWebSocketPingInterval(void)
  18309. {
  18310. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18311. }
  18312. int GetServerSign(void)
  18313. {
  18314. return server_sign;
  18315. }
  18316. uint8_t GetOcppSecurityProfile()
  18317. {
  18318. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18319. }
  18320. void GetOcppChargerBoxId(uint8_t *data)
  18321. {
  18322. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18323. }
  18324. void GetOcppSecurityPassword(uint8_t *data)
  18325. {
  18326. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18327. }
  18328. void SetOcppVersion(uint8_t *version)
  18329. {
  18330. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18331. DEBUG_INFO("ocpp version: %s\n", version);
  18332. if(strstr((char*)version, "ocpp1.6") != NULL)
  18333. {
  18334. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18335. }
  18336. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18337. {
  18338. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18339. system("pkill OcppBackend");
  18340. }
  18341. }
  18342. void SetServerSign(int value)
  18343. {
  18344. server_sign = value;
  18345. }
  18346. int GetBootNotificationInterval(void)
  18347. {
  18348. return BootNotificationInterval;
  18349. }
  18350. int GetInternetConn(void)
  18351. {
  18352. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18353. }
  18354. int GetBackendConnectionTimeout(void)
  18355. {
  18356. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18357. }
  18358. int isConnectorInitMode(int gun_index)
  18359. {
  18360. int tempIndex = 0;
  18361. int result = TRUE;
  18362. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18363. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18364. {
  18365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18366. {
  18367. tempIndex = ((gun_index==2) ? 1: 0);
  18368. }
  18369. else
  18370. {
  18371. tempIndex = gun_index;
  18372. }
  18373. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18374. {
  18375. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18376. {
  18377. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18378. } //end of the same index
  18379. }//end of for CHAdeMO_QUANTITY
  18380. }
  18381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18382. {
  18383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18384. {
  18385. tempIndex = ((gun_index==2) ? 1: 0);
  18386. }
  18387. else
  18388. {
  18389. tempIndex = gun_index;
  18390. }
  18391. for (int index = 0; index < CCS_QUANTITY; index++)
  18392. {
  18393. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18394. {
  18395. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18396. } //end of the same index
  18397. } // end of for CCS_QUANTITY
  18398. }
  18399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18400. {
  18401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18402. {
  18403. tempIndex = ((gun_index==2) ? 1: 0);
  18404. }
  18405. else
  18406. {
  18407. tempIndex = gun_index;
  18408. }
  18409. for (int index = 0; index < GB_QUANTITY; index++)
  18410. {
  18411. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18412. {
  18413. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18414. } //end of the same index
  18415. } // end of for GB_QUANTITY
  18416. }
  18417. else if(gunType[gun_index] == GUN_TYPE_DO)
  18418. {
  18419. tempIndex = gun_index;
  18420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18421. {
  18422. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18423. {
  18424. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18425. } //end of the same index
  18426. }
  18427. }
  18428. else
  18429. {
  18430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18431. {
  18432. tempIndex = 2;
  18433. }
  18434. else
  18435. {
  18436. tempIndex = gun_index;
  18437. }
  18438. for (int index = 0; index < AC_QUANTITY; index++)
  18439. {
  18440. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18441. {
  18442. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18443. }//end of the same index
  18444. }//end of for AC_QUANTITY
  18445. }
  18446. return result;
  18447. }
  18448. void refreshProcDogTimer()
  18449. {
  18450. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18451. }
  18452. void InitialSystemValue(void)
  18453. {
  18454. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18455. locallistVersion=0;
  18456. BootNotificationInterval = 0;
  18457. authorizeRetryTimes = 0;
  18458. GunStatusInterval = 10;
  18459. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18460. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18461. //Hear Beat
  18462. HeartBeatWithNOResponse = 0;
  18463. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18464. FirstHeartBeat = 0;
  18465. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18466. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18467. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18468. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18469. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18470. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18471. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18472. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18473. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18474. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18475. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18476. //Status && ConnectorPlugIn Setting
  18477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18478. {
  18479. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18480. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18481. }
  18482. for (int index = 0; index < CCS_QUANTITY; index++)
  18483. {
  18484. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18485. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18486. }
  18487. for (int index = 0; index < GB_QUANTITY; index++)
  18488. {
  18489. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18490. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18491. }
  18492. for (int index = 0; index < AC_QUANTITY; index++)
  18493. {
  18494. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18495. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18496. }
  18497. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18498. {
  18499. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18500. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18501. }
  18502. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18503. {
  18504. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18505. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18506. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18507. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18508. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18509. }
  18510. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18511. refreshStartTimer(&clientTime.Heartbeat);
  18512. sleep(1);
  18513. }
  18514. void LWS_Send(char *str)
  18515. {
  18516. //=====================================================
  18517. // Check InternetConn 0: disconnected, 1: connected
  18518. //====================================================
  18519. if(GetOcppConnStatus() == 0)
  18520. {
  18521. DEBUG_INFO("offline now !!!\n");
  18522. return;
  18523. }
  18524. // Only disable isWebsocketSendable operation initiated by charger
  18525. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18526. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18527. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18528. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18529. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18530. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18531. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18532. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18533. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18534. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18535. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18536. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18537. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18538. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18539. {
  18540. isWebsocketSendable = 0;
  18541. }
  18542. pthread_mutex_lock(&lock_send);
  18543. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18544. sprintf((char *)SendBuffer, "%s", str);
  18545. SendBufLen = strlen(str);
  18546. pthread_mutex_unlock(&lock_send);
  18547. lws_callback_on_writable(wsi_client);
  18548. //lws_service(context, 0);
  18549. //sleep(1);
  18550. }
  18551. void LWS_SendNow(char *str)
  18552. {
  18553. //=====================================================
  18554. // Check InternetConn 0: disconnected, 1: connected
  18555. //====================================================
  18556. if(GetOcppConnStatus() == 0)
  18557. {
  18558. DEBUG_INFO("offline now !!!\n");
  18559. return;
  18560. }
  18561. // Only disable isWebsocketSendable operation initiated by charger
  18562. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18563. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18564. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18565. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18566. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18567. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18568. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18569. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18570. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18571. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18572. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18573. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18574. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18575. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18576. {
  18577. isWebsocketSendable = 0;
  18578. }
  18579. pthread_mutex_lock(&lock_send);
  18580. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18581. sprintf((char *)SendBuffer, "%s", str);
  18582. SendBufLen = strlen(str);
  18583. pthread_mutex_unlock(&lock_send);
  18584. lws_callback_on_writable(wsi_client);
  18585. lws_service(context, 0);
  18586. //sleep(1);
  18587. }