MessageHandler.c 958 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //============================================
  79. // OCPP MeterValue request flag
  80. //============================================
  81. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  82. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  83. //=============================================
  84. // OCPP HeartBeat Response Not Receive Counts
  85. //============================================
  86. static int HeartBeatWithNOResponse = 0;
  87. extern sqlite3 *db;
  88. int TransactionMessageAttemptsGet(void);
  89. int TransactionMessageRetryIntervalGet(void);
  90. int GetOcppConnStatus(void);
  91. void SetOcppConnStatus(uint8_t status);
  92. int setKeyValue(char *key, char *value);
  93. void OCPP_get_TableAuthlocalAllData(void);
  94. void processUnkownKey(void);
  95. struct InterLock
  96. {
  97. unsigned char isGetDiagnosticGoing:1;
  98. unsigned char isUpdateFirmwareGoing:1;
  99. }interLock;
  100. struct ClientTime
  101. {
  102. struct timespec Heartbeat;
  103. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  104. struct timespec StartTransaction;
  105. struct timespec StopTransaction;
  106. struct timespec MeterValues[CONNECTOR_QUANTITY];
  107. struct timespec RemoteStartWait;
  108. struct timespec TcciQueryDeduct;
  109. }clientTime;
  110. typedef union
  111. {
  112. //Operations Initiated by Central System
  113. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  114. struct
  115. {
  116. //CsMsgValue[0]
  117. unsigned char StatusNotificationReq:1; //bit 0,
  118. unsigned char StatusNotificationConf:1; //bit 1,
  119. unsigned char TriggerMeterValue:1; //bit 2,
  120. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  121. unsigned char isOnCharging:1; //bit 4,
  122. unsigned char :3; //bit5~7
  123. }bits[CONNECTOR_QUANTITY];
  124. }CpinitiateMsg;
  125. CpinitiateMsg cpinitateMsg;
  126. //GetConfiguration Array
  127. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  128. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  130. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  131. #if 0
  132. static char *ChargePointErrorCodeStr[] = {
  133. MACROSTR(ConnectorLockFailure),
  134. MACROSTR(EVCommunicationError),
  135. MACROSTR(GroundFailure),
  136. MACROSTR(HighTemperature),
  137. MACROSTR(InternalError),
  138. MACROSTR(LocalListConflict),
  139. MACROSTR(NoError),
  140. MACROSTR(OtherError),
  141. MACROSTR(OverCurrentFailure),
  142. MACROSTR(OverVoltage),
  143. MACROSTR(PowerMeterFailure),
  144. MACROSTR(PowerSwitchFailure),
  145. MACROSTR(ReaderFailure),
  146. MACROSTR(ResetFailure),
  147. MACROSTR(UnderVoltage),
  148. MACROSTR(WeakSignal)
  149. };
  150. #endif
  151. static char * ChargePointStatusStr[] = {
  152. MACROSTR(Available),
  153. MACROSTR(Preparing),
  154. MACROSTR(Charging),
  155. MACROSTR(SuspendedEVSE),
  156. MACROSTR(SuspendedEV),
  157. MACROSTR(Finishing),
  158. MACROSTR(Reserved),
  159. MACROSTR(Unavailable),
  160. MACROSTR(Faulted)
  161. };
  162. static char *RegistrationStatusStr[] = {
  163. MACROSTR(Accepted),
  164. MACROSTR(Pending),
  165. MACROSTR(Rejected)
  166. };
  167. static char *AvailabilityTypeStr[] = {
  168. MACROSTR(Inoperative),
  169. MACROSTR(Operative)
  170. };
  171. static char *AvailabilityStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(Scheduled)
  175. };
  176. static char *ConfigurationStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected),
  179. MACROSTR(RebootRequired),
  180. MACROSTR(NotSupported)
  181. };
  182. static char *ClearCacheStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected)
  185. };
  186. static char *ChargingProfilePurposeTypeStr[] = {
  187. MACROSTR(ChargePointMaxProfile),
  188. MACROSTR(TxDefaultProfile),
  189. MACROSTR(TxProfile)
  190. };
  191. static char *ChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Rejected),
  194. MACROSTR(NotSupported)
  195. };
  196. static char *ClearChargingProfileStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Unknown)
  199. };
  200. static char *GetCompositeScheduleStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Rejected)
  203. };
  204. static char *UpdateTypeStr[] = {
  205. MACROSTR(Differential),
  206. MACROSTR(Full)
  207. };
  208. static char *UpdateStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotSupported),
  212. MACROSTR(VersionMismatch)
  213. };
  214. static char *RemoteStartStopStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Rejected)
  217. };
  218. static char *ReservationStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Faulted),
  221. MACROSTR(Occupied),
  222. MACROSTR(Rejected),
  223. MACROSTR(Unavailable)
  224. };
  225. static char *ResetTypeStr[] = {
  226. MACROSTR(Hard),
  227. MACROSTR(Soft)
  228. };
  229. static char *ResetStatusStr[] = {
  230. MACROSTR(Accepted),
  231. MACROSTR(Rejected)
  232. };
  233. static char * DiagnosticsStatusStr[] = {
  234. MACROSTR(Idle),
  235. MACROSTR(Uploaded),
  236. MACROSTR(UploadFailed),
  237. MACROSTR(Uploading)
  238. };
  239. static char * FirmwareStatusStr[] = {
  240. MACROSTR(Downloaded),
  241. MACROSTR(DownloadFailed),
  242. MACROSTR(Downloading),
  243. MACROSTR(Idle),
  244. MACROSTR(InstallationFailed),
  245. MACROSTR(Installing),
  246. MACROSTR(Installed)
  247. };
  248. static char * MessageTriggerStr[] = {
  249. MACROSTR(BootNotification),
  250. MACROSTR(DiagnosticsStatusNotification),
  251. MACROSTR(FirmwareStatusNotification),
  252. MACROSTR(Heartbeat),
  253. MACROSTR(MeterValues),
  254. MACROSTR(StatusNotification)
  255. };
  256. static char * TriggerMessageStatusStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotImplemented)
  260. };
  261. static char * UnlockStatusStr[] = {
  262. MACROSTR(Unlocked),
  263. MACROSTR(UnlockFailed),
  264. MACROSTR(NotSupported)
  265. };
  266. #if 0
  267. static char * StopTransactionReasonStr[] = {
  268. MACROSTR(EmergencyStop),
  269. MACROSTR(EVDisconnected),
  270. MACROSTR(HardReset),
  271. MACROSTR(Local),
  272. MACROSTR(Other),
  273. MACROSTR(PowerLoss),
  274. MACROSTR(Reboot),
  275. MACROSTR(Remote),
  276. MACROSTR(SoftReset),
  277. MACROSTR(UnlockCommand),
  278. MACROSTR(DeAuthorized)
  279. };
  280. #endif
  281. static char * CancelReservationStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Rejected)
  284. };
  285. static char * ReadingContextStr[] = {
  286. MACROSTR(Interruption.Begin),
  287. MACROSTR(Interruption.End),
  288. MACROSTR(Other),
  289. MACROSTR(Sample.Clock),
  290. MACROSTR(Sample.Periodic),
  291. MACROSTR(Transaction.Begin),
  292. MACROSTR(Transaction.End),
  293. MACROSTR(Trigger)
  294. };
  295. static char * ValueFormatStr[] = {
  296. MACROSTR(Raw),
  297. MACROSTR(SignedData)
  298. };
  299. static char * MeasurandStr[] = {
  300. MACROSTR(Current.Export),
  301. MACROSTR(Current.Import),
  302. MACROSTR(Current.Offered),
  303. MACROSTR(Energy.Active.Export.Register),
  304. MACROSTR(Energy.Active.Import.Register),
  305. MACROSTR(Energy.Reactive.Export.Register),
  306. MACROSTR(Energy.Reactive.Import.Register),
  307. MACROSTR(Energy.Active.Export.Interval),
  308. MACROSTR(Energy.Active.Import.Interval),
  309. MACROSTR(Energy.Reactive.Export.Interval),
  310. MACROSTR(Energy.Reactive.Import.Interval),
  311. MACROSTR(Frequency),
  312. MACROSTR(Power.Active.Export),
  313. MACROSTR(Power.Active.Import),
  314. MACROSTR(Power.Factor),
  315. MACROSTR(Power.Offered),
  316. MACROSTR(Power.Reactive.ExportMACROSTR),
  317. MACROSTR(Power.Reactive.Import),
  318. MACROSTR(RPM),
  319. MACROSTR(SoC),
  320. MACROSTR(Temperature),
  321. MACROSTR(Voltage)
  322. };
  323. static char * LocationStr[] = {
  324. MACROSTR(Body),
  325. MACROSTR(Cable),
  326. MACROSTR(EV),
  327. MACROSTR(Inlet),
  328. MACROSTR(Outlet)
  329. };
  330. static char * PhaseStr[] = {
  331. MACROSTR(L1),
  332. MACROSTR(L2),
  333. MACROSTR(L3),
  334. MACROSTR(N),
  335. MACROSTR(L1-N),
  336. MACROSTR(L2-N),
  337. MACROSTR(L3-N),
  338. MACROSTR(L1-L2),
  339. MACROSTR(L2-L3),
  340. MACROSTR(L3-L1)
  341. };
  342. static char * UnitOfMeasureStr[] = {
  343. MACROSTR(Wh),
  344. MACROSTR(kWh),
  345. MACROSTR(varh),
  346. MACROSTR(kvarh),
  347. MACROSTR(W),
  348. MACROSTR(kW),
  349. MACROSTR(VA),
  350. MACROSTR(kVA),
  351. MACROSTR(var),
  352. MACROSTR(kvar),
  353. MACROSTR(A),
  354. MACROSTR(V),
  355. MACROSTR(Celsius),
  356. MACROSTR(Fahrenheit),
  357. MACROSTR(K),
  358. MACROSTR(Percent)
  359. };
  360. //=========================================
  361. // TTIA routine
  362. //=========================================
  363. int sendTTIAInfo(uint8_t gun_index)
  364. {
  365. static int sn = 0;
  366. int result = FAIL;
  367. struct hostent *server;
  368. int udp_socket_fd;
  369. struct sockaddr_in dest_addr = {0};
  370. uint8_t tx_buf[80] = {0};
  371. uint8_t logBuf[256]= {0};
  372. uint8_t tx_len, tempIndex, socStart, socEnd;
  373. uint16_t PresentChargedEnergy;
  374. struct tm tmStart, tmEnd;
  375. DEBUG_INFO("sendTTIAInfo...\n");
  376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  377. {
  378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  379. {
  380. tempIndex = ((gun_index==2) ? 1: 0);
  381. }
  382. else
  383. {
  384. tempIndex = gun_index;
  385. }
  386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  387. {
  388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  389. {
  390. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  391. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  392. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  393. }
  394. }
  395. }
  396. else if(gunType[gun_index] == GUN_TYPE_CCS)
  397. {
  398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  399. {
  400. tempIndex = ((gun_index==2) ? 1: 0);
  401. }
  402. else
  403. {
  404. tempIndex = gun_index;
  405. }
  406. for (int index = 0; index < CCS_QUANTITY; index++)
  407. {
  408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  409. {
  410. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  411. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  412. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  413. }
  414. }
  415. }
  416. else if(gunType[gun_index] == GUN_TYPE_GBT)
  417. {
  418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  419. {
  420. tempIndex = ((gun_index==2) ? 1: 0);
  421. }
  422. else
  423. {
  424. tempIndex = gun_index;
  425. }
  426. for (int index = 0; index < GB_QUANTITY; index++)
  427. {
  428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  429. {
  430. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  431. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  432. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  433. }
  434. }
  435. }
  436. else if(gunType[gun_index] == GUN_TYPE_DO)
  437. {
  438. tempIndex = gun_index;
  439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  440. {
  441. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  442. {
  443. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  444. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  445. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  446. }
  447. }
  448. }
  449. else
  450. {
  451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  452. {
  453. tempIndex = 2;
  454. }
  455. else
  456. {
  457. tempIndex = gun_index;
  458. }
  459. for (int index = 0; index < AC_QUANTITY; index++)
  460. {
  461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  462. {
  463. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  464. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  465. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  466. }
  467. }// END
  468. }
  469. // Message assembly
  470. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  471. tx_buf[4] = 0x02; // Protocol Version
  472. tx_buf[5] = 0xb0; // Message ID
  473. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  474. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  475. tx_buf[8] = 0x00; // CarID low byte
  476. tx_buf[9] = 0x00; // CarID high byte
  477. tx_buf[10] = 0x00; // ID Storage
  478. tx_buf[11] = 0x00; // Driver lowest byte
  479. tx_buf[12] = 0x00; // Driver 2nd byte
  480. tx_buf[13] = 0x00; // Driver 3rd byte
  481. tx_buf[14] = 0x00; // Driver highest byte
  482. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  483. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  484. tx_buf[17] = 0x00; // Reserve
  485. tx_buf[18] = 60 & 0xff; // Payload length low byte
  486. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  487. // EVSE provider
  488. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  489. // EVSE provider
  490. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  491. // EVSE id
  492. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  493. // Connector id
  494. tx_buf[37] = gun_index;
  495. // EVSE station
  496. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  497. // Vehicle SN
  498. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  499. // Mileage
  500. tx_buf[61] = 0x00; // lowest byte
  501. tx_buf[62] = 0x00; // 2nd byte
  502. tx_buf[63] = 0x00; // highest byte
  503. // Start date time 6 bytes
  504. 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))
  505. {
  506. struct tm *tmTarget;
  507. struct timeb tbTarget;
  508. tmStart.tm_year -= 1900;
  509. tmStart.tm_mon -= 1;
  510. tmStart.tm_gmtoff = 0;
  511. tbTarget.time = mktime(&tmStart);
  512. tbTarget.timezone = 0;
  513. tbTarget.time += (8*3600);
  514. tmTarget = gmtime(&tbTarget.time);
  515. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  516. tx_buf[65] = (tmTarget->tm_mon+1);
  517. tx_buf[66] = tmTarget->tm_mday;
  518. tx_buf[67] = tmTarget->tm_hour;
  519. tx_buf[68] = tmTarget->tm_min;
  520. tx_buf[69] = tmTarget->tm_sec;
  521. }
  522. // Stop date time 6 bytes
  523. 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))
  524. {
  525. struct tm *tmTarget;
  526. struct timeb tbTarget;
  527. tmEnd.tm_year -= 1900;
  528. tmEnd.tm_mon -= 1;
  529. tmEnd.tm_gmtoff = 0;
  530. tbTarget.time = mktime(&tmEnd);
  531. tbTarget.timezone = 0;
  532. tbTarget.time += (8*3600);
  533. tmTarget = gmtime(&tbTarget.time);
  534. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  535. tx_buf[71] = (tmTarget->tm_mon+1);
  536. tx_buf[72] = tmTarget->tm_mday;
  537. tx_buf[73] = tmTarget->tm_hour;
  538. tx_buf[74] = tmTarget->tm_min;
  539. tx_buf[75] = tmTarget->tm_sec;
  540. }
  541. // Session energy 2 bytes
  542. tx_buf[76] = PresentChargedEnergy & 0xff;
  543. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  544. // Start SOC 1 byte
  545. tx_buf[78] = socStart;
  546. // Stop SOC 1 byte
  547. tx_buf[79] = socEnd;
  548. // Open socket
  549. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  550. if(udp_socket_fd == -1)
  551. {
  552. DEBUG_ERROR("UDP socket create failed!\n");
  553. }
  554. else
  555. {
  556. // Get server DNS entry
  557. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  558. if (server == NULL)
  559. {
  560. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  561. }
  562. else
  563. {
  564. // Build the server's Internet address
  565. bzero((char *) &dest_addr, sizeof(dest_addr));
  566. dest_addr.sin_family = AF_INET;
  567. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  568. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  569. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  570. {
  571. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  572. {
  573. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  574. }
  575. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  576. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  577. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  578. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  579. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  580. DEBUG_TTIA_INFO("---------- Header ----------\n");
  581. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  582. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  583. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  584. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  585. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  586. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  587. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  588. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  589. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  590. DEBUG_TTIA_INFO("Len: 0x3C\n");
  591. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  592. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  593. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  594. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  595. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  596. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  597. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  598. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  599. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  600. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  602. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  603. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  604. DEBUG_TTIA_INFO("=========================================\n");
  605. sn++;
  606. result = PASS;
  607. }
  608. else
  609. {
  610. DEBUG_ERROR("UDP sent out fail.\n");
  611. }
  612. }
  613. }
  614. return result;
  615. }
  616. //=========================================
  617. // Save configuration
  618. //=========================================
  619. int runShellCmd(const char*cmd)
  620. {
  621. int result = FAIL;
  622. char buf[256];
  623. FILE *fp;
  624. fp = popen(cmd, "r");
  625. if(fp != NULL)
  626. {
  627. while(fgets(buf, sizeof(buf), fp) != NULL)
  628. {
  629. DEBUG_INFO("%s\n", buf);
  630. }
  631. result = PASS;
  632. }
  633. pclose(fp);
  634. return result;
  635. }
  636. int StoreUsrConfigData(struct SysConfigData *UsrData)
  637. {
  638. int result = PASS;
  639. int fd,wrd;
  640. unsigned int i,Chk;
  641. unsigned char *ptr, *BufTmp;
  642. int MtdBlockSize = 0x300000;
  643. Chk=0;
  644. ptr=(unsigned char *)UsrData;
  645. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  646. {
  647. memset(BufTmp,0,MtdBlockSize);
  648. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  649. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  650. Chk+=*(BufTmp+i);
  651. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  652. // Output configuration to file.
  653. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  654. if (fd < 0)
  655. {
  656. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  657. free(BufTmp);
  658. return 0;
  659. }
  660. wrd=write(fd, BufTmp, MtdBlockSize);
  661. close(fd);
  662. if(wrd<MtdBlockSize)
  663. {
  664. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  665. free(BufTmp);
  666. return 0;
  667. }
  668. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  669. DEBUG_INFO("Erase /dev/mtd10.\n");
  670. runShellCmd("flash_erase /dev/mtd10 0 0");
  671. DEBUG_INFO("Write /dev/mtd10.\n");
  672. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  673. DEBUG_INFO("Erase /dev/mtd11.\n");
  674. runShellCmd("flash_erase /dev/mtd11 0 0");
  675. DEBUG_INFO("Write /dev/mtd11.\n");
  676. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  677. system("rm -f /mnt/EvseConfig.bin");
  678. DEBUG_INFO("EvseConfig write to flash OK\n");
  679. }
  680. else
  681. {
  682. DEBUG_ERROR("alloc BlockSize NG\r\n");
  683. result = FAIL;
  684. }
  685. if(BufTmp!=NULL)
  686. free(BufTmp);
  687. return result;
  688. }
  689. //=========================================
  690. // Sqlite3 related function
  691. //=========================================
  692. static int selectSqlCount = 0;
  693. static int callback(void *data, int argc, char **argv, char **azColName){
  694. int i;
  695. //printf("%s: ", (const char*)data);
  696. selectSqlCount = argc;
  697. for(i = 0; i<argc; i++){
  698. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  699. }
  700. //printf("\n");
  701. return 0;
  702. }
  703. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  704. //int i;
  705. //printf("%s:\n", (const char*)data);
  706. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  707. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  708. return 0;
  709. }
  710. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  711. //printf("%s:\n", (const char*)data);
  712. //idTag
  713. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  714. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. //parentIdTag
  716. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  717. //expir_date
  718. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  719. //status
  720. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  721. //version
  722. if(columenCount > 5)
  723. idTagQuery.listVersionInt = atoi(columnValue[5]);
  724. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  725. return 0;
  726. }
  727. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  728. {
  729. // localversion = argv[5] ? atoi(argv[5]) : 0;
  730. // printf("localversion=%d\n", localversion);
  731. return 0;
  732. }
  733. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  734. {
  735. for (int i = 0; i < n_columns; i++)
  736. {
  737. DEBUG_INFO("%s\t", col_values[i]);
  738. }
  739. DEBUG_INFO("\n");
  740. return 0;
  741. }
  742. int OCPP_cleanLocalCache()
  743. {
  744. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  745. char *errMsg = 0;
  746. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  747. if (SQLITE_OK != rc)
  748. {
  749. DEBUG_INFO("SQL error: %s\n",errMsg);
  750. return FALSE;
  751. }
  752. return TRUE;
  753. }
  754. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  755. {
  756. int isSuccess = TRUE;
  757. int ret = 0;
  758. //const char* data = "Callback function called";
  759. char sql[300];
  760. char zErrMsg[200];
  761. memset(sql, 0, 300);
  762. memset(zErrMsg, 0, 200);
  763. 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);
  764. //* Execute SQL statement */
  765. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  766. if( ret != SQLITE_OK )
  767. {
  768. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  769. isSuccess = FALSE;
  770. }
  771. return isSuccess;
  772. }
  773. void OCPP_getIdTagFromLocalCache(char idTag[])
  774. {
  775. int rc = 0;
  776. char sql[100];
  777. char zErrMsg[100];
  778. memset(sql, 0, 100);
  779. memset(zErrMsg, 0, 100);
  780. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  781. memset(&idTagQuery, 0, sizeof(idTagQuery));
  782. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  783. /* Execute SQL statement */
  784. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  785. if( rc != SQLITE_OK )
  786. {
  787. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  788. }
  789. }
  790. void OCPP_getListVerion()
  791. {
  792. int rc = 0;
  793. // const char* data = "Callback function called";
  794. char sql[100];
  795. char zErrMsg[100];
  796. memset(sql, 0, 100);
  797. memset(zErrMsg, 0, 100);
  798. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  799. /* Execute SQL statement */
  800. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  801. if( rc != SQLITE_OK )
  802. {
  803. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  804. }
  805. }
  806. void OCPP_get_TableAuthlocalAllData(void)
  807. {
  808. int rc = 0;
  809. char sql[100];
  810. char zErrMsg[100];
  811. memset(sql, 0, 100);
  812. memset(zErrMsg, 0, 100);
  813. sprintf(sql,"select * from ocpp_auth_local ");
  814. /* Execute SQL statement */
  815. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  816. if( rc != SQLITE_OK )
  817. {
  818. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  819. }
  820. //return ver;
  821. }
  822. int OCPP_cleanLocalList()
  823. {
  824. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  825. char *errMsg = 0;
  826. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  827. if (SQLITE_OK != rc)
  828. {
  829. DEBUG_INFO("%s\n",errMsg);
  830. return FALSE;
  831. }
  832. return TRUE;
  833. }
  834. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  835. {
  836. int isSuccess = FALSE;
  837. int ret = 0;
  838. //const char* data = "Callback function called";
  839. char sql[300];
  840. char zErrMsg[200];
  841. memset(sql, 0, 300);
  842. memset(zErrMsg, 0, 200);
  843. 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);
  844. //* Execute SQL statement */
  845. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  846. if( ret != SQLITE_OK )
  847. {
  848. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  849. return isSuccess;
  850. }
  851. memset(sql, 0, 300);
  852. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  853. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  854. if( ret != SQLITE_OK )
  855. {
  856. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  857. return isSuccess;
  858. }
  859. isSuccess = TRUE;
  860. return isSuccess;
  861. }
  862. void OCPP_getIdTagFromLocalList(char idTag[])
  863. {
  864. int rc = 0;
  865. // const char* data = "Callback function called";
  866. char sql[100];
  867. char zErrMsg[100];
  868. memset(sql, 0, 100);
  869. memset(zErrMsg, 0, 100);
  870. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  871. memset(&idTagQuery, 0, sizeof(idTagQuery));
  872. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  873. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  874. /* Execute SQL statement */
  875. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  876. if( rc != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. }
  880. //return ver;
  881. }
  882. void OCPP_deleteIdTagFromLocalList(char idTag[])
  883. {
  884. //int ver = 0;
  885. //int isSuccess = FALSE;
  886. int rc = 0;
  887. char sql[100];
  888. char zErrMsg[100];
  889. memset(sql, 0, 100);
  890. memset(zErrMsg, 0, 100);
  891. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  892. //* Execute SQL statement */
  893. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  894. if( rc != SQLITE_OK )
  895. {
  896. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  897. }
  898. }
  899. int getCurrentYear()
  900. {
  901. int result = 0;
  902. time_t CurrentTime;
  903. struct tm *tm;
  904. CurrentTime = time(NULL);
  905. tm=localtime(&CurrentTime);
  906. result = (tm->tm_year + 1900);
  907. return result;
  908. }
  909. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  910. {
  911. int result = PASS;
  912. char* errMsg = NULL;
  913. char sqlStr[8192];
  914. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  919. }
  920. 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));
  921. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  922. {
  923. result = FAIL;
  924. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  925. }
  926. return result;
  927. }
  928. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  929. {
  930. int isSuccess = TRUE;
  931. int tempIndex;
  932. json_object *EnergyDataTransfer = json_object_new_object();
  933. json_object *periodEnergys = json_object_new_object();
  934. char sql[1024];
  935. char zErrMsg[200];
  936. memset(sql, 0, ARRAY_SIZE(sql));
  937. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  939. {
  940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  941. {
  942. tempIndex = ((gun_index==2) ? 1: 0);
  943. }
  944. else
  945. {
  946. tempIndex = gun_index;
  947. }
  948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  949. {
  950. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  951. {
  952. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  953. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  954. {
  955. uint8_t period[3];
  956. sprintf((char*)period, "%d", idxPeriod);
  957. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  958. }
  959. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  960. } //end of the same index
  961. }//end of for CHAdeMO_QUANTITY
  962. }
  963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  964. {
  965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  966. {
  967. tempIndex = ((gun_index==2) ? 1: 0);
  968. }
  969. else
  970. {
  971. tempIndex = gun_index;
  972. }
  973. for (int index = 0; index < CCS_QUANTITY; index++)
  974. {
  975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  976. {
  977. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  978. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  979. {
  980. uint8_t period[3];
  981. sprintf((char*)period, "%d", idxPeriod);
  982. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  983. }
  984. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  985. } //end of the same index
  986. } // end of for CCS_QUANTITY
  987. }
  988. else if(gunType[gun_index] == GUN_TYPE_GBT)
  989. {
  990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  991. {
  992. tempIndex = ((gun_index==2) ? 1: 0);
  993. }
  994. else
  995. {
  996. tempIndex = gun_index;
  997. }
  998. for (int index = 0; index < GB_QUANTITY; index++)
  999. {
  1000. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1001. {
  1002. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1003. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1004. {
  1005. uint8_t period[3];
  1006. sprintf((char*)period, "%d", idxPeriod);
  1007. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1008. }
  1009. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1010. } //end of the same index
  1011. } // end of for GB_QUANTITY
  1012. }
  1013. else if(gunType[gun_index] == GUN_TYPE_DO)
  1014. {
  1015. tempIndex = gun_index;
  1016. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1017. {
  1018. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1019. {
  1020. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1021. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1022. {
  1023. uint8_t period[3];
  1024. sprintf((char*)period, "%d", idxPeriod);
  1025. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1026. }
  1027. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1028. } //end of the same index
  1029. }
  1030. }
  1031. else
  1032. {
  1033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1034. {
  1035. tempIndex = 2;
  1036. }
  1037. else
  1038. {
  1039. tempIndex = gun_index;
  1040. }
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1044. {
  1045. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1046. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1047. {
  1048. uint8_t period[3];
  1049. sprintf((char*)period, "%d", idxPeriod);
  1050. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1051. }
  1052. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1053. }//end of the same index
  1054. }//end of for AC_QUANTITY
  1055. }
  1056. 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));
  1057. json_object_put(EnergyDataTransfer);
  1058. //* Execute SQL statement */
  1059. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1060. {
  1061. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1062. isSuccess = FALSE;
  1063. }
  1064. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1065. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1066. {
  1067. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1068. isSuccess = FALSE;
  1069. }
  1070. return isSuccess;
  1071. }
  1072. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1073. {
  1074. int isSuccess = TRUE;
  1075. char sql[512];
  1076. char zErrMsg[200];
  1077. int rows, cols;
  1078. char **resultData;
  1079. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1080. /* Execute SQL statement */
  1081. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1082. {
  1083. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1084. isSuccess = FALSE;
  1085. }
  1086. else
  1087. {
  1088. if((rows > 0) && (atoi(resultData[4]) > 0))
  1089. {
  1090. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1091. }
  1092. else
  1093. {
  1094. DEBUG_WARN("There is not match transaction data.\n");
  1095. isSuccess = FALSE;
  1096. }
  1097. }
  1098. return isSuccess;
  1099. }
  1100. 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)
  1101. {
  1102. int result = PASS;
  1103. char* errMsg = NULL;
  1104. char sqlStr[8192];
  1105. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1106. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1107. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1108. {
  1109. result = FAIL;
  1110. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1111. }
  1112. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1113. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1114. {
  1115. result = FAIL;
  1116. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1117. }
  1118. return result;
  1119. }
  1120. int OCPP_update_deduct_info(int txId, char *creditNo)
  1121. {
  1122. int result = PASS;
  1123. char* errMsg = NULL;
  1124. char sqlStr[8192];
  1125. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1126. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1127. {
  1128. result = FAIL;
  1129. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1130. }
  1131. return result;
  1132. }
  1133. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1134. {
  1135. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1138. atoi(columnValue[1]),
  1139. columnValue[2],
  1140. atoi(columnValue[3])==1?"true":"false",
  1141. atoi(columnValue[4])==1?"true":"false",
  1142. columnValue[5],
  1143. columnValue[9]);
  1144. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1145. return 0;
  1146. }
  1147. void OCPP_query_deduct_info()
  1148. {
  1149. int rc = 0;
  1150. char sql[100];
  1151. char zErrMsg[100];
  1152. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1153. /* Execute SQL statement */
  1154. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1155. if( rc != SQLITE_OK )
  1156. {
  1157. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1158. }
  1159. }
  1160. void reportReaderStatus(int gun_index)
  1161. {
  1162. struct timeval tmnow;
  1163. struct tm *tm;
  1164. char buf[28];//, usec_buf[6];
  1165. gettimeofday(&tmnow, NULL);
  1166. time_t t;
  1167. t = time(NULL);
  1168. /*UTC time and date*/
  1169. tm = gmtime(&t);
  1170. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1171. #if 0 // remove temporally
  1172. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1173. strcat(buf,".");
  1174. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1175. strcat(buf,usec_buf);
  1176. #endif
  1177. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1180. (gun_index+1),
  1181. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1182. buf,
  1183. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1184. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1185. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1186. ShmOCPP16Data->CsMsg.bits[gun_index].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. struct ParsingResult
  1352. {
  1353. int result;
  1354. int scanedElement;
  1355. int year;
  1356. int month;
  1357. int mday;
  1358. int hour;
  1359. int min;
  1360. int sec;
  1361. int tz_hour;
  1362. int tz_min;
  1363. float minSec;
  1364. };
  1365. struct ParsingResult parseStart;
  1366. struct ParsingResult parseStop;
  1367. int result = -1;
  1368. struct tm tmStart;
  1369. struct timeb tbStart;
  1370. struct tm tmStop;
  1371. struct timeb tbStop;
  1372. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1373. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1374. // Scan start & stop date time
  1375. if(strstr((char*)start, ".") != NULL)
  1376. {
  1377. // Original data with mini second
  1378. if(strstr((char*)start, "Z") != NULL)
  1379. {
  1380. // Original data with Z
  1381. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1382. &parseStart.year,
  1383. &parseStart.month,
  1384. &parseStart.mday,
  1385. &parseStart.hour,
  1386. &parseStart.min,
  1387. &parseStart.sec,
  1388. &parseStart.minSec);
  1389. }
  1390. else
  1391. {
  1392. // Original data without Z
  1393. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1394. &parseStart.year,
  1395. &parseStart.month,
  1396. &parseStart.mday,
  1397. &parseStart.hour,
  1398. &parseStart.min,
  1399. &parseStart.sec,
  1400. &parseStart.minSec,
  1401. &parseStart.tz_hour,
  1402. &parseStart.tz_min);
  1403. }
  1404. }
  1405. else
  1406. {
  1407. // Original data without mini second
  1408. if(strstr((char*)start, "Z") != NULL)
  1409. {
  1410. // Original data with Z
  1411. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1412. &parseStart.year,
  1413. &parseStart.month,
  1414. &parseStart.mday,
  1415. &parseStart.hour,
  1416. &parseStart.min,
  1417. &parseStart.sec);
  1418. }
  1419. else
  1420. {
  1421. // Original data without Z
  1422. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1423. &parseStart.year,
  1424. &parseStart.month,
  1425. &parseStart.mday,
  1426. &parseStart.hour,
  1427. &parseStart.min,
  1428. &parseStart.sec,
  1429. &parseStart.tz_hour,
  1430. &parseStart.tz_min);
  1431. }
  1432. }
  1433. if(strstr((char*)stop, ".") != NULL)
  1434. {
  1435. // Original data with mini second
  1436. if(strstr((char*)stop, "Z") != NULL)
  1437. {
  1438. // Original data with Z
  1439. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1440. &parseStop.year,
  1441. &parseStop.month,
  1442. &parseStop.mday,
  1443. &parseStop.hour,
  1444. &parseStop.min,
  1445. &parseStop.sec,
  1446. &parseStop.minSec);
  1447. }
  1448. else
  1449. {
  1450. // Original data without Z
  1451. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1452. &parseStop.year,
  1453. &parseStop.month,
  1454. &parseStop.mday,
  1455. &parseStop.hour,
  1456. &parseStop.min,
  1457. &parseStop.sec,
  1458. &parseStop.minSec,
  1459. &parseStop.tz_hour,
  1460. &parseStop.tz_min);
  1461. }
  1462. }
  1463. else
  1464. {
  1465. // Original data without mini second
  1466. if(strstr((char*)stop, "Z") != NULL)
  1467. {
  1468. // Original data with Z
  1469. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1470. &parseStop.year,
  1471. &parseStop.month,
  1472. &parseStop.mday,
  1473. &parseStop.hour,
  1474. &parseStop.min,
  1475. &parseStop.sec);
  1476. }
  1477. else
  1478. {
  1479. // Original data without Z
  1480. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1481. &parseStop.year,
  1482. &parseStop.month,
  1483. &parseStop.mday,
  1484. &parseStop.hour,
  1485. &parseStop.min,
  1486. &parseStop.sec,
  1487. &parseStop.tz_hour,
  1488. &parseStop.tz_min);
  1489. }
  1490. }
  1491. // Calculate date time difference
  1492. if((parseStart.scanedElement >=6) &&
  1493. (parseStop.scanedElement >=6))
  1494. {
  1495. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1496. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1497. tmStart.tm_year = parseStart.year - 1900;
  1498. tmStart.tm_mon = parseStart.month - 1;
  1499. tmStart.tm_mday = parseStart.mday;
  1500. tmStart.tm_hour = parseStart.hour;
  1501. tmStart.tm_min = parseStart.min;
  1502. tmStart.tm_sec = parseStart.sec;
  1503. tmStart.tm_gmtoff = 0;
  1504. tbStart.time = mktime(&tmStart);
  1505. tbStart.timezone = 0;
  1506. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1507. tmStop.tm_year = parseStop.year - 1900;
  1508. tmStop.tm_mon = parseStop.month - 1;
  1509. tmStop.tm_mday = parseStop.mday;
  1510. tmStop.tm_hour = parseStop.hour;
  1511. tmStop.tm_min = parseStop.min;
  1512. tmStop.tm_sec = parseStop.sec;
  1513. tmStop.tm_gmtoff = 0;
  1514. tbStop.time = mktime(&tmStop);
  1515. tbStop.timezone = 0;
  1516. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1517. result = DiffTimebSec(tbStart, tbStop);
  1518. //DEBUG_INFO("getStartStop(): %d\n", result);
  1519. }
  1520. else
  1521. {
  1522. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1523. }
  1524. return result;
  1525. }
  1526. int isOvertNow(uint8_t *start)
  1527. {
  1528. int result = NO;
  1529. struct ParsingResult
  1530. {
  1531. int result;
  1532. int scanedElement;
  1533. int year;
  1534. int month;
  1535. int mday;
  1536. int hour;
  1537. int min;
  1538. int sec;
  1539. int tz_hour;
  1540. int tz_min;
  1541. float minSec;
  1542. }parsingResult;
  1543. struct tm tmStart;
  1544. struct timeb tbStart;
  1545. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1546. if(strstr((char*)start, ".") != NULL)
  1547. {
  1548. // Original data with mini second
  1549. if(strstr((char*)start, "Z") != NULL)
  1550. {
  1551. // Original data with Z
  1552. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1553. &parsingResult.year,
  1554. &parsingResult.month,
  1555. &parsingResult.mday,
  1556. &parsingResult.hour,
  1557. &parsingResult.min,
  1558. &parsingResult.sec,
  1559. &parsingResult.minSec);
  1560. }
  1561. else
  1562. {
  1563. // Original data without Z
  1564. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1565. &parsingResult.year,
  1566. &parsingResult.month,
  1567. &parsingResult.mday,
  1568. &parsingResult.hour,
  1569. &parsingResult.min,
  1570. &parsingResult.sec,
  1571. &parsingResult.minSec,
  1572. &parsingResult.tz_hour,
  1573. &parsingResult.tz_min);
  1574. }
  1575. }
  1576. else
  1577. {
  1578. // Original data without mini second
  1579. if(strstr((char*)start, "Z") != NULL)
  1580. {
  1581. // Original data with Z
  1582. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1583. &parsingResult.year,
  1584. &parsingResult.month,
  1585. &parsingResult.mday,
  1586. &parsingResult.hour,
  1587. &parsingResult.min,
  1588. &parsingResult.sec);
  1589. }
  1590. else
  1591. {
  1592. // Original data without Z
  1593. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1594. &parsingResult.year,
  1595. &parsingResult.month,
  1596. &parsingResult.mday,
  1597. &parsingResult.hour,
  1598. &parsingResult.min,
  1599. &parsingResult.sec,
  1600. &parsingResult.tz_hour,
  1601. &parsingResult.tz_min);
  1602. }
  1603. }
  1604. if(parsingResult.scanedElement >= 6)
  1605. {
  1606. tmStart.tm_year = parsingResult.year - 1900;
  1607. tmStart.tm_mon = parsingResult.month - 1;
  1608. tmStart.tm_mday = parsingResult.mday;
  1609. tmStart.tm_hour = parsingResult.hour;
  1610. tmStart.tm_min = parsingResult.min;
  1611. tmStart.tm_sec = parsingResult.sec;
  1612. tmStart.tm_gmtoff = 0;
  1613. tbStart.time = mktime(&tmStart);
  1614. tbStart.timezone = 0;
  1615. tbStart.millitm = 0;
  1616. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1617. if(DiffTimebWithNowSec(tbStart) <= 0)
  1618. result = NO;
  1619. else
  1620. result = YES;
  1621. }
  1622. else
  1623. {
  1624. DEBUG_WARN("Start date parsing error.\n");
  1625. }
  1626. return result;
  1627. }
  1628. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1629. {
  1630. struct ParsingResult
  1631. {
  1632. int result;
  1633. int scanedElement;
  1634. int year;
  1635. int month;
  1636. int mday;
  1637. int hour;
  1638. int min;
  1639. int sec;
  1640. int tz_hour;
  1641. int tz_min;
  1642. float minSec;
  1643. };
  1644. struct ParsingResult parseStart;
  1645. struct ParsingResult parseStop;
  1646. int result = -1;
  1647. struct tm tmStart;
  1648. struct timeb tbStart;
  1649. struct tm tmStop;
  1650. struct timeb tbStop;
  1651. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1652. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1653. // Scan start & stop date time
  1654. if(strstr((char*)start, ".") != NULL)
  1655. {
  1656. // Original data with mini second
  1657. if(strstr((char*)start, "Z") != NULL)
  1658. {
  1659. // Original data with Z
  1660. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1661. &parseStart.year,
  1662. &parseStart.month,
  1663. &parseStart.mday,
  1664. &parseStart.hour,
  1665. &parseStart.min,
  1666. &parseStart.sec,
  1667. &parseStart.minSec);
  1668. }
  1669. else
  1670. {
  1671. // Original data without Z
  1672. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1673. &parseStart.year,
  1674. &parseStart.month,
  1675. &parseStart.mday,
  1676. &parseStart.hour,
  1677. &parseStart.min,
  1678. &parseStart.sec,
  1679. &parseStart.minSec,
  1680. &parseStart.tz_hour,
  1681. &parseStart.tz_min);
  1682. }
  1683. }
  1684. else
  1685. {
  1686. // Original data without mini second
  1687. if(strstr((char*)start, "Z") != NULL)
  1688. {
  1689. // Original data with Z
  1690. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1691. &parseStart.year,
  1692. &parseStart.month,
  1693. &parseStart.mday,
  1694. &parseStart.hour,
  1695. &parseStart.min,
  1696. &parseStart.sec);
  1697. }
  1698. else
  1699. {
  1700. // Original data without Z
  1701. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1702. &parseStart.year,
  1703. &parseStart.month,
  1704. &parseStart.mday,
  1705. &parseStart.hour,
  1706. &parseStart.min,
  1707. &parseStart.sec,
  1708. &parseStart.tz_hour,
  1709. &parseStart.tz_min);
  1710. }
  1711. }
  1712. if(strstr((char*)stop, ".") != NULL)
  1713. {
  1714. // Original data with mini second
  1715. if(strstr((char*)stop, "Z") != NULL)
  1716. {
  1717. // Original data with Z
  1718. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1719. &parseStop.year,
  1720. &parseStop.month,
  1721. &parseStop.mday,
  1722. &parseStop.hour,
  1723. &parseStop.min,
  1724. &parseStop.sec,
  1725. &parseStop.minSec);
  1726. }
  1727. else
  1728. {
  1729. // Original data without Z
  1730. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1731. &parseStop.year,
  1732. &parseStop.month,
  1733. &parseStop.mday,
  1734. &parseStop.hour,
  1735. &parseStop.min,
  1736. &parseStop.sec,
  1737. &parseStop.minSec,
  1738. &parseStop.tz_hour,
  1739. &parseStop.tz_min);
  1740. }
  1741. }
  1742. else
  1743. {
  1744. // Original data without mini second
  1745. if(strstr((char*)stop, "Z") != NULL)
  1746. {
  1747. // Original data with Z
  1748. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1749. &parseStop.year,
  1750. &parseStop.month,
  1751. &parseStop.mday,
  1752. &parseStop.hour,
  1753. &parseStop.min,
  1754. &parseStop.sec);
  1755. }
  1756. else
  1757. {
  1758. // Original data without Z
  1759. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1760. &parseStop.year,
  1761. &parseStop.month,
  1762. &parseStop.mday,
  1763. &parseStop.hour,
  1764. &parseStop.min,
  1765. &parseStop.sec,
  1766. &parseStop.tz_hour,
  1767. &parseStop.tz_min);
  1768. }
  1769. }
  1770. // Calculate date time difference
  1771. if((parseStart.scanedElement >=6) &&
  1772. (parseStop.scanedElement >=6))
  1773. {
  1774. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1775. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1776. tmStart.tm_year = parseStart.year - 1900;
  1777. tmStart.tm_mon = parseStart.month - 1;
  1778. tmStart.tm_mday = parseStart.mday;
  1779. tmStart.tm_hour = parseStart.hour;
  1780. tmStart.tm_min = parseStart.min;
  1781. tmStart.tm_sec = parseStart.sec;
  1782. tmStart.tm_gmtoff = 0;
  1783. tbStart.time = mktime(&tmStart);
  1784. tbStart.timezone = 0;
  1785. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1786. tmStop.tm_year = parseStop.year - 1900;
  1787. tmStop.tm_mon = parseStop.month - 1;
  1788. tmStop.tm_mday = parseStop.mday;
  1789. tmStop.tm_hour = parseStop.hour;
  1790. tmStop.tm_min = parseStop.min;
  1791. tmStop.tm_sec = parseStop.sec;
  1792. tmStop.tm_gmtoff = 0;
  1793. tbStop.time = mktime(&tmStop);
  1794. tbStop.timezone = 0;
  1795. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1796. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1797. //DEBUG_INFO("getStartStop(): %d\n", result);
  1798. }
  1799. else
  1800. {
  1801. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1802. }
  1803. return result;
  1804. }
  1805. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1806. {
  1807. FILE *fp;
  1808. char profileFileName[128];
  1809. char *line = NULL;
  1810. size_t len = 0;
  1811. time_t CurrentTime;
  1812. struct tm *tmComposite;
  1813. struct StructChargingProfile maxProfile;
  1814. struct StructChargingProfile compositeProfile;
  1815. uint8_t limitMax=0;
  1816. int compositePeriodIdx = 0;
  1817. CurrentTime = time(NULL);
  1818. tmComposite=localtime(&CurrentTime);
  1819. 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);
  1820. if(isUnitA)
  1821. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1822. else
  1823. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1824. compositeProfile.ChargingSchedule.Duration = durationReq;
  1825. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1826. {
  1827. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1829. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1830. }
  1831. compositeProfile.ChargingProfileId = 0;
  1832. compositeProfile.StackLevel = 99 ;
  1833. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1834. maxProfile.ChargingProfileId = -1;
  1835. maxProfile.ChargingSchedule.Duration = -1;
  1836. system("rm -f /tmp/*.json");
  1837. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1838. // Search max profile
  1839. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1840. if((access(profileFileName, F_OK))!=-1)
  1841. {
  1842. fp = fopen(profileFileName, "r");
  1843. while(getline(&line, &len, fp) != -1)
  1844. {
  1845. json_object *obj = NULL;
  1846. obj = json_tokener_parse(line);
  1847. if(is_error(obj))
  1848. {
  1849. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1850. }
  1851. else
  1852. {
  1853. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1854. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1855. )
  1856. {
  1857. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1858. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1859. )
  1860. {
  1861. struct tm tmFrom, tmTo;
  1862. struct timeb tbFrom, tbTo;
  1863. 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) &&
  1864. (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))
  1865. {
  1866. tmFrom.tm_year -= 1900;
  1867. tmFrom.tm_mon -= 1;
  1868. tbFrom.time = mktime(&tmFrom);
  1869. tmTo.tm_year -= 1900;
  1870. tmTo.tm_mon -= 1;
  1871. tbTo.time = mktime(&tmTo);
  1872. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1873. {
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. if(maxProfile.ChargingProfileId == -1)
  1881. DEBUG_INFO("MaxProfile found.\n");
  1882. else
  1883. DEBUG_INFO("MaxProfile updated.\n");
  1884. // Required item
  1885. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1886. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1887. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1888. if(isUnitA)
  1889. {
  1890. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1891. 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++)
  1892. {
  1893. 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"));
  1894. 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?
  1895. 3:
  1896. 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")));
  1897. 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")));
  1898. }
  1899. }
  1900. else
  1901. {
  1902. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1903. 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++)
  1904. {
  1905. 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"));
  1906. 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?
  1907. 3:
  1908. 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")));
  1909. 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));
  1910. }
  1911. }
  1912. // Optional item
  1913. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1914. {
  1915. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1916. }
  1917. else
  1918. {
  1919. sprintf((char*)maxProfile.ValidFrom, " ");
  1920. }
  1921. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1922. {
  1923. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1924. }
  1925. else
  1926. {
  1927. sprintf((char*)maxProfile.ValidTo, " ");
  1928. }
  1929. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1930. {
  1931. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1932. }
  1933. else
  1934. {
  1935. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1936. }
  1937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1938. {
  1939. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1940. }
  1941. else
  1942. {
  1943. maxProfile.TransactionId = -1;
  1944. }
  1945. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1946. {
  1947. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1948. }
  1949. else
  1950. {
  1951. maxProfile.ChargingSchedule.Duration = 86400;
  1952. }
  1953. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1954. {
  1955. 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")));
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1960. }
  1961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1962. {
  1963. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1964. }
  1965. else
  1966. {
  1967. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1968. }
  1969. }
  1970. }
  1971. }
  1972. else
  1973. {
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1979. }
  1980. if(maxProfile.ChargingProfileId == -1)
  1981. DEBUG_INFO("MaxProfile found.\n");
  1982. else
  1983. DEBUG_INFO("MaxProfile updated.\n");
  1984. // Required item
  1985. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1986. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1987. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1988. if(isUnitA)
  1989. {
  1990. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1991. 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++)
  1992. {
  1993. 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"));
  1994. 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?
  1995. 3:
  1996. 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")));
  1997. 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")));
  1998. }
  1999. }
  2000. else
  2001. {
  2002. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2003. 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++)
  2004. {
  2005. 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"));
  2006. 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?
  2007. 3:
  2008. 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")));
  2009. 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));
  2010. }
  2011. }
  2012. // Optional item
  2013. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2014. {
  2015. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2016. }
  2017. else
  2018. {
  2019. sprintf((char*)maxProfile.ValidFrom, " ");
  2020. }
  2021. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2022. {
  2023. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2024. }
  2025. else
  2026. {
  2027. sprintf((char*)maxProfile.ValidTo, " ");
  2028. }
  2029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2030. {
  2031. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2032. }
  2033. else
  2034. {
  2035. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2036. }
  2037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2038. {
  2039. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2040. }
  2041. else
  2042. {
  2043. maxProfile.TransactionId = -1;
  2044. }
  2045. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2046. {
  2047. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2048. }
  2049. else
  2050. {
  2051. maxProfile.ChargingSchedule.Duration = 86400;
  2052. }
  2053. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2054. {
  2055. 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")));
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2060. }
  2061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2062. {
  2063. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2064. }
  2065. else
  2066. {
  2067. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. json_object_put(obj);
  2073. }
  2074. fclose(fp);
  2075. /*
  2076. if(maxProfile.ChargingProfileId !=-1)
  2077. {
  2078. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2079. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2080. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2081. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2082. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2083. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2084. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2085. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2086. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2087. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2088. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2089. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2090. {
  2091. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2092. {
  2093. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2094. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2095. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2096. }
  2097. }
  2098. }
  2099. else
  2100. DEBUG_INFO("MaxProfile not found.\n");
  2101. DEBUG_INFO("------------------------------------\n");*/
  2102. }
  2103. if(maxProfile.ChargingProfileId != -1)
  2104. {
  2105. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2106. {
  2107. if(maxProfile.ChargingSchedule.Duration != -1)
  2108. {
  2109. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2110. 0:
  2111. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2112. }
  2113. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2114. {
  2115. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2116. {
  2117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2118. 0:
  2119. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2120. if(idxPeriod > 0)
  2121. {
  2122. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2123. {
  2124. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2131. {
  2132. if(maxProfile.ChargingSchedule.Duration != -1)
  2133. {
  2134. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2135. }
  2136. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2137. {
  2138. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2139. {
  2140. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2141. if(idxPeriod > 0)
  2142. {
  2143. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2144. {
  2145. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. else
  2152. {
  2153. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2154. {
  2155. if(maxProfile.ChargingSchedule.Duration != -1)
  2156. {
  2157. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2158. 0:
  2159. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2160. }
  2161. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2162. {
  2163. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2164. {
  2165. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2166. 0:
  2167. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2168. if(idxPeriod > 0)
  2169. {
  2170. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2171. {
  2172. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. else
  2179. {
  2180. if(maxProfile.ChargingSchedule.Duration != -1)
  2181. {
  2182. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2183. 0:
  2184. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2185. }
  2186. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2187. {
  2188. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2189. {
  2190. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2191. 0:
  2192. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2193. if(idxPeriod > 0)
  2194. {
  2195. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2196. {
  2197. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2198. }
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. /*
  2205. DEBUG_INFO("MaxProfile after align.\n");
  2206. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2207. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2208. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2209. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2210. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2211. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2212. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2213. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2214. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2215. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2216. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2217. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2218. {
  2219. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2220. {
  2221. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2222. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2223. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2224. }
  2225. }
  2226. DEBUG_INFO("------------------------------------\n");*/
  2227. }
  2228. // Find each profile period quantity
  2229. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2230. {
  2231. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2232. limitMax = idx+1;
  2233. }
  2234. if(maxProfile.ChargingProfileId != -1)
  2235. {
  2236. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2237. {
  2238. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2239. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2240. (maxProfile.ChargingSchedule.Duration > 0))
  2241. {
  2242. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2243. {
  2244. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2245. compositePeriodIdx++;
  2246. }
  2247. else
  2248. {
  2249. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2250. }
  2251. }
  2252. }
  2253. }
  2254. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2255. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2256. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2257. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2258. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2259. {
  2260. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2261. {
  2262. compositeProfile.ChargingProfileId = 1;
  2263. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2264. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2265. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2266. }
  2267. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2268. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2269. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2270. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2271. }
  2272. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2273. if(line)
  2274. free(line);
  2275. }
  2276. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2277. {
  2278. FILE *fp;
  2279. char profileFileName[128];
  2280. char *line = NULL;
  2281. size_t len = 0;
  2282. time_t CurrentTime;
  2283. struct tm *tmComposite;
  2284. struct StructChargingProfile maxProfile;
  2285. struct StructChargingProfile defaultTxProfile;
  2286. struct StructChargingProfile txProfile;
  2287. struct StructChargingProfile compositeProfile;
  2288. struct StructChargingSchedulePeriod tmpPeriod;
  2289. uint8_t limitMax=0;
  2290. uint8_t limitDef=0;
  2291. uint8_t limitTx=0;
  2292. int compositePeriodIdx = 0;
  2293. CurrentTime = time(NULL);
  2294. tmComposite=localtime(&CurrentTime);
  2295. 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);
  2296. if(isUnitA)
  2297. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2298. else
  2299. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2300. compositeProfile.ChargingSchedule.Duration = durationReq;
  2301. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2302. {
  2303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2306. }
  2307. compositeProfile.ChargingProfileId = 0;
  2308. compositeProfile.StackLevel = 99 ;
  2309. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2310. maxProfile.ChargingProfileId = -1;
  2311. defaultTxProfile.ChargingProfileId = -1;
  2312. txProfile.ChargingProfileId = -1;
  2313. maxProfile.ChargingSchedule.Duration = -1;
  2314. defaultTxProfile.ChargingSchedule.Duration = -1;
  2315. txProfile.ChargingSchedule.Duration = -1;
  2316. system("rm -f /tmp/*.json");
  2317. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2318. /*
  2319. * Search valid charging profile
  2320. */
  2321. //DEBUG_INFO("====================================\n");
  2322. // Search tx profile
  2323. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2324. if((access(profileFileName, F_OK))!=-1)
  2325. {
  2326. fp = fopen(profileFileName, "r");
  2327. while(getline(&line, &len, fp) != -1)
  2328. {
  2329. json_object *obj = NULL;
  2330. obj = json_tokener_parse(line);
  2331. if(is_error(obj))
  2332. {
  2333. DEBUG_ERROR("Parse txProfile from file error.\n");
  2334. }
  2335. else
  2336. {
  2337. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2338. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2339. )
  2340. {
  2341. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2342. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2343. )
  2344. {
  2345. struct tm tmFrom, tmTo;
  2346. struct timeb tbFrom, tbTo;
  2347. 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) &&
  2348. (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))
  2349. {
  2350. tmFrom.tm_year -= 1900;
  2351. tmFrom.tm_mon -= 1;
  2352. tbFrom.time = mktime(&tmFrom);
  2353. tmTo.tm_year -= 1900;
  2354. tmTo.tm_mon -= 1;
  2355. tbTo.time = mktime(&tmTo);
  2356. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2357. {
  2358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2359. {
  2360. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2361. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2363. }
  2364. if(txProfile.ChargingProfileId == -1)
  2365. DEBUG_INFO("TxProfile found.\n");
  2366. else
  2367. DEBUG_INFO("TxProfile updated.\n");
  2368. // Required item
  2369. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2370. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2371. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2372. if(isUnitA)
  2373. {
  2374. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2375. 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++)
  2376. {
  2377. 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"));
  2378. 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?
  2379. 3:
  2380. 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")));
  2381. 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")));
  2382. }
  2383. }
  2384. else
  2385. {
  2386. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2387. 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++)
  2388. {
  2389. 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"));
  2390. 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?
  2391. 3:
  2392. 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")));
  2393. 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));
  2394. }
  2395. }
  2396. // Optional item
  2397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2398. {
  2399. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2400. }
  2401. else
  2402. {
  2403. sprintf((char*)txProfile.ValidFrom, " ");
  2404. }
  2405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2406. {
  2407. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2408. }
  2409. else
  2410. {
  2411. sprintf((char*)txProfile.ValidTo, " ");
  2412. }
  2413. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2414. {
  2415. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2416. }
  2417. else
  2418. {
  2419. sprintf((char*)txProfile.RecurrencyKind, " ");
  2420. }
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2422. {
  2423. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2424. }
  2425. else
  2426. {
  2427. txProfile.TransactionId = -1;
  2428. }
  2429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2430. {
  2431. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2432. }
  2433. else
  2434. {
  2435. txProfile.ChargingSchedule.Duration = 86400;
  2436. }
  2437. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2438. {
  2439. 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")));
  2440. }
  2441. else
  2442. {
  2443. 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));
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2446. {
  2447. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2448. }
  2449. else
  2450. {
  2451. txProfile.ChargingSchedule.MinChargingRate = -1;
  2452. }
  2453. }
  2454. }
  2455. }
  2456. else
  2457. {
  2458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2459. {
  2460. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2462. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2463. }
  2464. if(txProfile.ChargingProfileId == -1)
  2465. DEBUG_INFO("TxProfile found.\n");
  2466. else
  2467. DEBUG_INFO("TxProfile updated.\n");
  2468. // Required item
  2469. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2470. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2471. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2472. if(isUnitA)
  2473. {
  2474. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2475. 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++)
  2476. {
  2477. 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"));
  2478. 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?
  2479. 3:
  2480. 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")));
  2481. 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")));
  2482. }
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2487. 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++)
  2488. {
  2489. 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"));
  2490. 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?
  2491. 3:
  2492. 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")));
  2493. 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));
  2494. }
  2495. }
  2496. // Optional item
  2497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2498. {
  2499. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2500. }
  2501. else
  2502. {
  2503. sprintf((char*)txProfile.ValidFrom, " ");
  2504. }
  2505. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2506. {
  2507. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2508. }
  2509. else
  2510. {
  2511. sprintf((char*)txProfile.ValidTo, " ");
  2512. }
  2513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2514. {
  2515. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2516. }
  2517. else
  2518. {
  2519. sprintf((char*)txProfile.RecurrencyKind, " ");
  2520. }
  2521. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2522. {
  2523. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2524. }
  2525. else
  2526. {
  2527. txProfile.TransactionId = -1;
  2528. }
  2529. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2530. {
  2531. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2532. }
  2533. else
  2534. {
  2535. txProfile.ChargingSchedule.Duration = 86400;
  2536. }
  2537. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2538. {
  2539. 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")));
  2540. }
  2541. else
  2542. {
  2543. 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));
  2544. }
  2545. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2546. {
  2547. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2548. }
  2549. else
  2550. {
  2551. txProfile.ChargingSchedule.MinChargingRate = -1;
  2552. }
  2553. }
  2554. }
  2555. }
  2556. json_object_put(obj);
  2557. }
  2558. fclose(fp);
  2559. /*
  2560. if(txProfile.ChargingProfileId != -1)
  2561. {
  2562. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2563. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2564. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2565. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2566. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2567. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2568. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2569. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2570. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2571. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2572. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2573. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2574. {
  2575. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2576. {
  2577. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2578. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2579. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2580. }
  2581. }
  2582. }
  2583. else
  2584. DEBUG_INFO("TxProfile not found.\n");*/
  2585. }
  2586. // Search default tx profile
  2587. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2588. if((access(profileFileName, F_OK))==-1)
  2589. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2590. if((access(profileFileName, F_OK))!=-1)
  2591. {
  2592. fp = fopen(profileFileName, "r");
  2593. while(getline(&line, &len, fp) != -1)
  2594. {
  2595. json_object *obj = NULL;
  2596. obj = json_tokener_parse(line);
  2597. if(is_error(obj))
  2598. {
  2599. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2600. }
  2601. else
  2602. {
  2603. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2604. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2605. )
  2606. {
  2607. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2608. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2609. )
  2610. {
  2611. struct tm tmFrom, tmTo;
  2612. struct timeb tbFrom, tbTo;
  2613. 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) &&
  2614. (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))
  2615. {
  2616. tmFrom.tm_year -= 1900;
  2617. tmFrom.tm_mon -= 1;
  2618. tbFrom.time = mktime(&tmFrom);
  2619. tmTo.tm_year -= 1900;
  2620. tmTo.tm_mon -= 1;
  2621. tbTo.time = mktime(&tmTo);
  2622. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2623. {
  2624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2625. {
  2626. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2627. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2628. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2629. }
  2630. if(defaultTxProfile.ChargingProfileId == -1)
  2631. DEBUG_INFO("TxDefaultProfile found.\n");
  2632. else
  2633. DEBUG_INFO("TxDefaultProfile updated.\n");
  2634. // Required item
  2635. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2636. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2637. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2638. if(isUnitA)
  2639. {
  2640. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2641. 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++)
  2642. {
  2643. 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"));
  2644. 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?
  2645. 3:
  2646. 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")));
  2647. 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")));
  2648. }
  2649. }
  2650. else
  2651. {
  2652. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2653. 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++)
  2654. {
  2655. 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"));
  2656. 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?
  2657. 3:
  2658. 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")));
  2659. 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));
  2660. }
  2661. }
  2662. // Optional item
  2663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2664. {
  2665. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2666. }
  2667. else
  2668. {
  2669. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2670. }
  2671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2672. {
  2673. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2674. }
  2675. else
  2676. {
  2677. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2678. }
  2679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2680. {
  2681. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2682. }
  2683. else
  2684. {
  2685. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2686. }
  2687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2688. {
  2689. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2690. }
  2691. else
  2692. {
  2693. defaultTxProfile.TransactionId = -1;
  2694. }
  2695. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2696. {
  2697. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2698. }
  2699. else
  2700. {
  2701. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2702. }
  2703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2704. {
  2705. 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")));
  2706. }
  2707. else
  2708. {
  2709. 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));
  2710. }
  2711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2712. {
  2713. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2714. }
  2715. else
  2716. {
  2717. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2718. }
  2719. }
  2720. }
  2721. }
  2722. else
  2723. {
  2724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2725. {
  2726. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2727. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2729. }
  2730. if(defaultTxProfile.ChargingProfileId == -1)
  2731. DEBUG_INFO("TxDefaultProfile found.\n");
  2732. else
  2733. DEBUG_INFO("TxDefaultProfile updated.\n");
  2734. // Required item
  2735. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2736. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2737. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2738. if(isUnitA)
  2739. {
  2740. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2741. 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++)
  2742. {
  2743. 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"));
  2744. 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?
  2745. 3:
  2746. 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")));
  2747. 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")));
  2748. }
  2749. }
  2750. else
  2751. {
  2752. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2753. 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++)
  2754. {
  2755. 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"));
  2756. 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?
  2757. 3:
  2758. 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")));
  2759. 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));
  2760. }
  2761. }
  2762. // Optional item
  2763. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2764. {
  2765. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2766. }
  2767. else
  2768. {
  2769. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2770. }
  2771. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2772. {
  2773. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2774. }
  2775. else
  2776. {
  2777. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2778. }
  2779. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2780. {
  2781. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2782. }
  2783. else
  2784. {
  2785. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2786. }
  2787. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2788. {
  2789. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2790. }
  2791. else
  2792. {
  2793. defaultTxProfile.TransactionId = -1;
  2794. }
  2795. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2796. {
  2797. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2798. }
  2799. else
  2800. {
  2801. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2802. }
  2803. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2804. {
  2805. 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")));
  2806. }
  2807. else
  2808. {
  2809. 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));
  2810. }
  2811. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2812. {
  2813. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2814. }
  2815. else
  2816. {
  2817. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2818. }
  2819. }
  2820. }
  2821. }
  2822. json_object_put(obj);
  2823. }
  2824. fclose(fp);
  2825. /*
  2826. if(defaultTxProfile.ChargingProfileId != -1)
  2827. {
  2828. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2829. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2830. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2831. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2832. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2833. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2834. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2835. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2836. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2837. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2838. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2842. {
  2843. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2844. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2845. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2846. }
  2847. }
  2848. }
  2849. else
  2850. DEBUG_INFO("TxDefaultProfile not found.\n");
  2851. DEBUG_INFO("------------------------------------\n");*/
  2852. }
  2853. // Search max profile
  2854. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2855. if((access(profileFileName, F_OK))!=-1)
  2856. {
  2857. fp = fopen(profileFileName, "r");
  2858. while(getline(&line, &len, fp) != -1)
  2859. {
  2860. json_object *obj = NULL;
  2861. obj = json_tokener_parse(line);
  2862. if(is_error(obj))
  2863. {
  2864. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2865. }
  2866. else
  2867. {
  2868. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2869. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2870. )
  2871. {
  2872. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2873. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2874. )
  2875. {
  2876. struct tm tmFrom, tmTo;
  2877. struct timeb tbFrom, tbTo;
  2878. 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) &&
  2879. (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))
  2880. {
  2881. tmFrom.tm_year -= 1900;
  2882. tmFrom.tm_mon -= 1;
  2883. tbFrom.time = mktime(&tmFrom);
  2884. tmTo.tm_year -= 1900;
  2885. tmTo.tm_mon -= 1;
  2886. tbTo.time = mktime(&tmTo);
  2887. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2888. {
  2889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2890. {
  2891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2893. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2894. }
  2895. if(maxProfile.ChargingProfileId == -1)
  2896. DEBUG_INFO("MaxProfile found.\n");
  2897. else
  2898. DEBUG_INFO("MaxProfile updated.\n");
  2899. // Required item
  2900. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2901. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2902. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2903. if(isUnitA)
  2904. {
  2905. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2906. 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++)
  2907. {
  2908. 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"));
  2909. 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?
  2910. 3:
  2911. 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")));
  2912. 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")));
  2913. }
  2914. }
  2915. else
  2916. {
  2917. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2918. 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++)
  2919. {
  2920. 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"));
  2921. 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?
  2922. 3:
  2923. 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")));
  2924. 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));
  2925. }
  2926. }
  2927. // Optional item
  2928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2929. {
  2930. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2931. }
  2932. else
  2933. {
  2934. sprintf((char*)maxProfile.ValidFrom, " ");
  2935. }
  2936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2937. {
  2938. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2939. }
  2940. else
  2941. {
  2942. sprintf((char*)maxProfile.ValidTo, " ");
  2943. }
  2944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2945. {
  2946. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2947. }
  2948. else
  2949. {
  2950. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2951. }
  2952. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2953. {
  2954. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2955. }
  2956. else
  2957. {
  2958. maxProfile.TransactionId = -1;
  2959. }
  2960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2961. {
  2962. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2963. }
  2964. else
  2965. {
  2966. maxProfile.ChargingSchedule.Duration = 86400;
  2967. }
  2968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2969. {
  2970. 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")));
  2971. }
  2972. else
  2973. {
  2974. 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));
  2975. }
  2976. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2977. {
  2978. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2979. }
  2980. else
  2981. {
  2982. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2983. }
  2984. }
  2985. }
  2986. }
  2987. else
  2988. {
  2989. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2990. {
  2991. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2994. }
  2995. if(maxProfile.ChargingProfileId == -1)
  2996. DEBUG_INFO("MaxProfile found.\n");
  2997. else
  2998. DEBUG_INFO("MaxProfile updated.\n");
  2999. // Required item
  3000. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3001. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3002. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3003. if(isUnitA)
  3004. {
  3005. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3006. 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++)
  3007. {
  3008. 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"));
  3009. 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?
  3010. 3:
  3011. 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")));
  3012. 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")));
  3013. }
  3014. }
  3015. else
  3016. {
  3017. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3018. 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++)
  3019. {
  3020. 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"));
  3021. 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?
  3022. 3:
  3023. 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")));
  3024. 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));
  3025. }
  3026. }
  3027. // Optional item
  3028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3029. {
  3030. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3031. }
  3032. else
  3033. {
  3034. sprintf((char*)maxProfile.ValidFrom, " ");
  3035. }
  3036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3037. {
  3038. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3039. }
  3040. else
  3041. {
  3042. sprintf((char*)maxProfile.ValidTo, " ");
  3043. }
  3044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3045. {
  3046. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3047. }
  3048. else
  3049. {
  3050. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3051. }
  3052. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3053. {
  3054. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3055. }
  3056. else
  3057. {
  3058. maxProfile.TransactionId = -1;
  3059. }
  3060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3061. {
  3062. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3063. }
  3064. else
  3065. {
  3066. maxProfile.ChargingSchedule.Duration = 86400;
  3067. }
  3068. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3069. {
  3070. 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")));
  3071. }
  3072. else
  3073. {
  3074. 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));
  3075. }
  3076. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3077. {
  3078. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3079. }
  3080. else
  3081. {
  3082. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. json_object_put(obj);
  3088. }
  3089. fclose(fp);
  3090. /*
  3091. if(maxProfile.ChargingProfileId !=-1)
  3092. {
  3093. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3094. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3095. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3096. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3097. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3098. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3099. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3100. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3101. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3102. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3103. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3104. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3105. {
  3106. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3107. {
  3108. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3109. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3110. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3111. }
  3112. }
  3113. }
  3114. else
  3115. DEBUG_INFO("MaxProfile not found.\n");
  3116. DEBUG_INFO("------------------------------------\n");*/
  3117. }
  3118. /*
  3119. * Align found profile start schedule & periods
  3120. */
  3121. //DEBUG_INFO("====================================\n");
  3122. /*
  3123. // For local test usage, force modify found profile start schedule info
  3124. 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);
  3125. 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);
  3126. 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);
  3127. */
  3128. if(txProfile.ChargingProfileId != -1)
  3129. {
  3130. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3131. {
  3132. if(txProfile.ChargingSchedule.Duration != -1)
  3133. {
  3134. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3135. 0:
  3136. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3137. }
  3138. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3139. {
  3140. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3141. {
  3142. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3143. 0:
  3144. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3145. if(idxPeriod > 0)
  3146. {
  3147. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3148. {
  3149. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3156. {
  3157. if(txProfile.ChargingSchedule.Duration != -1)
  3158. {
  3159. 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?
  3160. 0:
  3161. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3162. }
  3163. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3164. {
  3165. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3166. {
  3167. 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?
  3168. 0:
  3169. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3170. if(idxPeriod > 0)
  3171. {
  3172. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3173. {
  3174. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3175. }
  3176. }
  3177. }
  3178. }
  3179. }
  3180. else
  3181. {
  3182. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3183. {
  3184. if(txProfile.ChargingSchedule.Duration != -1)
  3185. {
  3186. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3187. 0:
  3188. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3189. }
  3190. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3191. {
  3192. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3193. {
  3194. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3195. 0:
  3196. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3197. if(idxPeriod > 0)
  3198. {
  3199. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3200. {
  3201. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3202. }
  3203. }
  3204. }
  3205. }
  3206. }
  3207. else
  3208. {
  3209. if(txProfile.ChargingSchedule.Duration != -1)
  3210. {
  3211. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3212. 0:
  3213. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3214. }
  3215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3216. {
  3217. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3218. {
  3219. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3220. 0:
  3221. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3222. if(idxPeriod > 0)
  3223. {
  3224. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3225. {
  3226. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. /*
  3234. DEBUG_INFO("txProfile after align.\n");
  3235. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3236. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3237. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3238. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3239. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3240. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3241. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3242. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3243. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3244. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3245. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3247. {
  3248. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3249. {
  3250. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3251. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3252. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3253. }
  3254. }*/
  3255. }
  3256. if(defaultTxProfile.ChargingProfileId != -1)
  3257. {
  3258. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3259. {
  3260. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3261. {
  3262. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3263. 0:
  3264. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3265. }
  3266. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3267. {
  3268. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3269. {
  3270. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3271. 0:
  3272. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3273. if(idxPeriod > 0)
  3274. {
  3275. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3276. {
  3277. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3278. }
  3279. }
  3280. }
  3281. }
  3282. }
  3283. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3284. {
  3285. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3286. {
  3287. 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?
  3288. 0:
  3289. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3290. }
  3291. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3292. {
  3293. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3294. {
  3295. 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?
  3296. 0:
  3297. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3298. if(idxPeriod > 0)
  3299. {
  3300. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3301. {
  3302. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3303. }
  3304. }
  3305. }
  3306. }
  3307. }
  3308. else
  3309. {
  3310. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3311. {
  3312. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3313. {
  3314. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3315. 0:
  3316. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3317. }
  3318. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3319. {
  3320. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3321. {
  3322. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3323. 0:
  3324. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3325. if(idxPeriod > 0)
  3326. {
  3327. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3328. {
  3329. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3330. }
  3331. }
  3332. }
  3333. }
  3334. }
  3335. else
  3336. {
  3337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3338. {
  3339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3340. 0:
  3341. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3342. }
  3343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3344. {
  3345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3346. {
  3347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3348. 0:
  3349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3350. if(idxPeriod > 0)
  3351. {
  3352. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3353. {
  3354. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3355. }
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. /*
  3362. DEBUG_INFO("defaultTxProfile after align.\n");
  3363. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3364. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3365. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3366. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3367. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3368. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3369. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3370. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3371. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3372. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3373. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3374. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3375. {
  3376. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3377. {
  3378. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3379. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3380. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3381. }
  3382. }
  3383. DEBUG_INFO("------------------------------------\n");*/
  3384. }
  3385. if(maxProfile.ChargingProfileId != -1)
  3386. {
  3387. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3388. {
  3389. if(maxProfile.ChargingSchedule.Duration != -1)
  3390. {
  3391. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3392. 0:
  3393. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3394. }
  3395. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3396. {
  3397. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3398. {
  3399. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3400. 0:
  3401. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3402. if(idxPeriod > 0)
  3403. {
  3404. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3405. {
  3406. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3413. {
  3414. if(maxProfile.ChargingSchedule.Duration != -1)
  3415. {
  3416. 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?
  3417. 0:
  3418. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3419. }
  3420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3421. {
  3422. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3423. {
  3424. 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?
  3425. 0:
  3426. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3427. if(idxPeriod > 0)
  3428. {
  3429. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3430. {
  3431. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3432. }
  3433. }
  3434. }
  3435. }
  3436. }
  3437. else
  3438. {
  3439. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3440. {
  3441. if(maxProfile.ChargingSchedule.Duration != -1)
  3442. {
  3443. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3444. 0:
  3445. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3446. }
  3447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3448. {
  3449. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3450. {
  3451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3452. 0:
  3453. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3454. if(idxPeriod > 0)
  3455. {
  3456. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3457. {
  3458. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3459. }
  3460. }
  3461. }
  3462. }
  3463. }
  3464. else
  3465. {
  3466. if(maxProfile.ChargingSchedule.Duration != -1)
  3467. {
  3468. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3469. 0:
  3470. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3471. }
  3472. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3473. {
  3474. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3475. {
  3476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3477. 0:
  3478. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3479. if(idxPeriod > 0)
  3480. {
  3481. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3482. {
  3483. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3484. }
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. /*
  3491. DEBUG_INFO("MaxProfile after align.\n");
  3492. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3493. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3494. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3495. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3496. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3497. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3498. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3499. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3500. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3501. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3502. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3503. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3504. {
  3505. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3506. {
  3507. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3508. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3509. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3510. }
  3511. }
  3512. DEBUG_INFO("------------------------------------\n");*/
  3513. }
  3514. /*
  3515. * Merge to conposite schedule
  3516. */
  3517. //DEBUG_INFO("====================================\n");
  3518. // Find each profile period quantity
  3519. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3520. {
  3521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3522. limitMax = idx+1;
  3523. }
  3524. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3525. {
  3526. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3527. limitDef = idx+1;
  3528. }
  3529. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3530. {
  3531. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3532. limitTx = idx+1;
  3533. }
  3534. // TxProfile found, composite schedule based on it
  3535. if(txProfile.ChargingProfileId != -1)
  3536. {
  3537. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3538. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3539. {
  3540. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3541. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3542. (txProfile.ChargingSchedule.Duration > 0))
  3543. {
  3544. if(maxProfile.ChargingProfileId != -1)
  3545. {
  3546. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3547. {
  3548. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3549. {
  3550. if((maxProfile.ChargingSchedule.Duration > 0))
  3551. {
  3552. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3553. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3554. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3555. }
  3556. else
  3557. {
  3558. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3559. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3560. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3561. }
  3562. }
  3563. if(idxMaxPeriod == (limitMax-1))
  3564. {
  3565. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3566. {
  3567. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3568. {
  3569. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3570. compositePeriodIdx++;
  3571. }
  3572. else
  3573. {
  3574. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3575. }
  3576. }
  3577. }
  3578. }
  3579. }
  3580. else
  3581. {
  3582. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3583. {
  3584. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3585. compositePeriodIdx++;
  3586. }
  3587. else
  3588. {
  3589. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3590. }
  3591. }
  3592. }
  3593. if(idxTxPeriod == (limitTx-1))
  3594. {
  3595. if(defaultTxProfile.ChargingProfileId != -1)
  3596. {
  3597. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3598. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3599. {
  3600. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3601. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3602. (defaultTxProfile.ChargingSchedule.Duration>0))
  3603. {
  3604. if(maxProfile.ChargingProfileId != -1)
  3605. {
  3606. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3607. {
  3608. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3609. {
  3610. if((maxProfile.ChargingSchedule.Duration > 0))
  3611. {
  3612. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3613. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3614. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3615. }
  3616. else
  3617. {
  3618. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3619. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3620. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3621. }
  3622. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3623. {
  3624. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3625. {
  3626. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3627. compositePeriodIdx++;
  3628. }
  3629. else
  3630. {
  3631. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3632. }
  3633. }
  3634. // Delete duplicate period
  3635. if(compositePeriodIdx > 1)
  3636. {
  3637. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3638. {
  3639. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3640. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3641. compositePeriodIdx -= 1;
  3642. }
  3643. }
  3644. }
  3645. else
  3646. {
  3647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3648. {
  3649. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3650. compositePeriodIdx++;
  3651. }
  3652. else
  3653. {
  3654. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3655. }
  3656. break;
  3657. }
  3658. }
  3659. }
  3660. else
  3661. {
  3662. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3663. {
  3664. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3665. compositePeriodIdx++;
  3666. }
  3667. else
  3668. {
  3669. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3679. else if(defaultTxProfile.ChargingProfileId != -1)
  3680. {
  3681. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3682. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3683. {
  3684. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3685. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3686. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3687. {
  3688. if(maxProfile.ChargingProfileId != -1)
  3689. {
  3690. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3691. {
  3692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3693. {
  3694. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3695. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3696. if((maxProfile.ChargingSchedule.Duration > 0))
  3697. {
  3698. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3699. }
  3700. else
  3701. {
  3702. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3703. }
  3704. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3705. {
  3706. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3707. {
  3708. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3709. compositePeriodIdx++;
  3710. }
  3711. else
  3712. {
  3713. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3714. }
  3715. }
  3716. // Delete duplicate period
  3717. if(compositePeriodIdx > 1)
  3718. {
  3719. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3720. {
  3721. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3722. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3723. compositePeriodIdx -= 1;
  3724. }
  3725. }
  3726. }
  3727. else
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3730. {
  3731. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3732. compositePeriodIdx++;
  3733. }
  3734. else
  3735. {
  3736. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3737. }
  3738. break;
  3739. }
  3740. }
  3741. }
  3742. else
  3743. {
  3744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3745. {
  3746. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3747. compositePeriodIdx++;
  3748. }
  3749. else
  3750. {
  3751. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3752. }
  3753. }
  3754. }
  3755. }
  3756. }
  3757. // Fill other period by MaxProfile
  3758. if(maxProfile.ChargingProfileId != -1)
  3759. {
  3760. if(compositePeriodIdx==0)
  3761. {
  3762. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3763. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3764. {
  3765. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3766. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3767. (maxProfile.ChargingSchedule.Duration > 0))
  3768. {
  3769. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3770. {
  3771. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3772. compositePeriodIdx++;
  3773. }
  3774. else
  3775. {
  3776. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3777. }
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. int lastCompositePeriodIdx = compositePeriodIdx;
  3784. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3785. {
  3786. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3787. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3788. (maxProfile.ChargingSchedule.Duration > 0))
  3789. {
  3790. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3791. {
  3792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3793. {
  3794. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3795. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3796. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3797. }
  3798. else
  3799. {
  3800. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3801. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3802. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3803. }
  3804. }
  3805. if(tmpPeriod.Limit != -1)
  3806. {
  3807. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3808. {
  3809. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3810. {
  3811. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3812. compositePeriodIdx++;
  3813. }
  3814. else
  3815. {
  3816. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3817. }
  3818. }
  3819. // Delete duplicate period
  3820. if(compositePeriodIdx > 1)
  3821. {
  3822. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3823. {
  3824. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3825. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3826. compositePeriodIdx -= 1;
  3827. }
  3828. }
  3829. }
  3830. }
  3831. }
  3832. }
  3833. }
  3834. compositeProfile.ChargingSchedule.Duration = durationReq;
  3835. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3836. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3837. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3838. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3840. {
  3841. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3842. {
  3843. compositeProfile.ChargingProfileId = 1;
  3844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3847. }
  3848. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3849. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3851. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3852. }
  3853. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3854. if(line)
  3855. free(line);
  3856. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3857. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3858. }
  3859. //==========================================
  3860. // Init all share memory
  3861. //==========================================
  3862. int InitShareMemory()
  3863. {
  3864. int result = PASS;
  3865. int MeterSMId;
  3866. //creat ShmSysConfigAndInfo
  3867. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3868. {
  3869. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3870. result = FAIL;
  3871. }
  3872. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3873. {
  3874. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3875. result = FAIL;
  3876. }
  3877. else
  3878. {}
  3879. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3880. {
  3881. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3882. result = FAIL;
  3883. }
  3884. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3885. {
  3886. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3887. result = FAIL;
  3888. }
  3889. else
  3890. {}
  3891. //creat ShmPsuData
  3892. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3893. {
  3894. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3895. result = FAIL;
  3896. }
  3897. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3898. {
  3899. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3900. result = FAIL;
  3901. }
  3902. else
  3903. {}
  3904. //creat ShmOCPP16Data
  3905. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3906. {
  3907. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3908. result = FAIL;
  3909. }
  3910. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3911. {
  3912. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3913. result = FAIL;
  3914. }
  3915. else
  3916. {}
  3917. /****************************** For Initial Settings************************************************/
  3918. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3920. // allocate Configuration memory address
  3921. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3922. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3923. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3924. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3925. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3926. //offline MeterValue Interval
  3927. TempMeterValueInterval = 0;
  3928. return result;
  3929. }
  3930. int ProcessShareMemory()
  3931. {
  3932. int result = PASS;
  3933. if(InitShareMemory() == FAIL)
  3934. {
  3935. DEBUG_ERROR("InitShareMemory NG\n");
  3936. if(ShmStatusCodeData!=NULL)
  3937. {
  3938. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3939. }
  3940. result = FAIL;
  3941. }
  3942. // Model name parsing
  3943. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3944. {
  3945. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3946. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3947. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3948. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3949. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3950. ) // 'D' means DC
  3951. {
  3952. // DO series
  3953. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3954. {
  3955. gunTotalNumber += 1;
  3956. gunType[gun_index] = GUN_TYPE_DO;
  3957. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3958. {
  3959. case Gun_Type_Chademo:
  3960. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3961. break;
  3962. case Gun_Type_CCS_2:
  3963. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3964. break;
  3965. case Gun_Type_GB:
  3966. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3967. break;
  3968. case Gun_Type_AC:
  3969. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3970. break;
  3971. default:
  3972. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3973. break;
  3974. }
  3975. }
  3976. }
  3977. else
  3978. {
  3979. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3980. {
  3981. gunTotalNumber += 1;
  3982. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3983. {
  3984. case Gun_Type_Chademo:
  3985. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3986. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3987. break;
  3988. case Gun_Type_CCS_2:
  3989. gunType[gun_index] = GUN_TYPE_CCS;
  3990. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3991. break;
  3992. case Gun_Type_GB:
  3993. gunType[gun_index] = GUN_TYPE_GBT;
  3994. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3995. break;
  3996. case Gun_Type_AC:
  3997. gunType[gun_index] = GUN_TYPE_AC;
  3998. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3999. break;
  4000. default:
  4001. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4002. break;
  4003. }
  4004. }
  4005. }
  4006. }
  4007. else
  4008. {
  4009. DEBUG_ERROR("Model name parsing fail.\n");
  4010. result = FAIL;
  4011. }
  4012. if(result != PASS)sleep(5);
  4013. return result;
  4014. }
  4015. void checkRemoteStart(uint8_t connectorIdInt)
  4016. {
  4017. uint8_t tempIndex;
  4018. int result = PASS;
  4019. char cmdBuf[512];
  4020. //check Transaction active
  4021. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4022. {
  4023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4024. {
  4025. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4026. }
  4027. else
  4028. {
  4029. tempIndex = connectorIdInt -1;
  4030. }
  4031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4034. {
  4035. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4036. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4037. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4038. {
  4039. //Reserved
  4040. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4041. }
  4042. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4043. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4044. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4045. {
  4046. //Reserved
  4047. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4048. result = FAIL;
  4049. goto end;
  4050. }
  4051. else
  4052. {
  4053. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4054. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4055. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4056. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4057. {
  4058. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4059. result = FAIL;
  4060. goto end;
  4061. }
  4062. }//END FOR ELSE
  4063. }
  4064. }// END FOR CHAdeMO_QUANTITY
  4065. }
  4066. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4067. {
  4068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4069. {
  4070. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4071. }
  4072. else
  4073. {
  4074. tempIndex = connectorIdInt -1;
  4075. }
  4076. for (int index = 0; index < CCS_QUANTITY; index++)
  4077. {
  4078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4079. {
  4080. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4081. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4082. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4083. {
  4084. //Reserved
  4085. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4086. }
  4087. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4088. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4089. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4090. {
  4091. //Reserved
  4092. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4093. result = FAIL;
  4094. goto end;
  4095. }
  4096. else
  4097. {
  4098. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4099. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4100. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4101. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4102. {
  4103. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4104. result = FAIL;
  4105. goto end;
  4106. }
  4107. }// END FOR ELSE
  4108. }
  4109. }// END FOR CCS_QUANTITY
  4110. }
  4111. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4114. {
  4115. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4116. }
  4117. else
  4118. {
  4119. tempIndex = connectorIdInt -1;
  4120. }
  4121. for (int index = 0; index < GB_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4124. {
  4125. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4126. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4127. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4128. {
  4129. //Reserved
  4130. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4131. }
  4132. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4133. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4134. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4135. {
  4136. //Reserved
  4137. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4138. result = FAIL;
  4139. goto end;
  4140. }
  4141. else
  4142. {
  4143. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4144. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4145. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4146. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4147. {
  4148. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4149. result = FAIL;
  4150. goto end;
  4151. }
  4152. }// END FOR ELSE
  4153. }
  4154. } // END FOR GB_QUANTITY
  4155. }
  4156. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4157. {
  4158. tempIndex = connectorIdInt -1;
  4159. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4162. {
  4163. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4164. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4165. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4166. {
  4167. //Reserved
  4168. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4169. }
  4170. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4171. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4172. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4173. {
  4174. //Reserved
  4175. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4176. result = FAIL;
  4177. goto end;
  4178. }
  4179. else
  4180. {
  4181. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4182. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4183. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4184. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4185. {
  4186. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4187. result = FAIL;
  4188. goto end;
  4189. }
  4190. }// END FOR ELSE
  4191. }
  4192. } // END FOR GB_QUANTITY
  4193. }
  4194. else
  4195. {
  4196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4197. {
  4198. tempIndex = 2;
  4199. }
  4200. else
  4201. {
  4202. tempIndex = connectorIdInt -1;
  4203. }
  4204. for (int index = 0; index < AC_QUANTITY; index++)
  4205. {
  4206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4207. {
  4208. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4209. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4210. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4211. {
  4212. //Reserved
  4213. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4214. }
  4215. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4216. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4217. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4218. {
  4219. //Reserved
  4220. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4221. result = FAIL;
  4222. goto end;
  4223. }
  4224. else
  4225. {
  4226. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4227. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4228. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4229. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4230. {
  4231. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4232. result = FAIL;
  4233. goto end;
  4234. }
  4235. }//END FOR ELSE
  4236. }
  4237. }// END FOR AC_QUANTITY
  4238. }
  4239. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4240. {
  4241. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4242. {
  4243. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4244. {
  4245. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4246. system(cmdBuf);
  4247. }
  4248. }
  4249. else
  4250. {
  4251. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4252. result = FAIL;
  4253. }
  4254. }
  4255. end:
  4256. if(result == PASS)
  4257. {
  4258. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4259. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4260. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4261. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4262. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4263. }
  4264. }
  4265. void CheckSystemValue(void)
  4266. {
  4267. char filenmae[100]={0};
  4268. char str[100]={0};
  4269. int tempIndex = 0;
  4270. //===============================
  4271. // send Heartbeat
  4272. //===============================
  4273. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4274. {
  4275. //parameter for test
  4276. sendHeartbeatRequest(0);
  4277. //===========================
  4278. // Reset Waiting Time
  4279. //===========================
  4280. HeartBeatWithNOResponse += 1;
  4281. }
  4282. //===============================
  4283. // Credit deduct report
  4284. //===============================
  4285. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4286. {
  4287. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4288. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4289. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4290. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4291. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4292. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4293. }
  4294. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4295. {
  4296. OCPP_query_deduct_info();
  4297. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4298. }
  4299. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4300. {
  4301. // ClockAlign MeterValue
  4302. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4303. {
  4304. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4305. {
  4306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4307. {
  4308. tempIndex = ((gun_index==2) ? 1: 0);
  4309. }
  4310. else
  4311. {
  4312. tempIndex = gun_index;
  4313. }
  4314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4315. {
  4316. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4318. {
  4319. reqClockAlignMeter[gun_index] = 1;
  4320. }
  4321. }// End for CHAdeMO
  4322. }
  4323. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4324. {
  4325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4326. {
  4327. tempIndex = ((gun_index==2) ? 1: 0);
  4328. }
  4329. else
  4330. {
  4331. tempIndex = gun_index;
  4332. }
  4333. for (int index = 0; index < CCS_QUANTITY; index++)
  4334. {
  4335. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4336. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4337. {
  4338. reqClockAlignMeter[gun_index] = 1;
  4339. }
  4340. } // End for CCS
  4341. }
  4342. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4343. {
  4344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4345. {
  4346. tempIndex = ((gun_index==2) ? 1: 0);
  4347. }
  4348. else
  4349. {
  4350. tempIndex = gun_index;
  4351. }
  4352. for (int index = 0; index < GB_QUANTITY; index++)
  4353. {
  4354. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4355. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4356. {
  4357. reqClockAlignMeter[gun_index] = 1;
  4358. }
  4359. }// End for GB
  4360. }
  4361. else if(gunType[gun_index] == GUN_TYPE_DO)
  4362. {
  4363. tempIndex = gun_index;
  4364. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4365. {
  4366. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4367. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4368. {
  4369. reqClockAlignMeter[gun_index] = 1;
  4370. }
  4371. }
  4372. }
  4373. else
  4374. {
  4375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4376. {
  4377. tempIndex = 2;
  4378. }
  4379. else
  4380. {
  4381. tempIndex = gun_index;
  4382. }
  4383. for (int index = 0; index < AC_QUANTITY; index++)
  4384. {
  4385. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4386. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4387. {
  4388. reqClockAlignMeter[gun_index] = 1;
  4389. }
  4390. }//End for AC
  4391. }
  4392. }
  4393. }
  4394. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4395. {
  4396. //==========================================
  4397. // Check remote start without connector id
  4398. //==========================================
  4399. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4400. {
  4401. int connectorIdInt = -1;
  4402. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4403. {
  4404. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4405. {
  4406. connectorIdInt = (gun_index+1);
  4407. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4408. checkRemoteStart(connectorIdInt);
  4409. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4410. break;
  4411. }
  4412. }
  4413. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4414. {
  4415. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4416. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4417. }
  4418. }
  4419. //==========================================
  4420. // csu trigger DataTransferReq
  4421. //==========================================
  4422. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4423. {
  4424. sendDataTransferRequest(gun_index);
  4425. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4426. }
  4427. //==========================================
  4428. // CSU Trigger Authorize Request
  4429. //==========================================
  4430. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4431. {
  4432. sendAuthorizeRequest(0);
  4433. authorizeRetryTimes = authorizeRetryTimes + 1;
  4434. if(authorizeRetryTimes < 3)
  4435. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4436. }
  4437. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4438. {
  4439. authorizeRetryTimes = 0;
  4440. SetOcppConnStatus(FALSE);
  4441. server_sign = FALSE;
  4442. }
  4443. 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))
  4444. {
  4445. sendAuthorizeRequest(0);
  4446. }
  4447. //==========================================
  4448. // Charger start transaction
  4449. //==========================================
  4450. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4451. {
  4452. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4453. sendStartTransactionRequest(gun_index);
  4454. refreshStartTimer(&clientTime.StartTransaction);
  4455. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4456. storeTempStopTransaction(gun_index);
  4457. }
  4458. //==========================================
  4459. // Charger stop transaction
  4460. //==========================================
  4461. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4462. {
  4463. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4464. sendStopTransactionRequest(gun_index);
  4465. OCPP_updatePeriodEnergy(gun_index);
  4466. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4467. refreshStartTimer(&clientTime.StopTransaction);
  4468. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4469. }
  4470. //==========================================
  4471. // Charger status report
  4472. //==========================================
  4473. //--- Check Mode Change ---//
  4474. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4475. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4476. {
  4477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4478. {
  4479. tempIndex = ((gun_index==2) ? 1: 0);
  4480. }
  4481. else
  4482. {
  4483. tempIndex = gun_index;
  4484. }
  4485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4486. {
  4487. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4488. {
  4489. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4490. {
  4491. // Sent unplug message for California pricing logic
  4492. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4493. {
  4494. uint8_t ts[20];
  4495. getNowDatetime(ts);
  4496. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4497. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4498. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4499. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4500. }
  4501. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4502. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4503. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4504. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4505. {
  4506. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4507. if((access(filenmae,F_OK))!=-1)
  4508. {
  4509. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4510. sprintf(str,"rm -f %s",filenmae);
  4511. system(str);
  4512. }
  4513. }
  4514. }
  4515. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4516. #if 1 // for TempStopTransaction
  4517. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4518. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4519. {
  4520. checkTempStopTransaction(gun_index);
  4521. }
  4522. #endif
  4523. }
  4524. }
  4525. }
  4526. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4527. {
  4528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4529. {
  4530. tempIndex = ((gun_index==2) ? 1: 0);
  4531. }
  4532. else
  4533. {
  4534. tempIndex = gun_index;
  4535. }
  4536. for (int index = 0; index < CCS_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4539. {
  4540. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4541. {
  4542. // Sent unplug message for California pricing logic
  4543. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4544. {
  4545. uint8_t ts[20];
  4546. getNowDatetime(ts);
  4547. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4548. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4549. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4550. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4551. }
  4552. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4553. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4554. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4555. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4556. {
  4557. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4558. if((access(filenmae,F_OK))!=-1)
  4559. {
  4560. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4561. sprintf(str,"rm -f %s",filenmae);
  4562. system(str);
  4563. }
  4564. }
  4565. }
  4566. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4567. #if 1 // for TempStopTransaction
  4568. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4569. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4570. {
  4571. checkTempStopTransaction(gun_index);
  4572. }
  4573. #endif
  4574. }
  4575. }
  4576. }
  4577. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4578. {
  4579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4580. {
  4581. tempIndex = ((gun_index==2) ? 1: 0);
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. for (int index = 0; index < GB_QUANTITY; index++)
  4588. {
  4589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4590. {
  4591. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4592. {
  4593. // Sent unplug message for California pricing logic
  4594. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4595. {
  4596. uint8_t ts[20];
  4597. getNowDatetime(ts);
  4598. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4599. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4600. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4601. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4602. }
  4603. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4604. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4605. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4606. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4607. {
  4608. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4609. if((access(filenmae,F_OK))!=-1)
  4610. {
  4611. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4612. sprintf(str,"rm -f %s",filenmae);
  4613. system(str);
  4614. }
  4615. }
  4616. }
  4617. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4618. #if 1 // for TempStopTransaction
  4619. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4620. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4621. {
  4622. checkTempStopTransaction(gun_index);
  4623. }
  4624. #endif
  4625. }
  4626. }
  4627. }
  4628. else if(gunType[gun_index] == GUN_TYPE_DO)
  4629. {
  4630. tempIndex = gun_index;
  4631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4632. {
  4633. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4634. {
  4635. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4636. {
  4637. // Sent unplug message for California pricing logic
  4638. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4639. {
  4640. uint8_t ts[20];
  4641. getNowDatetime(ts);
  4642. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4643. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4644. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4645. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4646. }
  4647. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4648. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4649. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4650. 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
  4651. {
  4652. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4653. if((access(filenmae,F_OK))!=-1)
  4654. {
  4655. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4656. sprintf(str,"rm -f %s",filenmae);
  4657. system(str);
  4658. }
  4659. }
  4660. }
  4661. 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);
  4662. #if 1 // for TempStopTransaction
  4663. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4664. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4665. {
  4666. checkTempStopTransaction(gun_index);
  4667. }
  4668. #endif
  4669. }
  4670. }
  4671. }
  4672. else
  4673. {
  4674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4675. {
  4676. tempIndex = 2;
  4677. }
  4678. else
  4679. {
  4680. tempIndex = gun_index;
  4681. }
  4682. for (int index = 0; index < AC_QUANTITY; index++)
  4683. {
  4684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4685. {
  4686. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4687. {
  4688. // Sent unplug message for California pricing logic
  4689. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4690. {
  4691. uint8_t ts[20];
  4692. getNowDatetime(ts);
  4693. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4694. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4695. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4696. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4697. }
  4698. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4699. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4700. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4701. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4702. {
  4703. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4704. if((access(filenmae,F_OK))!=-1)
  4705. {
  4706. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4707. sprintf(str,"rm -f %s",filenmae);
  4708. system(str);
  4709. }
  4710. }
  4711. }
  4712. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4713. #if 1 // for TempStopTransaction
  4714. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4715. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4716. {
  4717. checkTempStopTransaction(gun_index);
  4718. }
  4719. #endif
  4720. }
  4721. }// END
  4722. }
  4723. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4724. (
  4725. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4726. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4727. )
  4728. )
  4729. {
  4730. sendStatusNotificationRequest(gun_index);
  4731. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4732. }
  4733. //==============================================
  4734. // TCCI reader status report
  4735. //==============================================
  4736. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4737. {
  4738. reportReaderStatus(gun_index);
  4739. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4740. }
  4741. //==============================================
  4742. // CSU Trigger Smart Charging Profile
  4743. //==============================================
  4744. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4745. {
  4746. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4747. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4748. }
  4749. //==============================================
  4750. // Meter report
  4751. //==============================================
  4752. // Trigger MeterValue
  4753. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4754. {
  4755. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4756. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4757. }
  4758. // Clock-aligned Meter value
  4759. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4760. {
  4761. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4762. reqClockAlignMeter[gun_index] = 0;
  4763. }
  4764. // Sample period MeterValue
  4765. 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))))
  4766. {
  4767. //check Transaction active
  4768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4769. {
  4770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4771. {
  4772. tempIndex = ((gun_index==2) ? 1: 0);
  4773. }
  4774. else
  4775. {
  4776. tempIndex = gun_index;
  4777. }
  4778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4779. {
  4780. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4781. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4784. {
  4785. reqSampleMeter[gun_index] = 1;
  4786. }
  4787. }
  4788. }// End for CHAdeMO
  4789. }
  4790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4793. {
  4794. tempIndex = ((gun_index==2) ? 1: 0);
  4795. }
  4796. else
  4797. {
  4798. tempIndex = gun_index;
  4799. }
  4800. for (int index = 0; index < CCS_QUANTITY; index++)
  4801. {
  4802. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4803. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4804. {
  4805. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4806. {
  4807. reqSampleMeter[gun_index] = 1;
  4808. }
  4809. }
  4810. } // End for CCS
  4811. }
  4812. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4815. {
  4816. tempIndex = ((gun_index==2) ? 1: 0);
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < GB_QUANTITY; index++)
  4823. {
  4824. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4825. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4826. {
  4827. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4828. {
  4829. reqSampleMeter[gun_index] = 1;
  4830. }
  4831. }
  4832. }// End for GB
  4833. }
  4834. else if(gunType[gun_index] == GUN_TYPE_DO)
  4835. {
  4836. tempIndex = gun_index;
  4837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4838. {
  4839. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4840. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4841. {
  4842. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4843. {
  4844. reqSampleMeter[gun_index] = 1;
  4845. }
  4846. }
  4847. }
  4848. }
  4849. else
  4850. {
  4851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4852. {
  4853. tempIndex = 2;
  4854. }
  4855. else
  4856. {
  4857. tempIndex = gun_index;
  4858. }
  4859. for (int index = 0; index < AC_QUANTITY; index++)
  4860. {
  4861. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4862. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4863. {
  4864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4865. {
  4866. reqSampleMeter[gun_index] = 1;
  4867. }
  4868. }
  4869. }//End for AC
  4870. }
  4871. if(reqSampleMeter[gun_index] == 1)
  4872. {
  4873. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4874. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4875. storeTempStopTransaction(gun_index);
  4876. reqSampleMeter[gun_index] = 0;
  4877. }
  4878. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4879. }
  4880. //==============================================
  4881. // Check Connector reserved
  4882. //==============================================
  4883. //===============================
  4884. // Check if Reserve is expired
  4885. //===============================
  4886. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4887. {
  4888. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4889. {
  4890. DEBUG_INFO("reserve expired.\n");
  4891. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4892. }
  4893. }//END OF Check if Reserve is expired
  4894. //==========================================
  4895. // csu trigger FirmwareStatusNotificationReq
  4896. //==========================================
  4897. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4898. {
  4899. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4900. }
  4901. //==========================================
  4902. // csu trigger DiagnosticsStatusNotificationReq
  4903. //==========================================
  4904. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4905. {
  4906. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4907. }
  4908. //==========================================
  4909. // csu trigger CancelReservationConf
  4910. //==========================================
  4911. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4912. {
  4913. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4914. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4915. }
  4916. //==========================================
  4917. // csu trigger ChangeAvailabilityConf
  4918. //==========================================
  4919. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4920. {
  4921. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4922. }
  4923. //==========================================
  4924. // csu trigger UnlockConnectorConf
  4925. //==========================================
  4926. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4927. {
  4928. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4929. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4930. }
  4931. //==========================================
  4932. // csu trigger ReserveNowConf
  4933. //==========================================
  4934. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4935. {
  4936. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4937. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4938. }
  4939. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4940. {
  4941. sendSignCertificateRequest();
  4942. }
  4943. }
  4944. }
  4945. //==========================================
  4946. // send request routine
  4947. //==========================================
  4948. int sendAuthorizeRequest(int gun_index)
  4949. {
  4950. mtrace();
  4951. int result = FAIL;
  4952. char message[100]={0};
  4953. char guid[37];
  4954. char tempdata[65]={0};
  4955. DEBUG_INFO("sendAuthorizeRequest...\n");
  4956. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4957. //Local Authorize
  4958. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4959. {
  4960. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4961. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4962. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4963. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4964. result = PASS;
  4965. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4966. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4967. authorizeRetryTimes = 0;
  4968. return result;
  4969. }
  4970. 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))||
  4971. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4972. {
  4973. // Query from cache
  4974. DEBUG_INFO("Authorize from cache.\n");
  4975. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4976. // Query from list
  4977. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4978. {
  4979. DEBUG_INFO("Authorize from list.\n");
  4980. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4981. }
  4982. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4983. {
  4984. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4985. {
  4986. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4987. }
  4988. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4989. {
  4990. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4991. }
  4992. if(!GetOcppConnStatus())
  4993. {
  4994. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4995. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4996. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4997. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4998. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4999. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5000. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5001. authorizeRetryTimes = 0;
  5002. return result;
  5003. }
  5004. }
  5005. else
  5006. {
  5007. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5008. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5009. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5010. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5011. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5012. else
  5013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5014. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5015. result = PASS;
  5016. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5017. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5018. authorizeRetryTimes = 0;
  5019. return result;
  5020. }
  5021. }
  5022. //initialize struct Authorize
  5023. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5024. //get data from shared memory
  5025. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5026. random_uuid(guid);
  5027. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5028. LWS_Send(message);
  5029. sprintf(tempdata, "Authorize,%d", gun_index);
  5030. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5031. {
  5032. result = PASS;
  5033. DEBUG_INFO("Authorize mapItem pass\n");
  5034. }
  5035. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5036. return result;
  5037. }
  5038. int sendBootNotificationRequest(void)
  5039. {
  5040. mtrace();
  5041. int result = FAIL;
  5042. char message[500]={0}, payload[700]={0};
  5043. char guid[37]={0};
  5044. char tempdata[65]={0};
  5045. // Fill BootNotification fields
  5046. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5047. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5048. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5049. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5050. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5051. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5052. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5053. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5054. ShmOCPP16Data->ChargeBoxId
  5055. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5056. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5057. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5058. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5059. ,ShmOCPP16Data->BootNotification.CpIccid
  5060. ,ShmOCPP16Data->BootNotification.CpImsi);
  5061. random_uuid(guid);
  5062. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5063. LWS_Send(message);
  5064. sprintf(tempdata, "BootNotification,0");
  5065. 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*/)
  5066. {
  5067. result = PASS;
  5068. }
  5069. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5070. strcpy(queuedata,message);
  5071. return result;
  5072. }
  5073. int sendDataTransferRequest(int gun_index)
  5074. {
  5075. mtrace();
  5076. char message[1000]={0};
  5077. char guid[37]={0};
  5078. char tempdata[65]={0};
  5079. int result = FAIL;
  5080. random_uuid(guid);
  5081. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5082. MESSAGE_TYPE_CALL,
  5083. guid,
  5084. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5085. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5086. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5087. LWS_Send(message);
  5088. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5089. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5090. {
  5091. result = PASS;
  5092. DEBUG_INFO("DataTransfer mapItem pass\n");
  5093. }
  5094. return result;
  5095. }
  5096. int sendDiagnosticsStatusNotificationRequest(char *status)
  5097. {
  5098. mtrace();
  5099. int result = FAIL;
  5100. char message[110]={0};
  5101. char guid[37]={0};
  5102. char tempdata[65]={0};
  5103. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5104. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5105. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5106. random_uuid(guid);
  5107. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5108. LWS_SendNow(message);
  5109. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5110. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5111. {
  5112. result = PASS;
  5113. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5114. }
  5115. //#ifdef SystemLogMessage
  5116. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5117. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5118. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5119. //#endif
  5120. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5122. //record status
  5123. if(strcmp(status,"Idle")==0)
  5124. {
  5125. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5126. }
  5127. else if(strcmp(status,"Uploaded")==0)
  5128. {
  5129. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5130. }
  5131. else if(strcmp(status,"UploadFailed")==0)
  5132. {
  5133. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5134. }
  5135. else if(strcmp(status,"Uploading")==0)
  5136. {
  5137. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5138. }
  5139. return result;
  5140. }
  5141. int sendFirmwareStatusNotificationRequest(char *status)
  5142. {
  5143. mtrace();
  5144. int result = FAIL;
  5145. char message[110]={0};
  5146. char guid[37]={0};
  5147. char tempdata[65]={0};
  5148. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5149. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5150. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5151. random_uuid(guid);
  5152. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5153. LWS_SendNow(message);
  5154. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5155. 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*/)
  5156. {
  5157. result = PASS;
  5158. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5159. }
  5160. //#ifdef SystemLogMessage
  5161. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5162. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5163. //#endif
  5164. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5165. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5166. //record status
  5167. if(strcmp(status,"Downloaded")==0)
  5168. {
  5169. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5170. }
  5171. else if(strcmp(status,"DownloadFailed")==0)
  5172. {
  5173. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5174. }
  5175. else if(strcmp(status,"Downloading")==0)
  5176. {
  5177. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5178. }
  5179. else if(strcmp(status,"Idle")==0)
  5180. {
  5181. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5182. }
  5183. else if(strcmp(status,"InstallationFailed")==0)
  5184. {
  5185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5186. }
  5187. else if(strcmp(status,"Installing")==0)
  5188. {
  5189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5190. }
  5191. else if(strcmp(status,"Installed")==0)
  5192. {
  5193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5194. }
  5195. return result;
  5196. }
  5197. int sendHeartbeatRequest(int gun_index)
  5198. {
  5199. mtrace();
  5200. int result = FAIL;
  5201. char message[80]={0};
  5202. char guid[37]={0};
  5203. char tempdata[65]={0};
  5204. random_uuid(guid);
  5205. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5206. , MESSAGE_TYPE_CALL
  5207. , guid );
  5208. LWS_Send(message);
  5209. sprintf(tempdata, "Heartbeat,%d", 0);
  5210. 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*/)
  5211. {
  5212. result = PASS;
  5213. }
  5214. return result;
  5215. }
  5216. int sendStartTransactionRequest(int gun_index)
  5217. {
  5218. mtrace();
  5219. int result = FAIL;
  5220. char message[250]={0};
  5221. char guid[37]={0};
  5222. struct timeval tmnow;
  5223. struct tm *tm;
  5224. char buf[28];//, usec_buf[6];
  5225. char tempdata[65]={0};
  5226. int tempIndex = 0;
  5227. DEBUG_INFO("sendStartTransactionRequest...\n");
  5228. gettimeofday(&tmnow, NULL);
  5229. time_t t;
  5230. t = time(NULL);
  5231. /*UTC time and date*/
  5232. tm = gmtime(&t);
  5233. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5234. #if 0 // remove temporally
  5235. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5236. strcat(buf,".");
  5237. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5238. strcat(buf,usec_buf);
  5239. #endif
  5240. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5241. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5242. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5243. // clear StartTransaction Response
  5244. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5245. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5246. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5247. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5248. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5249. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5250. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5253. {
  5254. tempIndex = ((gun_index==2) ? 1: 0);
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5261. {
  5262. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5263. {
  5264. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5265. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5266. }
  5267. }
  5268. }
  5269. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5270. {
  5271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5272. {
  5273. tempIndex = ((gun_index==2) ? 1: 0);
  5274. }
  5275. else
  5276. {
  5277. tempIndex = gun_index;
  5278. }
  5279. for (int index = 0; index < CCS_QUANTITY; index++)
  5280. {
  5281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5282. {
  5283. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5284. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5285. }
  5286. }
  5287. }
  5288. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5289. {
  5290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5291. {
  5292. tempIndex = ((gun_index==2) ? 1: 0);
  5293. }
  5294. else
  5295. {
  5296. tempIndex = gun_index;
  5297. }
  5298. for (int index = 0; index < GB_QUANTITY; index++)
  5299. {
  5300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5301. {
  5302. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5303. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5304. }
  5305. }
  5306. }
  5307. else if(gunType[gun_index] == GUN_TYPE_DO)
  5308. {
  5309. tempIndex = gun_index;
  5310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5313. {
  5314. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5315. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5316. }
  5317. }
  5318. }
  5319. else
  5320. {
  5321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5322. {
  5323. tempIndex = 2;
  5324. }
  5325. else
  5326. {
  5327. tempIndex = gun_index;
  5328. }
  5329. for (int index = 0; index < AC_QUANTITY; index++)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5332. {
  5333. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5334. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5335. }
  5336. }
  5337. }
  5338. random_uuid(guid);
  5339. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5340. {
  5341. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5342. , gun_index +1
  5343. , MESSAGE_TYPE_CALL
  5344. , guid
  5345. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5346. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5347. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5348. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5349. }
  5350. else
  5351. {
  5352. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5353. , gun_index +1
  5354. , MESSAGE_TYPE_CALL
  5355. , guid
  5356. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5357. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5358. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5359. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5360. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5361. }
  5362. #if 1
  5363. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5364. 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*/)
  5365. {
  5366. result = PASS;
  5367. }
  5368. #endif
  5369. strcpy(queuedata, message);
  5370. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5371. OCPP_insert_transaction_msg(YES, queuedata);
  5372. return result;
  5373. }
  5374. int sendStatusNotificationRequest(int gun_index)
  5375. {
  5376. mtrace();
  5377. int result = FAIL;
  5378. char message[600]={0};
  5379. char guid[37];
  5380. int currentStatus = 0;
  5381. struct timeval tmnow;
  5382. struct tm *tm;
  5383. char buf[28];//, usec_buf[6];
  5384. char tempdata[65]={0};
  5385. int tempIndex = 0;
  5386. uint8_t isStateChanged = TRUE;
  5387. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5388. gettimeofday(&tmnow, NULL);
  5389. time_t t;
  5390. t = time(NULL);
  5391. /*UTC time and date*/
  5392. tm = gmtime(&t);
  5393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5394. #if 0 // remove temporally
  5395. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5396. strcat(buf,".");
  5397. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5398. strcat(buf,usec_buf);
  5399. #endif
  5400. //printf("%s",buf);
  5401. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5402. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5403. // it's option
  5404. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5405. /*
  5406. enum _SYSTEM_STATUS
  5407. {
  5408. S_BOOTING = 0,
  5409. S_IDLE, = 1
  5410. S_AUTHORIZING, =2
  5411. S_REASSIGN_CHECK, =3
  5412. S_REASSIGN, =4
  5413. S_PRECHARGE, =5
  5414. S_PREPARING_FOR_EV, =6
  5415. S_PREPARING_FOR_EVSE, =7
  5416. S_CHARGING, =8
  5417. S_TERMINATING, =9
  5418. S_COMPLETE, =10
  5419. S_ALARM, =11
  5420. S_FAULT =12
  5421. }
  5422. */
  5423. //check Transaction active
  5424. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5425. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5436. {
  5437. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5438. {
  5439. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5440. {
  5441. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5442. {
  5443. currentStatus = Preparing; //OCPP Status: Preparing
  5444. }
  5445. else
  5446. {
  5447. currentStatus = Available; //OCPP Status: Available
  5448. }
  5449. }
  5450. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5451. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5452. ) //S_PRECHARGE
  5453. {
  5454. currentStatus = Preparing; //OCPP Status: Preparing
  5455. }
  5456. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5457. {
  5458. currentStatus = Charging; //OCPP Status: Charging
  5459. }
  5460. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5461. {
  5462. currentStatus = Finishing; //OCPP Status: Finishing
  5463. }
  5464. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5465. {
  5466. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5467. }
  5468. 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
  5469. {
  5470. currentStatus = Unavailable; //OCPP Status: Unavailable
  5471. }
  5472. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5473. {
  5474. currentStatus = Faulted; //OCPP Status: Faulted
  5475. }
  5476. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5477. {
  5478. currentStatus = Reserved; //OCPP Status: Reserved
  5479. }
  5480. } //end of the same index
  5481. }//end of for CHAdeMO_QUANTITY
  5482. }
  5483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5484. {
  5485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5486. {
  5487. tempIndex = ((gun_index==2) ? 1: 0);
  5488. }
  5489. else
  5490. {
  5491. tempIndex = gun_index;
  5492. }
  5493. for (int index = 0; index < CCS_QUANTITY; index++)
  5494. {
  5495. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5496. {
  5497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5498. {
  5499. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5500. {
  5501. currentStatus = Preparing; //OCPP Status: Preparing
  5502. }
  5503. else
  5504. {
  5505. currentStatus = Available; //OCPP Status: Available
  5506. }
  5507. }
  5508. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5509. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5510. ) //S_PRECHARGE
  5511. {
  5512. currentStatus = Preparing; //OCPP Status: Preparing
  5513. }
  5514. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5515. {
  5516. currentStatus = Charging; //OCPP Status: Charging
  5517. }
  5518. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5519. {
  5520. currentStatus = Finishing; //OCPP Status: Finishing
  5521. }
  5522. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5523. {
  5524. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5525. }
  5526. 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
  5527. {
  5528. currentStatus = Unavailable; //OCPP Status : Unavailable
  5529. }
  5530. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5531. {
  5532. currentStatus = Faulted; //OCPP Status: Faulted
  5533. }
  5534. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5535. {
  5536. currentStatus = Reserved; //OCPP Status: Reserved
  5537. }
  5538. } //end of the same index
  5539. } // end of for CCS_QUANTITY
  5540. }
  5541. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5542. {
  5543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5544. {
  5545. tempIndex = ((gun_index==2) ? 1: 0);
  5546. }
  5547. else
  5548. {
  5549. tempIndex = gun_index;
  5550. }
  5551. for (int index = 0; index < GB_QUANTITY; index++)
  5552. {
  5553. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5556. {
  5557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5558. {
  5559. currentStatus = Preparing; //OCPP Status: Preparing
  5560. }
  5561. else
  5562. {
  5563. currentStatus = Available; //OCPP Status: Available
  5564. }
  5565. }
  5566. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5567. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5568. ) //S_PRECHARGE
  5569. {
  5570. currentStatus = Preparing; //OCPP Status: Preparing
  5571. }
  5572. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5573. {
  5574. currentStatus = Charging; //OCPP Status: Charging
  5575. }
  5576. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5577. {
  5578. currentStatus = Finishing; //OCPP Status: Finishing
  5579. }
  5580. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5581. {
  5582. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5583. }
  5584. 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
  5585. {
  5586. currentStatus = Unavailable; //OCPP Status: Unavailable
  5587. }
  5588. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5589. {
  5590. currentStatus = Faulted; //OCPP Status: Faulted
  5591. }
  5592. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5593. {
  5594. currentStatus = Reserved; //OCPP Status: Reserved
  5595. }
  5596. } //end of the same index
  5597. } // end of for GB_QUANTITY
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_DO)
  5600. {
  5601. tempIndex = gun_index;
  5602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5603. {
  5604. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5605. {
  5606. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5607. {
  5608. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5609. {
  5610. currentStatus = Preparing; //OCPP Status: Preparing
  5611. }
  5612. else
  5613. {
  5614. currentStatus = Available; //OCPP Status: Available
  5615. }
  5616. }
  5617. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5618. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5619. ) //S_PRECHARGE
  5620. {
  5621. currentStatus = Preparing; //OCPP Status: Preparing
  5622. }
  5623. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5624. {
  5625. currentStatus = Charging; //OCPP Status: Charging
  5626. }
  5627. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5628. {
  5629. currentStatus = Finishing; //OCPP Status: Finishing
  5630. }
  5631. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5632. {
  5633. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5634. }
  5635. 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
  5636. {
  5637. currentStatus = Unavailable; //OCPP Status: Unavailable
  5638. }
  5639. 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
  5640. {
  5641. currentStatus = Faulted; //OCPP Status: Faulted
  5642. }
  5643. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5644. {
  5645. currentStatus = Reserved; //OCPP Status: Reserved
  5646. }
  5647. } //end of the same index
  5648. }
  5649. }
  5650. else
  5651. {
  5652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5653. {
  5654. tempIndex = 2;
  5655. }
  5656. else
  5657. {
  5658. tempIndex = gun_index;
  5659. }
  5660. for (int index = 0; index < AC_QUANTITY; index++)
  5661. {
  5662. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5663. {
  5664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5665. {
  5666. 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))
  5667. {
  5668. currentStatus = Preparing; //OCPP Status: Preparing
  5669. }
  5670. else
  5671. {
  5672. currentStatus = Available; //OCPP Status: Available
  5673. }
  5674. }
  5675. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5676. {
  5677. currentStatus = Preparing; //OCPP Status: Preparing
  5678. }
  5679. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5680. {
  5681. currentStatus = Charging; //OCPP Status: Charging
  5682. }
  5683. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5684. {
  5685. currentStatus = Finishing; //OCPP Status: Finishing
  5686. }
  5687. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5688. {
  5689. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5690. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5691. else
  5692. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5693. }
  5694. 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
  5695. {
  5696. currentStatus = Unavailable; //OCPP Status: Unavailable
  5697. }
  5698. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5699. {
  5700. currentStatus = Faulted; //OCPP Status: Faulted
  5701. }
  5702. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5703. {
  5704. currentStatus = Reserved; //OCPP Status: Reserved
  5705. }
  5706. }//end of the same index
  5707. }//end of for AC_QUANTITY
  5708. }
  5709. //it's option
  5710. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5711. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5712. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5713. {
  5714. isStateChanged = FALSE;
  5715. }
  5716. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5717. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5718. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5719. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5720. random_uuid(guid);
  5721. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5722. , MESSAGE_TYPE_CALL
  5723. , guid
  5724. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5725. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5726. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5727. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5728. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5729. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5730. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5731. if((server_sign == TRUE) && isStateChanged)
  5732. {
  5733. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5734. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5735. LWS_Send(message);
  5736. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5737. 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*/)
  5738. {
  5739. //DEBUG_ERROR("statusNotification mapitem pass");
  5740. result = PASS;
  5741. }
  5742. }
  5743. else
  5744. {
  5745. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5746. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5747. result = PASS;
  5748. }
  5749. return result;
  5750. }
  5751. int sendStopTransactionRequest(int gun_index)
  5752. {
  5753. mtrace();
  5754. int result = FAIL;
  5755. //char message[1500]={0};
  5756. char guid[37]={0};
  5757. char tempdata[65]={0};
  5758. int tempIndex = 0;
  5759. char TempStopTransaction[256];
  5760. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5761. //int idx_sample=0;
  5762. DEBUG_INFO("sendStopTransactionRequest \n");
  5763. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5764. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5765. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5766. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5767. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5768. {
  5769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5770. {
  5771. tempIndex = ((gun_index==2) ? 1: 0);
  5772. }
  5773. else
  5774. {
  5775. tempIndex = gun_index;
  5776. }
  5777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5778. {
  5779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5780. {
  5781. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5782. }
  5783. }// END OF CHAdeMO_QUANTITY
  5784. }
  5785. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5786. {
  5787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5788. {
  5789. tempIndex = ((gun_index==2) ? 1: 0);
  5790. }
  5791. else
  5792. {
  5793. tempIndex = gun_index;
  5794. }
  5795. for (int index = 0; index < CCS_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5798. {
  5799. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5800. }
  5801. }// END OF CCS_QUANTITY
  5802. }
  5803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5804. {
  5805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5806. {
  5807. tempIndex = ((gun_index==2) ? 1: 0);
  5808. }
  5809. else
  5810. {
  5811. tempIndex = gun_index;
  5812. }
  5813. for (int index = 0; index < GB_QUANTITY; index++)
  5814. {
  5815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5816. {
  5817. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5818. }
  5819. }// END OF GB_QUANTITY
  5820. }
  5821. else if(gunType[gun_index] == GUN_TYPE_DO)
  5822. {
  5823. tempIndex = gun_index;
  5824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5827. {
  5828. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5829. }
  5830. }// END OF GB_QUANTITY
  5831. }
  5832. else
  5833. {
  5834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5835. {
  5836. tempIndex = 2;
  5837. }
  5838. else
  5839. {
  5840. tempIndex = gun_index;
  5841. }
  5842. for (int index = 0; index < AC_QUANTITY; index++)
  5843. {
  5844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5845. {
  5846. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5847. }
  5848. }// END OF AC_QUANTITY
  5849. }
  5850. //====================================== Stop Transaction Time =====================================================
  5851. struct timeval tmnow;
  5852. struct tm *tm;
  5853. char buf[28];//, usec_buf[6];
  5854. gettimeofday(&tmnow, NULL);
  5855. time_t t;
  5856. t = time(NULL);
  5857. /*UTC time and date*/
  5858. tm = gmtime(&t);
  5859. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5861. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5862. random_uuid(guid);
  5863. /***********************************transactionData******************************************************/
  5864. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5866. //=================================
  5867. // Transaction_Begin
  5868. //=================================
  5869. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5870. {
  5871. //============================================ Energy.Active.Import.Interval ================================
  5872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5875. 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*/]);
  5876. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5877. 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))
  5878. {
  5879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5880. }
  5881. else
  5882. {
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5884. }
  5885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5887. }
  5888. //=================================
  5889. // Transaction_End
  5890. //=================================
  5891. // ================================= Current.Import L1 ===============================================
  5892. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5893. {
  5894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5898. {
  5899. tempIndex = ((gun_index==2) ? 1: 0);
  5900. }
  5901. else
  5902. {
  5903. tempIndex = gun_index;
  5904. }
  5905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5906. {
  5907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5908. {
  5909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5910. }
  5911. }// End of for CHAdeMO_QUANTITY
  5912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5913. }
  5914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5915. {
  5916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5917. {
  5918. tempIndex = ((gun_index==2) ? 1: 0);
  5919. }
  5920. else
  5921. {
  5922. tempIndex = gun_index;
  5923. }
  5924. for (int index = 0; index < CCS_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5927. {
  5928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5929. }
  5930. }// End of for CCS_QUANTITY
  5931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5932. }
  5933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5934. {
  5935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5936. {
  5937. tempIndex = ((gun_index==2) ? 1: 0);
  5938. }
  5939. else
  5940. {
  5941. tempIndex = gun_index;
  5942. }
  5943. for (int index = 0; index < GB_QUANTITY; index++)
  5944. {
  5945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5946. {
  5947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5948. }
  5949. }// End of for GB_QUANTITY
  5950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5951. }
  5952. else if(gunType[gun_index] == GUN_TYPE_DO)
  5953. {
  5954. tempIndex = gun_index;
  5955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5958. {
  5959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5960. }
  5961. }
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5963. }
  5964. else
  5965. {
  5966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5967. {
  5968. tempIndex = 2;
  5969. }
  5970. else
  5971. {
  5972. tempIndex = gun_index;
  5973. }
  5974. for (int index = 0; index < AC_QUANTITY; index++)
  5975. {
  5976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5977. {
  5978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5979. }
  5980. }// End of for AC_QUANTITY
  5981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5982. }
  5983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5988. }
  5989. // ================================= Energy.Active.Import.Interval ==============================================
  5990. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5991. {
  5992. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5993. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5994. {
  5995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5996. {
  5997. tempIndex = ((gun_index==2) ? 1: 0);
  5998. }
  5999. else
  6000. {
  6001. tempIndex = gun_index;
  6002. }
  6003. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6004. {
  6005. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6006. {
  6007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6008. }
  6009. }// END OF CHAdeMO_QUANTITY
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6011. }
  6012. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6013. {
  6014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6015. {
  6016. tempIndex = ((gun_index==2) ? 1: 0);
  6017. }
  6018. else
  6019. {
  6020. tempIndex = gun_index;
  6021. }
  6022. for (int index = 0; index < CCS_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6027. }
  6028. }// END OF CCS_QUANTITY
  6029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6030. }
  6031. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6032. {
  6033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6034. {
  6035. tempIndex = ((gun_index==2) ? 1: 0);
  6036. }
  6037. else
  6038. {
  6039. tempIndex = gun_index;
  6040. }
  6041. for (int index = 0; index < GB_QUANTITY; index++)
  6042. {
  6043. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6044. {
  6045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6046. }
  6047. }// END OF GB_QUANTITY
  6048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6049. }
  6050. else if(gunType[gun_index] == GUN_TYPE_DO)
  6051. {
  6052. tempIndex = gun_index;
  6053. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6054. {
  6055. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6056. {
  6057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6058. }
  6059. }
  6060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6061. }
  6062. else
  6063. {
  6064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6065. {
  6066. tempIndex = 2;
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. for (int index = 0; index < AC_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6077. }
  6078. }// END OF AC_QUANTITY
  6079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6080. }
  6081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6086. }
  6087. //=================================== Power.Active.Import ==================================================
  6088. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6089. {
  6090. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6091. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6094. {
  6095. tempIndex = ((gun_index==2) ? 1: 0);
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6106. }
  6107. } // End for CHAdeMO_QUANTITY
  6108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6109. }
  6110. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6111. {
  6112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6113. {
  6114. tempIndex = ((gun_index==2) ? 1: 0);
  6115. }
  6116. else
  6117. {
  6118. tempIndex = gun_index;
  6119. }
  6120. for (int index = 0; index < CCS_QUANTITY; index++)
  6121. {
  6122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6123. {
  6124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6125. }
  6126. } // END for CCS_QUANTITY
  6127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6128. }
  6129. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6130. {
  6131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6132. {
  6133. tempIndex = ((gun_index==2) ? 1: 0);
  6134. }
  6135. else
  6136. {
  6137. tempIndex = gun_index;
  6138. }
  6139. for (int index = 0; index < GB_QUANTITY; index++)
  6140. {
  6141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6142. {
  6143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6144. }
  6145. }// END for GB_QUANTITY
  6146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6147. }
  6148. else if(gunType[gun_index] == GUN_TYPE_DO)
  6149. {
  6150. tempIndex = gun_index;
  6151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6152. {
  6153. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6154. {
  6155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6156. }
  6157. }
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6159. }
  6160. else
  6161. {
  6162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6163. {
  6164. tempIndex = 2;
  6165. }
  6166. else
  6167. {
  6168. tempIndex = gun_index;
  6169. }
  6170. for (int index = 0; index < AC_QUANTITY; index++)
  6171. {
  6172. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6173. {
  6174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6175. }
  6176. } // END for AC_QUANTITY
  6177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6178. }
  6179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6184. }
  6185. //============================ Voltage L1 ====================================
  6186. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6187. {
  6188. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6189. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6202. {
  6203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6204. }
  6205. } // END OF FOR CHAdeMO_QUANTITY
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6207. }
  6208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6209. {
  6210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6211. {
  6212. tempIndex = ((gun_index==2) ? 1: 0);
  6213. }
  6214. else
  6215. {
  6216. tempIndex = gun_index;
  6217. }
  6218. for (int index = 0; index < CCS_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6223. }
  6224. } // END OF FOR CCS_QUANTITY
  6225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6226. }
  6227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6228. {
  6229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6230. {
  6231. tempIndex = ((gun_index==2) ? 1: 0);
  6232. }
  6233. else
  6234. {
  6235. tempIndex = gun_index;
  6236. }
  6237. for (int index = 0; index < GB_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6240. {
  6241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6242. }
  6243. } // END OF FOR GB_QUANTITY
  6244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6245. }
  6246. else if(gunType[gun_index] == GUN_TYPE_DO)
  6247. {
  6248. tempIndex = gun_index;
  6249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6254. }
  6255. }
  6256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6257. }
  6258. else
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6261. {
  6262. tempIndex = 2;
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < AC_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6271. {
  6272. 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
  6273. }
  6274. } // END OF FOR AC_QUANTITY
  6275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6276. }
  6277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6282. }
  6283. //====================== End SoC ================================
  6284. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6285. {
  6286. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6287. 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))
  6288. {
  6289. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6290. {
  6291. tempIndex = ((gun_index==2) ? 1: 0);
  6292. }
  6293. else
  6294. {
  6295. tempIndex = gun_index;
  6296. }
  6297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6298. {
  6299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6304. }
  6305. }
  6306. }
  6307. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6308. {
  6309. for (int index = 0; index < CCS_QUANTITY; index++)
  6310. {
  6311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6312. {
  6313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6314. }
  6315. }
  6316. }
  6317. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6318. {
  6319. for (int index = 0; index < GB_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6322. {
  6323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6324. }
  6325. }
  6326. }
  6327. else if(gunType[gun_index] == GUN_TYPE_DO)
  6328. {
  6329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6330. {
  6331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6332. {
  6333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6334. }
  6335. }
  6336. }
  6337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6343. } // END FOR DC CASE
  6344. }
  6345. // ================================= Current.Import L2 ===============================================
  6346. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6347. {
  6348. // AC 3 phse L2 current
  6349. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6350. {
  6351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6352. {
  6353. tempIndex = 2;
  6354. }
  6355. else
  6356. {
  6357. tempIndex = gun_index;
  6358. }
  6359. for (int index = 0; index < AC_QUANTITY; index++)
  6360. {
  6361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6362. {
  6363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6364. }
  6365. }// End of for AC_QUANTITY
  6366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6367. }
  6368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6373. }
  6374. // ================================= Current.Import L3 ===============================================
  6375. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6376. {
  6377. // AC 3 phse L3 current
  6378. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6379. {
  6380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6381. {
  6382. tempIndex = 2;
  6383. }
  6384. else
  6385. {
  6386. tempIndex = gun_index;
  6387. }
  6388. for (int index = 0; index < AC_QUANTITY; index++)
  6389. {
  6390. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6391. {
  6392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6393. }
  6394. }// End of for AC_QUANTITY
  6395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6396. }
  6397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6402. }
  6403. //============================ Voltage L2 ====================================
  6404. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6405. {
  6406. // AC 3 phse L2 voltage
  6407. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6408. {
  6409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6410. {
  6411. tempIndex = 2;
  6412. }
  6413. else
  6414. {
  6415. tempIndex = gun_index;
  6416. }
  6417. for (int index = 0; index < AC_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6420. {
  6421. 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
  6422. }
  6423. } // END OF FOR AC_QUANTITY
  6424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6425. }
  6426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6431. }
  6432. //============================ Voltage L3 ====================================
  6433. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6434. {
  6435. // AC 3 phse L3 voltage
  6436. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6437. {
  6438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6439. {
  6440. tempIndex = 2;
  6441. }
  6442. else
  6443. {
  6444. tempIndex = gun_index;
  6445. }
  6446. for (int index = 0; index < AC_QUANTITY; index++)
  6447. {
  6448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6449. {
  6450. 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
  6451. }
  6452. } // END OF FOR AC_QUANTITY
  6453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6454. }
  6455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6460. }
  6461. //====================== Start SoC ================================
  6462. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6463. {
  6464. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6465. 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))
  6466. {
  6467. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6468. {
  6469. tempIndex = ((gun_index==2) ? 1: 0);
  6470. }
  6471. else
  6472. {
  6473. tempIndex = gun_index;
  6474. }
  6475. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6476. {
  6477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6478. {
  6479. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6480. {
  6481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6482. }
  6483. }
  6484. }
  6485. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6486. {
  6487. for (int index = 0; index < CCS_QUANTITY; index++)
  6488. {
  6489. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6490. {
  6491. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6492. }
  6493. }
  6494. }
  6495. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6496. {
  6497. for (int index = 0; index < GB_QUANTITY; index++)
  6498. {
  6499. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6500. {
  6501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6502. }
  6503. }
  6504. }
  6505. else if(gunType[gun_index] == GUN_TYPE_DO)
  6506. {
  6507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6508. {
  6509. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6510. {
  6511. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6512. }
  6513. }
  6514. }
  6515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6521. } // END FOR DC CASE
  6522. }
  6523. //================================================ Message create ====================================================
  6524. json_object *StopTransaction = json_object_new_object();
  6525. json_object *transactionDatas = json_object_new_array();
  6526. json_object *sampledValues = json_object_new_array();
  6527. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6528. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6529. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6530. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6531. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6532. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6533. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6534. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6535. {
  6536. json_object *transactionData = json_object_new_object();
  6537. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6538. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6539. {
  6540. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6541. {
  6542. json_object *sampledValue = json_object_new_object();
  6543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6556. json_object_array_add(sampledValues, sampledValue);
  6557. }
  6558. }
  6559. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6560. json_object_array_add(transactionDatas, transactionData);
  6561. }
  6562. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6563. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6564. ,MESSAGE_TYPE_CALL
  6565. ,guid
  6566. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6567. json_object_put(StopTransaction);
  6568. #if 1 // for TempStopTransaction
  6569. //Delete TempStopTransaction
  6570. if((access(TempStopTransaction,F_OK))!=-1)
  6571. {
  6572. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6573. }
  6574. #endif
  6575. #if 1
  6576. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6577. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6578. {
  6579. result = PASS;
  6580. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6581. }
  6582. #endif
  6583. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6584. OCPP_insert_transaction_msg(NO, queuedata);
  6585. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6586. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6587. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6588. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6589. {
  6590. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6591. }
  6592. //for test
  6593. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6594. return result;
  6595. }
  6596. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6597. {
  6598. mtrace();
  6599. int result = FAIL;
  6600. char guid[37]={0};
  6601. char tempdata[65]={0};
  6602. int tempIndex = 0;
  6603. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6604. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6605. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6606. //set value
  6607. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6608. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6609. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6610. -1);
  6611. random_uuid(guid);
  6612. //UTC Date time
  6613. struct timeval tmnow;
  6614. struct tm *tm;
  6615. char buf[28];//, usec_buf[6];
  6616. gettimeofday(&tmnow, NULL);
  6617. time_t t;
  6618. t = time(NULL);
  6619. /*UTC time and date*/
  6620. tm = gmtime(&t);
  6621. if(dataType == ReadingContext_Sample_Clock)
  6622. {
  6623. struct tm *tmTarget;
  6624. struct timeb tbTarget;
  6625. tbTarget.time = mktime(tm);
  6626. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6627. tmTarget = gmtime(&tbTarget.time);
  6628. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6629. }
  6630. else
  6631. {
  6632. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6633. }
  6634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6635. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6636. //********************************(1)Current.Import L1************************************************/
  6637. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6638. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6639. (dataType == ReadingContext_Trigger))
  6640. {
  6641. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6642. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6645. {
  6646. tempIndex = ((gun_index==2) ? 1: 0);
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6655. {
  6656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6657. }
  6658. }
  6659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6660. }
  6661. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6662. {
  6663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6664. {
  6665. tempIndex = ((gun_index==2) ? 1: 0);
  6666. }
  6667. else
  6668. {
  6669. tempIndex = gun_index;
  6670. }
  6671. for (int index = 0; index < CCS_QUANTITY; index++)
  6672. {
  6673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6674. {
  6675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6676. }
  6677. }
  6678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6679. }
  6680. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6681. {
  6682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6683. {
  6684. tempIndex = ((gun_index==2) ? 1: 0);
  6685. }
  6686. else
  6687. {
  6688. tempIndex = gun_index;
  6689. }
  6690. for (int index = 0; index < GB_QUANTITY; index++)
  6691. {
  6692. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6693. {
  6694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6695. }
  6696. }
  6697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6698. }
  6699. else if(gunType[gun_index] == GUN_TYPE_DO)
  6700. {
  6701. tempIndex = gun_index;
  6702. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6703. {
  6704. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6705. {
  6706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6707. }
  6708. }
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6710. }
  6711. else
  6712. {
  6713. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6714. {
  6715. tempIndex = 2;
  6716. }
  6717. else
  6718. {
  6719. tempIndex = gun_index;
  6720. }
  6721. for (int index = 0; index < AC_QUANTITY; index++)
  6722. {
  6723. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6724. {
  6725. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6726. }
  6727. }
  6728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6729. }
  6730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6735. }
  6736. //********************************(2)Energy.Active.Import.Register ************************************************/
  6737. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6738. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6739. (dataType == ReadingContext_Trigger))
  6740. {
  6741. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6742. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6743. {
  6744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6745. {
  6746. tempIndex = ((gun_index==2) ? 1: 0);
  6747. }
  6748. else
  6749. {
  6750. tempIndex = gun_index;
  6751. }
  6752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6753. {
  6754. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6755. {
  6756. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6757. }
  6758. }
  6759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6760. }
  6761. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6762. {
  6763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6764. {
  6765. tempIndex = ((gun_index==2) ? 1: 0);
  6766. }
  6767. else
  6768. {
  6769. tempIndex = gun_index;
  6770. }
  6771. for (int index = 0; index < CCS_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6776. }
  6777. }
  6778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6779. }
  6780. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6781. {
  6782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6783. {
  6784. tempIndex = ((gun_index==2) ? 1: 0);
  6785. }
  6786. else
  6787. {
  6788. tempIndex = gun_index;
  6789. }
  6790. for (int index = 0; index < GB_QUANTITY; index++)
  6791. {
  6792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6793. {
  6794. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6795. }
  6796. }
  6797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6798. }
  6799. else if(gunType[gun_index] == GUN_TYPE_DO)
  6800. {
  6801. tempIndex = gun_index;
  6802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6803. {
  6804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6805. {
  6806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6807. }
  6808. }
  6809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6810. }
  6811. else
  6812. {
  6813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6814. {
  6815. tempIndex = 2;
  6816. }
  6817. else
  6818. {
  6819. tempIndex = gun_index;
  6820. }
  6821. for (int index = 0; index < AC_QUANTITY; index++)
  6822. {
  6823. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6824. {
  6825. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6826. }
  6827. }
  6828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6829. }
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6835. }
  6836. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6837. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6838. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6839. (dataType == ReadingContext_Trigger))
  6840. {
  6841. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6843. {
  6844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6845. {
  6846. tempIndex = ((gun_index==2) ? 1: 0);
  6847. }
  6848. else
  6849. {
  6850. tempIndex = gun_index;
  6851. }
  6852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6853. {
  6854. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6855. {
  6856. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6857. }
  6858. } // END OF FOR CHAdeMO_QUANTITY
  6859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6860. }
  6861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6862. {
  6863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6864. {
  6865. tempIndex = ((gun_index==2) ? 1: 0);
  6866. }
  6867. else
  6868. {
  6869. tempIndex = gun_index;
  6870. }
  6871. for (int index = 0; index < CCS_QUANTITY; index++)
  6872. {
  6873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6874. {
  6875. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6876. }
  6877. } // END OF CCS_QUANTITY
  6878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6879. }
  6880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6881. {
  6882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6883. {
  6884. tempIndex = ((gun_index==2) ? 1: 0);
  6885. }
  6886. else
  6887. {
  6888. tempIndex = gun_index;
  6889. }
  6890. for (int index = 0; index < GB_QUANTITY; index++)
  6891. {
  6892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6893. {
  6894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6895. }
  6896. } // END OF GB_QUANTITY
  6897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6898. }
  6899. else if(gunType[gun_index] == GUN_TYPE_DO)
  6900. {
  6901. tempIndex = gun_index;
  6902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6903. {
  6904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6905. {
  6906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6907. }
  6908. }
  6909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6910. }
  6911. else
  6912. {
  6913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6914. {
  6915. tempIndex = 2;
  6916. }
  6917. else
  6918. {
  6919. tempIndex = gun_index;
  6920. }
  6921. for (int index = 0; index < AC_QUANTITY; index++)
  6922. {
  6923. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6924. {
  6925. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6926. }
  6927. }
  6928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6929. }
  6930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6935. }
  6936. //********************************(4)Power.Active.Import************************************************/
  6937. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6938. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6939. (dataType == ReadingContext_Trigger))
  6940. {
  6941. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6943. {
  6944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6945. {
  6946. tempIndex = ((gun_index==2) ? 1: 0);
  6947. }
  6948. else
  6949. {
  6950. tempIndex = gun_index;
  6951. }
  6952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6955. {
  6956. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6957. }
  6958. } // END OF FOR
  6959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6960. }
  6961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6962. {
  6963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6964. {
  6965. tempIndex = ((gun_index==2) ? 1: 0);
  6966. }
  6967. else
  6968. {
  6969. tempIndex = gun_index;
  6970. }
  6971. for (int index = 0; index < CCS_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6974. {
  6975. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6976. }
  6977. }
  6978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6979. }
  6980. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6981. {
  6982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6983. {
  6984. tempIndex = ((gun_index==2) ? 1: 0);
  6985. }
  6986. else
  6987. {
  6988. tempIndex = gun_index;
  6989. }
  6990. for (int index = 0; index < GB_QUANTITY; index++)
  6991. {
  6992. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6993. {
  6994. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6995. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6996. }
  6997. }
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6999. }
  7000. else if(gunType[gun_index] == GUN_TYPE_DO)
  7001. {
  7002. tempIndex = gun_index;
  7003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7006. {
  7007. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7008. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7009. }
  7010. }
  7011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7012. }
  7013. else
  7014. {
  7015. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7016. {
  7017. tempIndex = 2;
  7018. }
  7019. else
  7020. {
  7021. tempIndex = gun_index;
  7022. }
  7023. for (int index = 0; index < AC_QUANTITY; index++)
  7024. {
  7025. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7026. {
  7027. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7028. }
  7029. }
  7030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7031. }
  7032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7037. }
  7038. //***********************************************(5)VOLTAGE L1******************************************************/
  7039. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7040. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7041. (dataType == ReadingContext_Trigger))
  7042. {
  7043. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7044. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7045. {
  7046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7047. {
  7048. tempIndex = ((gun_index==2) ? 1: 0);
  7049. }
  7050. else
  7051. {
  7052. tempIndex = gun_index;
  7053. }
  7054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7055. {
  7056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7057. {
  7058. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7059. }
  7060. }
  7061. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7062. }
  7063. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7064. {
  7065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7066. {
  7067. tempIndex = ((gun_index==2) ? 1: 0);
  7068. }
  7069. else
  7070. {
  7071. tempIndex = gun_index;
  7072. }
  7073. for (int index = 0; index < CCS_QUANTITY; index++)
  7074. {
  7075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7076. {
  7077. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7078. }
  7079. }
  7080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7081. }
  7082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7083. {
  7084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7085. {
  7086. tempIndex = ((gun_index==2) ? 1: 0);
  7087. }
  7088. else
  7089. {
  7090. tempIndex = gun_index;
  7091. }
  7092. for (int index = 0; index < GB_QUANTITY; index++)
  7093. {
  7094. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7095. {
  7096. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7097. }
  7098. }
  7099. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7100. }
  7101. else if(gunType[gun_index] == GUN_TYPE_DO)
  7102. {
  7103. tempIndex = gun_index;
  7104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7107. {
  7108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7109. }
  7110. }
  7111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7112. }
  7113. else
  7114. {
  7115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7116. {
  7117. tempIndex = 2;
  7118. }
  7119. else
  7120. {
  7121. tempIndex = gun_index;
  7122. }
  7123. for (int index = 0; index < AC_QUANTITY; index++)
  7124. {
  7125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7126. {
  7127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7128. }
  7129. }
  7130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7131. }
  7132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7137. }
  7138. //***********************************************(6)SOC******************************************************/
  7139. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7140. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7141. (dataType == ReadingContext_Trigger))
  7142. {
  7143. 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))
  7144. {
  7145. //idx_sample=5;
  7146. //sampledValue = NULL;
  7147. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7148. {
  7149. tempIndex = ((gun_index==2) ? 1: 0);
  7150. }
  7151. else
  7152. {
  7153. tempIndex = gun_index;
  7154. }
  7155. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7156. {
  7157. //tempIndex = ((gun_index==2) ? 1: 0);
  7158. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7159. {
  7160. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7161. {
  7162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7163. }
  7164. }
  7165. }
  7166. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7167. {
  7168. //tempIndex = ((gun_index==2) ? 1: 0);
  7169. for (int index = 0; index < CCS_QUANTITY; index++)
  7170. {
  7171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7172. {
  7173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7174. }
  7175. }
  7176. }
  7177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7178. {
  7179. //tempIndex = ((gun_index==2) ? 1: 0);
  7180. for (int index = 0; index < GB_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7183. {
  7184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7185. }
  7186. }
  7187. }
  7188. else if(gunType[gun_index] == GUN_TYPE_DO)
  7189. {
  7190. //tempIndex = ((gun_index==2) ? 1: 0);
  7191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7192. {
  7193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7194. {
  7195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7196. }
  7197. }
  7198. }
  7199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7205. }
  7206. }
  7207. //********************************(7)Current.Import L2************************************************/
  7208. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7209. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7210. (dataType == ReadingContext_Trigger))
  7211. {
  7212. // Only for AC 3 phase
  7213. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7214. {
  7215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7216. {
  7217. tempIndex = 2;
  7218. }
  7219. else
  7220. {
  7221. tempIndex = gun_index;
  7222. }
  7223. for (int index = 0; index < AC_QUANTITY; index++)
  7224. {
  7225. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7226. {
  7227. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7228. }
  7229. }
  7230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7231. }
  7232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7237. }
  7238. //********************************(8)Current.Import L3************************************************/
  7239. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7240. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7241. (dataType == ReadingContext_Trigger))
  7242. {
  7243. // Only for AC 3 phase
  7244. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7245. {
  7246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7247. {
  7248. tempIndex = 2;
  7249. }
  7250. else
  7251. {
  7252. tempIndex = gun_index;
  7253. }
  7254. for (int index = 0; index < AC_QUANTITY; index++)
  7255. {
  7256. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7257. {
  7258. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7259. }
  7260. }
  7261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7262. }
  7263. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7266. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7268. }
  7269. //***********************************************(9)VOLTAGE L2******************************************************/
  7270. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7271. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7272. (dataType == ReadingContext_Trigger))
  7273. {
  7274. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7275. {
  7276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7277. {
  7278. tempIndex = 2;
  7279. }
  7280. else
  7281. {
  7282. tempIndex = gun_index;
  7283. }
  7284. for (int index = 0; index < AC_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7287. {
  7288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7289. }
  7290. }
  7291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7292. }
  7293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7298. }
  7299. //***********************************************(10)VOLTAGE L3******************************************************/
  7300. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7301. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7302. (dataType == ReadingContext_Trigger))
  7303. {
  7304. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7305. {
  7306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7307. {
  7308. tempIndex = 2;
  7309. }
  7310. else
  7311. {
  7312. tempIndex = gun_index;
  7313. }
  7314. for (int index = 0; index < AC_QUANTITY; index++)
  7315. {
  7316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7317. {
  7318. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7319. }
  7320. }
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7322. }
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7328. }
  7329. //***********************************************(11)Current.Offered******************************************************/
  7330. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7331. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7332. (dataType == ReadingContext_Trigger))
  7333. {
  7334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7336. {
  7337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7338. {
  7339. tempIndex = ((gun_index==2) ? 1: 0);
  7340. }
  7341. else
  7342. {
  7343. tempIndex = gun_index;
  7344. }
  7345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7346. {
  7347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7348. {
  7349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7350. }
  7351. } // END OF FOR CHAdeMO_QUANTITY
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7354. {
  7355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7356. {
  7357. tempIndex = ((gun_index==2) ? 1: 0);
  7358. }
  7359. else
  7360. {
  7361. tempIndex = gun_index;
  7362. }
  7363. for (int index = 0; index < CCS_QUANTITY; index++)
  7364. {
  7365. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7366. {
  7367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7368. }
  7369. } // END OF CCS_QUANTITY
  7370. }
  7371. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7372. {
  7373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7374. {
  7375. tempIndex = ((gun_index==2) ? 1: 0);
  7376. }
  7377. else
  7378. {
  7379. tempIndex = gun_index;
  7380. }
  7381. for (int index = 0; index < GB_QUANTITY; index++)
  7382. {
  7383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7384. {
  7385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7386. }
  7387. } // END OF GB_QUANTITY
  7388. }
  7389. else if(gunType[gun_index] == GUN_TYPE_DO)
  7390. {
  7391. tempIndex = gun_index;
  7392. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7393. {
  7394. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7395. {
  7396. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7397. }
  7398. }
  7399. }
  7400. else
  7401. {
  7402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7403. {
  7404. tempIndex = 2;
  7405. }
  7406. else
  7407. {
  7408. tempIndex = gun_index;
  7409. }
  7410. for (int index = 0; index < AC_QUANTITY; index++)
  7411. {
  7412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7413. {
  7414. uint16_t currentOffer;
  7415. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7416. {
  7417. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7418. }
  7419. else
  7420. {
  7421. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7422. }
  7423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7424. }
  7425. }
  7426. }
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7432. }
  7433. //***********************************************(12)Power.Offered******************************************************/
  7434. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7435. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7436. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7437. {
  7438. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7439. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7440. {
  7441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7442. {
  7443. tempIndex = ((gun_index==2) ? 1: 0);
  7444. }
  7445. else
  7446. {
  7447. tempIndex = gun_index;
  7448. }
  7449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7450. {
  7451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7452. {
  7453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7454. }
  7455. } // END OF FOR CHAdeMO_QUANTITY
  7456. }
  7457. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7458. {
  7459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7460. {
  7461. tempIndex = ((gun_index==2) ? 1: 0);
  7462. }
  7463. else
  7464. {
  7465. tempIndex = gun_index;
  7466. }
  7467. for (int index = 0; index < CCS_QUANTITY; index++)
  7468. {
  7469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7470. {
  7471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7472. }
  7473. } // END OF CCS_QUANTITY
  7474. }
  7475. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7476. {
  7477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7478. {
  7479. tempIndex = ((gun_index==2) ? 1: 0);
  7480. }
  7481. else
  7482. {
  7483. tempIndex = gun_index;
  7484. }
  7485. for (int index = 0; index < GB_QUANTITY; index++)
  7486. {
  7487. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7488. {
  7489. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7490. }
  7491. } // END OF GB_QUANTITY
  7492. }
  7493. else if(gunType[gun_index] == GUN_TYPE_DO)
  7494. {
  7495. tempIndex = gun_index;
  7496. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7497. {
  7498. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7499. {
  7500. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7501. }
  7502. }
  7503. }
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7509. }
  7510. // Message create ====================================================================================================
  7511. if(TRUE)
  7512. {
  7513. json_object *MeterValueReq = json_object_new_object();
  7514. json_object *MeterValues = json_object_new_array();
  7515. json_object *sampledValues = json_object_new_array();
  7516. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7517. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7518. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7519. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7520. {
  7521. json_object *MeterValue = json_object_new_object();
  7522. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7523. {
  7524. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7525. {
  7526. json_object *sampledValue = json_object_new_object();
  7527. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7528. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7529. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7530. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7531. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7532. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7533. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7534. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7535. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7536. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7537. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7538. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7539. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7540. json_object_array_add(sampledValues, sampledValue);
  7541. }
  7542. }
  7543. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7544. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7545. json_object_array_add(MeterValues, MeterValue);
  7546. }
  7547. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7548. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7549. ,gun_index + 1
  7550. ,MESSAGE_TYPE_CALL
  7551. ,guid
  7552. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7553. json_object_put(MeterValueReq);
  7554. }
  7555. // Put request guid to hash map
  7556. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7557. 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*/)
  7558. {
  7559. result = PASS;
  7560. //DEBUG_INFO("MeterValues mapitem pass\n");
  7561. }
  7562. if((dataType != ReadingContext_Trigger) &&
  7563. (dataType != ReadingContext_Sample_Clock) &&
  7564. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7565. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7566. else
  7567. {
  7568. if(FirstHeartBeat)
  7569. LWS_Send(queuedata +2);
  7570. }
  7571. return result;
  7572. }
  7573. int sendLogStatusNotificationRequest(char *status)
  7574. {
  7575. mtrace();
  7576. int result = PASS;
  7577. char message[4096]={0};
  7578. char guid[37]={0};
  7579. char tempdata[128]={0};
  7580. json_object *LogStatusNotification = json_object_new_object();
  7581. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7582. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7583. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7584. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7585. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7586. random_uuid(guid);
  7587. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7588. json_object_put(LogStatusNotification);
  7589. LWS_Send(message);
  7590. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7591. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7592. {
  7593. result = PASS;
  7594. }
  7595. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7596. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7597. return result;
  7598. }
  7599. int sendSecurityEventNotificationRequest()
  7600. {
  7601. mtrace();
  7602. int result = PASS;
  7603. char message[4096]={0};
  7604. char guid[37]={0};
  7605. char tempdata[128]={0};
  7606. json_object *SecurityEventNotification = json_object_new_object();
  7607. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7608. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7609. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7610. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7611. random_uuid(guid);
  7612. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7613. json_object_put(SecurityEventNotification);
  7614. LWS_Send(message);
  7615. sprintf(tempdata, "SecurityEventNotification,0");
  7616. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7617. {
  7618. result = PASS;
  7619. }
  7620. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7621. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7622. return result;
  7623. }
  7624. int sendSignCertificateRequest()
  7625. {
  7626. mtrace();
  7627. int result = PASS;
  7628. char message[4096]={0};
  7629. char guid[37]={0};
  7630. char tempdata[128]={0};
  7631. json_object *SignCertificate = json_object_new_object();
  7632. DEBUG_INFO("sendSignCertificateRequest...\n");
  7633. // Read csr file content
  7634. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7635. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7636. char *line = NULL;
  7637. size_t len = 0;
  7638. while(getline(&line, &len, fp) != -1)
  7639. {
  7640. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7641. {
  7642. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7643. }
  7644. }
  7645. fclose(fp);
  7646. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7647. random_uuid(guid);
  7648. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7649. json_object_put(SignCertificate);
  7650. LWS_Send(message);
  7651. sprintf(tempdata, "SignCertificate,0");
  7652. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7653. {
  7654. result = PASS;
  7655. }
  7656. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7657. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7658. return result;
  7659. }
  7660. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7661. {
  7662. mtrace();
  7663. int result = PASS;
  7664. char message[110]={0};
  7665. char guid[37]={0};
  7666. char tempdata[65]={0};
  7667. json_object *FirmwareStatusNotification = json_object_new_object();
  7668. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7669. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7670. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7671. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7672. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7673. random_uuid(guid);
  7674. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7675. json_object_put(FirmwareStatusNotification);
  7676. LWS_Send(message);
  7677. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7678. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7679. {
  7680. result = PASS;
  7681. }
  7682. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7683. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7684. return result;
  7685. }
  7686. //==========================================
  7687. // send confirm routine
  7688. //==========================================
  7689. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7690. {
  7691. mtrace();
  7692. int result = FAIL;
  7693. char message[100]={0};
  7694. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7695. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7696. LWS_Send(message);
  7697. result = TRUE;
  7698. return result;
  7699. }
  7700. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7701. {
  7702. mtrace();
  7703. int result = FAIL;
  7704. char message[100]={0};
  7705. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7706. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7707. LWS_Send(message);
  7708. result = TRUE;
  7709. return result;
  7710. }
  7711. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7712. {
  7713. mtrace();
  7714. int result = FAIL;
  7715. char message[100]={0};
  7716. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7717. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7718. LWS_Send(message);
  7719. result = TRUE;
  7720. return result;
  7721. }
  7722. int sendClearCacheConfirmation(char *uuid,char *payload)
  7723. {
  7724. mtrace();
  7725. int result = FAIL;
  7726. char message[500]={0};
  7727. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7728. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7729. LWS_Send(message);
  7730. return result;
  7731. }
  7732. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char message[500]={0};
  7737. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7738. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7739. LWS_Send(message);
  7740. return result;
  7741. }
  7742. int sendDataTransferConfirmation(char *uuid,char *payload)
  7743. {
  7744. mtrace();
  7745. char statusStr[20]={0};
  7746. char dataStr[10]={0};
  7747. char sstr[20]={0};
  7748. int c = 0;
  7749. char *loc;
  7750. int result = FAIL;
  7751. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7752. /**********************status**************************/
  7753. loc = strstr(payload, "status");
  7754. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7755. c = 0;
  7756. while (loc[3+strlen("status")+c] != '\"')
  7757. {
  7758. sstr[c] = loc[3+strlen("status")+c];
  7759. c++;
  7760. }
  7761. sstr[c] = '\0';
  7762. strcpy(statusStr, sstr);
  7763. /**********************data**************************/
  7764. loc = strstr(payload, "data");
  7765. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7766. c = 0;
  7767. while (loc[3+strlen("data")+c] != '\"')
  7768. {
  7769. sstr[c] = loc[3+strlen("data")+c];
  7770. c++;
  7771. }
  7772. sstr[c] = '\0';
  7773. strcpy(dataStr, sstr);
  7774. return result;
  7775. }
  7776. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7777. {
  7778. mtrace();
  7779. int result = FAIL;
  7780. char message[1000]={0};
  7781. int CompositeScheduleIndex = 0;
  7782. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7783. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7784. if(nPeriod == 0)
  7785. {
  7786. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7787. {
  7788. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7789. ,MESSAGE_TYPE_CALLRESULT
  7790. ,uuid
  7791. ,payload
  7792. ,connectorIdInt);
  7793. }
  7794. else
  7795. {
  7796. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7797. ,MESSAGE_TYPE_CALLRESULT
  7798. ,uuid
  7799. ,payload
  7800. ,connectorIdInt
  7801. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7802. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7803. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7804. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7805. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7806. }
  7807. }
  7808. else
  7809. {
  7810. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7811. ,MESSAGE_TYPE_CALLRESULT
  7812. ,uuid
  7813. ,payload
  7814. ,connectorIdInt
  7815. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7816. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7817. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7818. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7819. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7820. {
  7821. if (idx_sample == 0)
  7822. {
  7823. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7824. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7825. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7826. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7827. }
  7828. else
  7829. {
  7830. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7831. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7832. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7833. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7834. }
  7835. }
  7836. sprintf(message + strlen(message), "]}}]");
  7837. }
  7838. LWS_Send(message);
  7839. result = TRUE;
  7840. return result;
  7841. }
  7842. int sendGetConfigurationConfirmation(char *uuid)
  7843. {
  7844. mtrace();
  7845. int result = FAIL;
  7846. int MaxKeySupported = 0;
  7847. int sentConfigurationNumber= 0;
  7848. int sentunConfigurationNumber= 0;
  7849. char message[1024*10]={0};
  7850. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7851. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7852. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7853. ,MESSAGE_TYPE_CALLRESULT
  7854. ,uuid );
  7855. //configuration key
  7856. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7857. {
  7858. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7859. {
  7860. if (sentConfigurationNumber == 0)
  7861. {
  7862. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7863. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7864. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7865. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7866. }
  7867. else
  7868. {
  7869. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7870. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7871. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7872. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7873. }
  7874. sentConfigurationNumber = sentConfigurationNumber + 1;
  7875. }
  7876. }
  7877. sprintf(message + strlen(message), "]");
  7878. if(UnknownKeynum != 0)
  7879. {
  7880. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7881. //unkown key
  7882. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7883. {
  7884. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7885. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7886. if(sentunConfigurationNumber == 0)
  7887. {
  7888. sprintf(message + strlen(message), "\"%s\""
  7889. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7890. }
  7891. else
  7892. {
  7893. sprintf(message + strlen(message), ",\"%s\""
  7894. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7895. }
  7896. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7897. }
  7898. sprintf(message + strlen(message), "]");
  7899. }
  7900. sprintf(message + strlen(message), "}]");
  7901. LWS_Send(message);
  7902. return result;
  7903. }
  7904. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7905. {
  7906. mtrace();
  7907. int result = FAIL;
  7908. char message[400]={0};
  7909. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7910. if(strcmp(payload,"")==0)
  7911. {
  7912. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7913. }
  7914. else
  7915. {
  7916. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7917. }
  7918. LWS_Send(message);
  7919. result = TRUE;
  7920. return result;
  7921. }
  7922. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7923. {
  7924. mtrace();
  7925. int result = FAIL;
  7926. char message[80]={0};
  7927. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7928. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7929. LWS_Send(message);
  7930. result = TRUE;
  7931. return result;
  7932. }
  7933. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7934. {
  7935. mtrace();
  7936. int result = FAIL;
  7937. char message[80]={0};
  7938. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7939. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7940. LWS_Send(message);
  7941. result = TRUE;
  7942. return result;
  7943. }
  7944. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7945. {
  7946. mtrace();
  7947. int result = FAIL;
  7948. char message[80]={0};
  7949. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7950. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7951. LWS_Send(message);
  7952. result = TRUE;
  7953. return result;
  7954. }
  7955. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7956. {
  7957. mtrace();
  7958. int result = FAIL;
  7959. char message[80]={0};
  7960. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7961. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7962. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7963. LWS_Send(message);
  7964. result = TRUE;
  7965. return result;
  7966. }
  7967. int sendResetConfirmation(char *uuid,char *payload)
  7968. {
  7969. mtrace();
  7970. int result = FAIL;
  7971. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7972. char message[80]={0};
  7973. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7974. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7975. LWS_Send(message);
  7976. result = TRUE;
  7977. return result;
  7978. }
  7979. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7980. {
  7981. mtrace();
  7982. int result = FAIL;
  7983. char message[500]={0};
  7984. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7985. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7986. LWS_Send(message);
  7987. result = TRUE;
  7988. return result;
  7989. }
  7990. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7991. {
  7992. mtrace();
  7993. int result = FAIL;
  7994. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7995. char message[80]={0};
  7996. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7998. LWS_Send(message);
  7999. result = TRUE;
  8000. return result;
  8001. }
  8002. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8003. {
  8004. mtrace();
  8005. int result = FAIL;
  8006. char message[80]={0};
  8007. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8008. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8009. LWS_Send(message);
  8010. result = TRUE;
  8011. return result;
  8012. }
  8013. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8014. {
  8015. mtrace();
  8016. int result = FAIL;
  8017. char message[80]={0};
  8018. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8019. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8020. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8021. LWS_Send(message);
  8022. result = TRUE;
  8023. return result;
  8024. }
  8025. int sendUpdateFirmwareConfirmation(char *uuid)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. char message[60]={0};
  8030. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8031. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8032. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8033. LWS_Send(message);
  8034. result = TRUE;
  8035. return result;
  8036. }
  8037. int sendCertificateSignedConfirmation(char *uuid)
  8038. {
  8039. mtrace();
  8040. int result = PASS;
  8041. char message[4096]={0};
  8042. json_object *CertificateSigned = json_object_new_object();
  8043. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8044. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8045. sprintf(message,"[%d,\"%s\",%s]"
  8046. ,MESSAGE_TYPE_CALLRESULT
  8047. ,uuid
  8048. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8049. json_object_put(CertificateSigned);
  8050. LWS_Send(message);
  8051. return result;
  8052. }
  8053. int sendDeleteCertificateConfirmation(char *uuid)
  8054. {
  8055. mtrace();
  8056. int result = PASS;
  8057. char message[4096]={0};
  8058. json_object *DeleteCertificate = json_object_new_object();
  8059. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8060. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8061. sprintf(message,"[%d,\"%s\",%s]"
  8062. ,MESSAGE_TYPE_CALLRESULT
  8063. ,uuid
  8064. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8065. json_object_put(DeleteCertificate);
  8066. LWS_Send(message);
  8067. return result;
  8068. }
  8069. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8070. {
  8071. mtrace();
  8072. int result = PASS;
  8073. char message[4096]={0};
  8074. json_object *ExtendedTriggerMessage = json_object_new_object();
  8075. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8076. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8077. sprintf(message,"[%d,\"%s\",%s]"
  8078. ,MESSAGE_TYPE_CALLRESULT
  8079. ,uuid
  8080. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8081. json_object_put(ExtendedTriggerMessage);
  8082. LWS_Send(message);
  8083. return result;
  8084. }
  8085. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8086. {
  8087. mtrace();
  8088. int result = PASS;
  8089. char message[4096]={0};
  8090. json_object *GetInstalledCertificateIds = json_object_new_object();
  8091. json_object *certificateHashDataDatas = json_object_new_array();
  8092. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8093. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8094. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8095. {
  8096. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8097. {
  8098. json_object *certificateHashData = json_object_new_object();
  8099. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8100. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8101. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8102. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8103. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8104. }
  8105. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8106. }
  8107. else
  8108. {
  8109. json_object_put(certificateHashDataDatas);
  8110. }
  8111. sprintf(message,"[%d,\"%s\",%s]"
  8112. ,MESSAGE_TYPE_CALLRESULT
  8113. ,uuid
  8114. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8115. json_object_put(GetInstalledCertificateIds);
  8116. LWS_Send(message);
  8117. return result;
  8118. }
  8119. int sendGetLogConfirmation(char *uuid)
  8120. {
  8121. mtrace();
  8122. int result = PASS;
  8123. char message[4096]={0};
  8124. json_object *GetLog = json_object_new_object();
  8125. DEBUG_INFO("sendGetLogConfirmation...\n");
  8126. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8127. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8128. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8129. sprintf(message,"[%d,\"%s\",%s]"
  8130. ,MESSAGE_TYPE_CALLRESULT
  8131. ,uuid
  8132. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8133. json_object_put(GetLog);
  8134. LWS_Send(message);
  8135. return result;
  8136. }
  8137. int sendInstallCertificateConfirmation(char *uuid)
  8138. {
  8139. mtrace();
  8140. int result = PASS;
  8141. char message[4096]={0};
  8142. json_object *InstallCertificate = json_object_new_object();
  8143. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8144. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8145. sprintf(message,"[%d,\"%s\",%s]"
  8146. ,MESSAGE_TYPE_CALLRESULT
  8147. ,uuid
  8148. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8149. json_object_put(InstallCertificate);
  8150. LWS_Send(message);
  8151. return result;
  8152. }
  8153. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8154. {
  8155. mtrace();
  8156. int result = PASS;
  8157. char message[4096]={0};
  8158. json_object *SignedUpdateFirmware = json_object_new_object();
  8159. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8160. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8161. sprintf(message,"[%d,\"%s\",%s]"
  8162. ,MESSAGE_TYPE_CALLRESULT
  8163. ,uuid
  8164. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8165. json_object_put(SignedUpdateFirmware);
  8166. LWS_Send(message);
  8167. return result;
  8168. }
  8169. int sendUnknownConfirmation(char *uuid)
  8170. {
  8171. mtrace();
  8172. int result = PASS;
  8173. char message[256]={0};
  8174. DEBUG_INFO("sendUnknownConfirmation...\n");
  8175. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8176. LWS_Send(message);
  8177. return result;
  8178. }
  8179. //==========================================
  8180. // Handle server request routine Start
  8181. //==========================================
  8182. int handleCancelReservationRequest(char *uuid, char *payload)
  8183. {
  8184. mtrace();
  8185. int result = FAIL;
  8186. int gunNO = 0;
  8187. int reservationIdInt = -1;
  8188. char comfirmstr[20];
  8189. DEBUG_INFO("handleCancelReservationRequest...\n");
  8190. json_object *CancelReservation;
  8191. CancelReservation = json_tokener_parse(payload);
  8192. if(!is_error(CancelReservation))
  8193. {
  8194. // Required data
  8195. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8196. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8197. }
  8198. json_object_put(CancelReservation);
  8199. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8200. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8201. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8202. if(reservationIdInt != -1)
  8203. {
  8204. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8205. //check Transaction active
  8206. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8208. {
  8209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8210. {
  8211. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8212. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8213. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8214. {
  8215. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8216. }
  8217. else
  8218. {
  8219. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8220. }
  8221. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8222. goto end;
  8223. }
  8224. }
  8225. for (int index = 0; index < CCS_QUANTITY; index++)
  8226. {
  8227. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8228. {
  8229. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8230. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8231. if(gunType[2] == GUN_TYPE_CCS)
  8232. {
  8233. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8234. }
  8235. else
  8236. {
  8237. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8238. }
  8239. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8240. goto end;
  8241. }
  8242. }
  8243. for (int index = 0; index < GB_QUANTITY; index++)
  8244. {
  8245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8246. {
  8247. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8248. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8249. if(gunType[2] == GUN_TYPE_GBT)
  8250. {
  8251. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8252. }
  8253. else
  8254. {
  8255. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8256. }
  8257. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8258. goto end;
  8259. }
  8260. }
  8261. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8262. {
  8263. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8264. {
  8265. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8266. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8267. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8268. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8269. goto end;
  8270. }
  8271. }
  8272. for (int index = 0; index < AC_QUANTITY; index++)
  8273. {
  8274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8275. {
  8276. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8277. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8279. {
  8280. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8281. }
  8282. else
  8283. {
  8284. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8285. }
  8286. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8287. goto end;
  8288. }
  8289. }
  8290. }
  8291. //The reservationId does NOT match the reservationId
  8292. sendCancelReservationConfirmation(uuid, comfirmstr);
  8293. end:
  8294. // Fill in ocpp packet uuid
  8295. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8296. return result;
  8297. }
  8298. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8299. {
  8300. mtrace();
  8301. int result = FAIL;
  8302. int gunIndex = -1;
  8303. char typeStr[16]={0};
  8304. char comfirmstr[20];
  8305. int specificId = FALSE;
  8306. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8307. json_object *ChangeAvailability;
  8308. ChangeAvailability = json_tokener_parse(payload);
  8309. if(!is_error(ChangeAvailability))
  8310. {
  8311. // Required data
  8312. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8313. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8314. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8315. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8316. }
  8317. json_object_put(ChangeAvailability);
  8318. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8319. {
  8320. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8321. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8322. }
  8323. else if(gunIndex == 0)
  8324. {
  8325. for(int i=0; i < gunTotalNumber; i++)
  8326. {
  8327. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8328. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8329. }
  8330. }
  8331. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8333. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8334. {
  8335. specificId = TRUE;
  8336. }
  8337. if(specificId == FALSE)
  8338. goto end;
  8339. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8340. {
  8341. //----------------------gunIndex is 0 ------------------------------------------------//
  8342. if(gunIndex == 0)
  8343. {
  8344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8345. {
  8346. for(int i=0; i < gunTotalNumber; i++)
  8347. {
  8348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8349. {
  8350. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8351. {
  8352. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8353. {
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8355. goto end;
  8356. }
  8357. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8358. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8359. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8360. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8361. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8362. {
  8363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8364. goto end;
  8365. }
  8366. }
  8367. }//END FOR CHAdeMO_QUANTITY
  8368. for (int index = 0; index < CCS_QUANTITY; index++)
  8369. {
  8370. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8371. {
  8372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8373. {
  8374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8375. goto end;
  8376. }
  8377. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8379. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8380. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8381. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8382. {
  8383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8384. goto end;
  8385. }
  8386. }
  8387. }//END FOR CCS_QUANTITY
  8388. for (int index = 0; index < GB_QUANTITY; index++)
  8389. {
  8390. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8391. {
  8392. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8393. {
  8394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8395. goto end;
  8396. }
  8397. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8398. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8399. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8400. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8401. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8402. {
  8403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8404. goto end;
  8405. }
  8406. }
  8407. }// END FOR GB_QUANTITY
  8408. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8409. {
  8410. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8411. {
  8412. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8413. {
  8414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8415. goto end;
  8416. }
  8417. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8418. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8419. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8420. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8421. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8422. {
  8423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8424. goto end;
  8425. }
  8426. }
  8427. }// END FOR GENERAL_GUN_QUANTITY
  8428. for (int index = 0; index < AC_QUANTITY; index++)
  8429. {
  8430. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8431. {
  8432. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8433. {
  8434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8435. goto end;
  8436. }
  8437. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8439. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8440. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8441. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8442. {
  8443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8444. goto end;
  8445. }
  8446. }
  8447. }//END FOR AC_QUANTITY
  8448. }// END FOR gunTotalNumber
  8449. }
  8450. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8451. {
  8452. for(int i=0; i < gunTotalNumber; i++)
  8453. {
  8454. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8455. {
  8456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8457. goto end;
  8458. }
  8459. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8460. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8461. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8462. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8463. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8464. {
  8465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8466. goto end;
  8467. }
  8468. }
  8469. }
  8470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8471. goto end;
  8472. }
  8473. //----------------------gunIndex is not 0 ------------------------------------------------//
  8474. //check Transaction active
  8475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8476. {
  8477. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8478. {
  8479. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8480. {
  8481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8482. goto end;
  8483. }
  8484. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8486. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8487. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8488. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8489. {
  8490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8491. goto end;
  8492. }
  8493. else
  8494. {
  8495. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8497. goto end;
  8498. }
  8499. }
  8500. }//END FOR CHAdeMO_QUANTITY
  8501. for (int index = 0; index < CCS_QUANTITY; index++)
  8502. {
  8503. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8504. {
  8505. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8506. {
  8507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8508. goto end;
  8509. }
  8510. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8511. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8512. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8513. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8514. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8515. {
  8516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8517. goto end;
  8518. }
  8519. else
  8520. {
  8521. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8523. goto end;
  8524. }
  8525. }
  8526. }//END FOR CCS_QUANTITY
  8527. for (int index = 0; index < GB_QUANTITY; index++)
  8528. {
  8529. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8530. {
  8531. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8532. {
  8533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8534. goto end;
  8535. }
  8536. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8537. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8538. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8539. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8540. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8541. {
  8542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8543. goto end;
  8544. }
  8545. else
  8546. {
  8547. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8549. goto end;
  8550. }
  8551. }
  8552. }// END FOR GB_QUANTITY
  8553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8554. {
  8555. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8556. {
  8557. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8558. {
  8559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8560. goto end;
  8561. }
  8562. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8563. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8564. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8565. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8566. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8567. {
  8568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8569. goto end;
  8570. }
  8571. else
  8572. {
  8573. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8575. goto end;
  8576. }
  8577. }
  8578. }// END FOR GENERAL_GUN_QUANTITY
  8579. for (int index = 0; index < AC_QUANTITY; index++)
  8580. {
  8581. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8582. {
  8583. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8584. {
  8585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8586. goto end;
  8587. }
  8588. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8590. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8591. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8592. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8593. {
  8594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8595. goto end;
  8596. }
  8597. else
  8598. {
  8599. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8601. goto end;
  8602. }
  8603. }
  8604. }//END FOR AC_QUANTITY
  8605. }//END FOR AvailabilityTypeStr[Inoperative]
  8606. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8607. {
  8608. //----------------------gunIndex is 0 ------------------------------------------------//
  8609. if(gunIndex == 0)
  8610. {
  8611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8612. {
  8613. for(int i=0; i < gunTotalNumber; i++)
  8614. {
  8615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8616. {
  8617. 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
  8618. {
  8619. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8620. goto end;
  8621. }
  8622. }//END FOR CHAdeMO_QUANTITY
  8623. for (int index = 0; index < CCS_QUANTITY; index++)
  8624. {
  8625. 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
  8626. {
  8627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8628. goto end;
  8629. }
  8630. }//END FOR CCS_QUANTITY
  8631. for (int index = 0; index < GB_QUANTITY; index++)
  8632. {
  8633. 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
  8634. {
  8635. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8637. goto end;
  8638. }
  8639. }// END FOR GB_QUANTITY
  8640. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8641. {
  8642. 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
  8643. {
  8644. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8646. goto end;
  8647. }
  8648. }// END FOR GENERAL_GUN_QUANTITY
  8649. for (int index = 0; index < AC_QUANTITY; index++)
  8650. {
  8651. 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
  8652. {
  8653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8654. goto end;
  8655. }
  8656. }//END FOR CHAdeMO_QUANTITY
  8657. }// END FOR gunTotalNumber
  8658. }
  8659. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8660. {
  8661. for(int i=0; i < gunTotalNumber; i++)
  8662. {
  8663. for (int index = 0; index < AC_QUANTITY; index++)
  8664. {
  8665. 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
  8666. {
  8667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8668. goto end;
  8669. }
  8670. }//END FOR CHAdeMO_QUANTITY
  8671. } // END FOR gunTotalNumber
  8672. }
  8673. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8674. goto end;
  8675. }
  8676. //----------------------gunIndex is not 0 ------------------------------------------------//
  8677. //check Transaction active
  8678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8679. {
  8680. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8681. {
  8682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8683. goto end;
  8684. }
  8685. }//END FOR CHAdeMO_QUANTITY
  8686. for (int index = 0; index < CCS_QUANTITY; index++)
  8687. {
  8688. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8689. {
  8690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8691. goto end;
  8692. }
  8693. }//END FOR CCS_QUANTITY
  8694. for (int index = 0; index < GB_QUANTITY; index++)
  8695. {
  8696. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8699. goto end;
  8700. }
  8701. }// END FOR GB_QUANTITY
  8702. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8703. {
  8704. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8705. {
  8706. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8707. goto end;
  8708. }
  8709. }// END FOR GENERAL_GUN_QUANTITY
  8710. for (int index = 0; index < AC_QUANTITY; index++)
  8711. {
  8712. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8713. {
  8714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8715. goto end;
  8716. }
  8717. }//END FOR AC_QUANTITY
  8718. }//END FOR AvailabilityTypeStr[Operative]
  8719. end:
  8720. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8721. {
  8722. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8723. }
  8724. else
  8725. {
  8726. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8727. }
  8728. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8729. {
  8730. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8731. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8732. }
  8733. else if(gunIndex == 0)
  8734. {
  8735. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8736. {
  8737. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8738. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8739. }
  8740. }
  8741. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8742. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8743. return result;
  8744. }
  8745. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8746. {
  8747. mtrace();
  8748. int valueInvalid = NO;
  8749. int result = FAIL;
  8750. char keystr[40]={0};
  8751. char valuestr[501]={0}; //value should be limited in 500 bytes
  8752. char comfirmstr[20]={0};
  8753. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8754. json_object *ChangeConfiguration;
  8755. ChangeConfiguration = json_tokener_parse(payload);
  8756. if(!is_error(ChangeConfiguration))
  8757. {
  8758. // Required data
  8759. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8760. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8761. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8762. {
  8763. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8764. }
  8765. else
  8766. {
  8767. valueInvalid = YES;
  8768. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8769. }
  8770. }
  8771. json_object_put(ChangeConfiguration);
  8772. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8773. {
  8774. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8775. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8776. }
  8777. else
  8778. {
  8779. int status = setKeyValue(keystr, valuestr);
  8780. switch(status)
  8781. {
  8782. case ConfigurationStatus_Accepted:
  8783. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8784. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8785. StoreConfigurationTable();
  8786. break;
  8787. case RebootRequired:
  8788. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8789. StoreConfigurationTable();
  8790. break;
  8791. case NotSupported:
  8792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8793. break;
  8794. case ConfigurationStatus_Rejected:
  8795. default:
  8796. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8797. break;
  8798. }
  8799. }
  8800. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8801. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8802. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8803. {
  8804. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8805. SetOcppConnStatus(FALSE);
  8806. }
  8807. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8808. {
  8809. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8810. }
  8811. return result;
  8812. }
  8813. int handleClearCacheRequest(char *uuid, char *payload)
  8814. {
  8815. mtrace();
  8816. int result = FAIL;
  8817. char comfirmstr[20];
  8818. char rmFileCmd[100]={0};
  8819. struct stat stats;
  8820. DEBUG_INFO("handleClearCacheRequest...\n");
  8821. stat("/Storage/OCPP", &stats);
  8822. // Check for directory existence
  8823. if (S_ISDIR(stats.st_mode) == 1)
  8824. {}
  8825. else
  8826. {
  8827. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8828. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8829. system(rmFileCmd);
  8830. }
  8831. if(OCPP_cleanLocalCache())
  8832. {
  8833. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8834. }
  8835. else
  8836. {
  8837. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8838. }
  8839. sendClearCacheConfirmation(uuid, comfirmstr);
  8840. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8841. return result;
  8842. }
  8843. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8844. {
  8845. mtrace();
  8846. int result = FAIL;
  8847. int resultRename;
  8848. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8849. char chargingProfilePurposeStr[26]={0};
  8850. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8851. char tempchargingProfilePurposeStr[26]={0};
  8852. char str[100]={0};
  8853. char fname[200]={0};
  8854. char comfirmstr[20]={0};
  8855. char word[1600]={0};
  8856. int clearflag = FALSE;
  8857. int chargingProfileIdIsNULL = FALSE;
  8858. int connectorIsNULL = FALSE;
  8859. int chargingProfilePurposeIsNULL = FALSE;
  8860. int stackLevelIsNULL = FALSE;
  8861. //int GotoEnd = FALSE;
  8862. FILE *fptr1, *fptr2;
  8863. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8864. int n_chargingProfile=0;
  8865. int isEmptyFile = FALSE;
  8866. char sLineWord[1600]={0};
  8867. char chargingProfiles[10][100]={0};
  8868. int ChargeProfileCount = 0;
  8869. int ch;
  8870. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8871. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8872. json_object *ClearChargingProfile;
  8873. ClearChargingProfile = json_tokener_parse(payload);
  8874. if(!is_error(ClearChargingProfile))
  8875. {
  8876. // Optional data
  8877. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8878. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8879. else
  8880. chargingProfileIdIsNULL = TRUE;
  8881. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8882. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8883. else
  8884. connectorIsNULL = TRUE;
  8885. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8886. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8887. else
  8888. chargingProfilePurposeIsNULL = TRUE;
  8889. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8890. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8891. else
  8892. stackLevelIsNULL = TRUE;
  8893. }
  8894. json_object_put(ClearChargingProfile);
  8895. if(connectorIsNULL == FALSE)
  8896. {
  8897. switch(connectorIdInt)
  8898. {
  8899. case 0:
  8900. if(chargingProfilePurposeIsNULL == TRUE)
  8901. {
  8902. int l = 0;
  8903. strcpy(fname, ChargePointMaxProfile_JSON);
  8904. if((access(fname,F_OK))!=-1)
  8905. {
  8906. strcpy(chargingProfiles[l], fname);
  8907. l = l + 1;
  8908. }
  8909. strcpy(fname, TxDefaultProfile_0_JSON);
  8910. if((access(fname,F_OK))!=-1)
  8911. {
  8912. strcpy(chargingProfiles[l], fname);
  8913. l = l + 1;
  8914. }
  8915. ChargeProfileCount = l;
  8916. }
  8917. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8918. {
  8919. strcpy(fname, ChargePointMaxProfile_JSON);
  8920. if((access(fname,F_OK))!=-1)
  8921. {
  8922. strcpy(chargingProfiles[0], fname);
  8923. ChargeProfileCount = 1;
  8924. }
  8925. }
  8926. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8927. {
  8928. strcpy(fname, TxDefaultProfile_0_JSON);
  8929. if((access(fname,F_OK))!=-1)
  8930. {
  8931. strcpy(chargingProfiles[0], fname);
  8932. ChargeProfileCount = 1;
  8933. }
  8934. }
  8935. break;
  8936. default:
  8937. if(chargingProfilePurposeIsNULL == TRUE)
  8938. {
  8939. int m = 0;
  8940. memset(fname, 0, ARRAY_SIZE(fname));
  8941. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8942. if((access(fname,F_OK))!=-1)
  8943. {
  8944. strcpy(chargingProfiles[m], fname);
  8945. m = m + 1;
  8946. }
  8947. memset(fname, 0, ARRAY_SIZE(fname));
  8948. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8949. if((access(fname,F_OK))!=-1)
  8950. {
  8951. strcpy(chargingProfiles[m], fname);
  8952. m = m + 1;
  8953. }
  8954. ChargeProfileCount = m;
  8955. }
  8956. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8957. {
  8958. //strcpy(fname, TxDefaultProfile_1_JSON);
  8959. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8960. if((access(fname,F_OK))!=-1)
  8961. {
  8962. strcpy(chargingProfiles[0], fname);
  8963. ChargeProfileCount = 1;
  8964. }
  8965. }
  8966. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8967. {
  8968. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8969. if((access(fname,F_OK))!=-1)
  8970. {
  8971. strcpy(chargingProfiles[0], fname);
  8972. ChargeProfileCount = 1;
  8973. }
  8974. //strcpy(fname, TxProfile_1_JSON);
  8975. }
  8976. //strcpy(fname, ChargePointMaxProfile_JSON );
  8977. break;
  8978. }
  8979. }
  8980. else // Check all Charging Profiles
  8981. {
  8982. int i = 0;
  8983. char fnametemp[200]={0};
  8984. ChargeProfileCount = 0;
  8985. //Check ChargePointMaxProfile.json exit
  8986. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8987. {
  8988. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8989. i = i + 1;
  8990. }
  8991. //Check TxDefaultProfile_0.json exit
  8992. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8993. {
  8994. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8995. i = i + 1;
  8996. }
  8997. //Check TxDefaultProfile_%d.json
  8998. for(int j=1; j <= gunTotalNumber; j++)
  8999. {
  9000. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9001. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9002. if((access(fnametemp,F_OK))!=-1)
  9003. {
  9004. strcpy(chargingProfiles[i], fnametemp);
  9005. i = i + 1;
  9006. }
  9007. }
  9008. //Check TxProfile_%d.json
  9009. for(int j=1; j <= gunTotalNumber; j++)
  9010. {
  9011. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9012. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9013. if((access(fnametemp,F_OK))!=-1)
  9014. {
  9015. strcpy(chargingProfiles[i], fnametemp);
  9016. i = i + 1;
  9017. }
  9018. }
  9019. ChargeProfileCount = i;
  9020. }// End connectorIsNULL is TRUE
  9021. if(ChargeProfileCount == 0)
  9022. {
  9023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9024. goto end;
  9025. }
  9026. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9027. {
  9028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9029. goto end;
  9030. }
  9031. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9032. {
  9033. memset(str, 0, ARRAY_SIZE(str));
  9034. // clear temp file
  9035. sprintf(str,"rm -f %s",temp);
  9036. system(str);
  9037. for(int k=0; k < ChargeProfileCount; k++)
  9038. {
  9039. memset(str, 0, ARRAY_SIZE(str));
  9040. //clear file in C
  9041. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9042. system(str);
  9043. }
  9044. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9045. goto end;
  9046. }
  9047. else if(connectorIsNULL == TRUE)
  9048. {
  9049. for(int k=0; k < ChargeProfileCount; k++)
  9050. {
  9051. fptr1 = fopen(chargingProfiles[k], "r");
  9052. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9053. //Check Charging Profile Count
  9054. while(fscanf(fptr1, "%s", word) != EOF)
  9055. {
  9056. //DEBUG_INFO("word=%s\n",word);
  9057. if(strstr(word, "chargingProfileId")!= NULL)
  9058. {
  9059. //DEBUG_INFO("test chargingProfileId \n");
  9060. n_chargingProfile = n_chargingProfile + 1;
  9061. //DEBUG_INFO("chargingProfileId Found\n");
  9062. }
  9063. }
  9064. rewind(fptr1);
  9065. //search Charging Profile Element
  9066. //int i= 0;
  9067. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9068. {
  9069. json_object *tmpProfilee;
  9070. tmpProfilee = json_tokener_parse(sLineWord);
  9071. if(!is_error(tmpProfilee))
  9072. {
  9073. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9074. {
  9075. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9076. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9077. }
  9078. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9079. {
  9080. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9081. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9082. }
  9083. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9084. {
  9085. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9086. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9087. }
  9088. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9089. {
  9090. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9091. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9092. }
  9093. }
  9094. json_object_put(tmpProfilee);
  9095. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9096. {
  9097. //------- not write to fptr2-------//
  9098. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9099. //clearflag = TRUE;
  9100. }
  9101. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9102. {
  9103. //------- not write to fptr2-------//
  9104. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9105. }
  9106. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9107. {
  9108. //------- not write to fptr2-------//
  9109. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9110. }
  9111. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9112. {
  9113. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9114. }
  9115. else
  9116. {
  9117. fprintf(fptr2, sLineWord);//writing data into file
  9118. }
  9119. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9120. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9121. if(clearflag == TRUE)
  9122. {
  9123. fclose(fptr1);
  9124. fclose(fptr2);
  9125. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9126. system(str);
  9127. // clear temp file
  9128. sprintf(str,"rm -f %s",temp);
  9129. system(str);
  9130. }
  9131. else
  9132. {
  9133. fclose(fptr1);
  9134. fclose(fptr2);
  9135. memset(str, 0, ARRAY_SIZE(str));
  9136. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9137. system(str);
  9138. resultRename = rename(temp, chargingProfiles[k]);
  9139. if(resultRename == 0)
  9140. {
  9141. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9142. }
  9143. else
  9144. {
  9145. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9146. }
  9147. if(comfirmstr[0]== 0)
  9148. {
  9149. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9150. }
  9151. //Check chargingProfile is empty file
  9152. /*------ Read the file ----------------*/
  9153. fptr1=fopen(chargingProfiles[k],"r");
  9154. ch=fgetc(fptr1);
  9155. rewind(fptr1);
  9156. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9157. if(ch!=EOF)
  9158. {
  9159. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9160. {
  9161. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9162. if(sLineWord[0]=='\0')
  9163. {
  9164. isEmptyFile = TRUE;
  9165. break;
  9166. }
  9167. else
  9168. {
  9169. isEmptyFile = FALSE;
  9170. break;
  9171. }
  9172. }
  9173. }
  9174. else
  9175. isEmptyFile = TRUE;
  9176. fclose(fptr1);
  9177. if(isEmptyFile == TRUE)
  9178. {
  9179. memset(str, 0, ARRAY_SIZE(str));
  9180. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9181. system(str);
  9182. }
  9183. }
  9184. }// End of while(int k=0; k < ChargePointCount; k++)
  9185. }
  9186. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9187. {
  9188. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9189. for(int k=0; k < ChargeProfileCount; k++)
  9190. {
  9191. fptr1 = fopen(chargingProfiles[k], "r");
  9192. fptr2 = fopen(temp, "w+");
  9193. //Check Charging Profile Count
  9194. while(fscanf(fptr1, "%s", word) != EOF)
  9195. {
  9196. //DEBUG_INFO("word=%s\n",word);
  9197. if(strstr(word, "chargingProfileId")!= NULL)
  9198. {
  9199. n_chargingProfile = n_chargingProfile + 1;
  9200. }
  9201. }
  9202. rewind(fptr1);
  9203. //search Charging Profile Element
  9204. //int i= 0;
  9205. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9206. {
  9207. json_object *tmpProfilee;
  9208. tmpProfilee = json_tokener_parse(sLineWord);
  9209. if(!is_error(tmpProfilee))
  9210. {
  9211. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9212. {
  9213. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9214. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9215. }
  9216. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9217. {
  9218. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9219. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9220. }
  9221. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9222. {
  9223. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9224. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9225. }
  9226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9227. {
  9228. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9229. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9230. }
  9231. }
  9232. json_object_put(tmpProfilee);
  9233. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9234. {
  9235. //------- not write to fptr2-------//
  9236. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9237. //clearflag = TRUE;
  9238. }
  9239. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9240. {
  9241. //------- not write to fptr2-------//
  9242. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9243. }
  9244. else if(stackLevelIsNULL == TRUE)
  9245. {
  9246. //Clear Whole File
  9247. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9248. clearflag = TRUE;
  9249. break;
  9250. }
  9251. else
  9252. {
  9253. fprintf(fptr2, sLineWord);//writing data into file
  9254. }
  9255. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9256. }
  9257. if(clearflag == TRUE)
  9258. {
  9259. fclose(fptr1);
  9260. fclose(fptr2);
  9261. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9262. system(str);
  9263. // clear temp file
  9264. sprintf(str,"rm -f %s",temp);
  9265. system(str);
  9266. }
  9267. else
  9268. {
  9269. fclose(fptr1);
  9270. fclose(fptr2);
  9271. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9272. system(str);
  9273. resultRename = rename(temp, chargingProfiles[k]);
  9274. if(resultRename == 0)
  9275. {
  9276. DEBUG_INFO("File ChargingProfile renamed successfully");
  9277. }
  9278. else
  9279. {
  9280. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9281. }
  9282. if(comfirmstr[0]== 0)
  9283. {
  9284. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9285. }
  9286. //Check chargingProfile is empty file
  9287. /*------ Read the file ----------------*/
  9288. fptr1=fopen(chargingProfiles[k],"r");
  9289. ch=fgetc(fptr1);
  9290. rewind(fptr1);
  9291. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9292. if(ch!=EOF)
  9293. {
  9294. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9295. {
  9296. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9297. if(sLineWord[0]=='\0')
  9298. {
  9299. isEmptyFile = TRUE;
  9300. break;
  9301. }
  9302. else
  9303. {
  9304. isEmptyFile = FALSE;
  9305. break;
  9306. }
  9307. }
  9308. }
  9309. else
  9310. isEmptyFile = TRUE;
  9311. fclose(fptr1);
  9312. if(isEmptyFile == TRUE)
  9313. {
  9314. memset(str, 0, ARRAY_SIZE(str));
  9315. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9316. system(str);
  9317. }
  9318. /*------- End of reading ---------------*/
  9319. }
  9320. } // while(int k=0; k < ChargeProfileCount; k++)
  9321. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9322. end:
  9323. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9324. {
  9325. if(connectorIdInt == 0)
  9326. {
  9327. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9328. {
  9329. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9330. }
  9331. }
  9332. else
  9333. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9334. }
  9335. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9336. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9337. return result;
  9338. }
  9339. void createFirmwareVersionByDataTransfer(void)
  9340. {
  9341. json_object *FirmwareDataTransfer = json_object_new_object();
  9342. // AC & DC model
  9343. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9344. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9345. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9346. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9347. // DC model
  9348. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9349. {
  9350. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9351. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9352. (gunType[3] != GUN_TYPE_UNKNOWN))
  9353. {
  9354. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9355. }
  9356. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9357. {
  9358. // DS DM DW
  9359. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9360. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9361. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9362. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9363. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9364. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9365. }
  9366. else
  9367. {
  9368. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9369. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9370. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9371. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9372. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9373. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9374. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9375. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9376. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9377. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9378. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9379. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9380. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9381. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9382. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9383. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9384. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9385. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9386. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9388. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9389. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9390. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9391. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9392. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9393. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9394. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9395. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9396. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9397. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9398. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9399. }
  9400. }
  9401. // 4G model
  9402. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9403. {
  9404. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9405. }
  9406. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9407. json_object_put(FirmwareDataTransfer);
  9408. }
  9409. int handleDataTransferRequest(char *uuid, char *payload)
  9410. {
  9411. mtrace();
  9412. json_object *response = json_object_new_object();
  9413. int result = FAIL;
  9414. char tempvendorId[255]={0};
  9415. char tempmessageId[50]={0};
  9416. char tempdata[1024]={0};
  9417. char message[2048]={0};
  9418. DEBUG_INFO("handleDataTransferRequest...\n");
  9419. if((uuid != NULL) && (payload != NULL))
  9420. {
  9421. json_object *DataTransfer;
  9422. DataTransfer = json_tokener_parse(payload);
  9423. if(!is_error(DataTransfer))
  9424. {
  9425. // Required data
  9426. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9427. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9428. // Optional data
  9429. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9430. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9431. if(json_object_object_get(DataTransfer, "data") != NULL)
  9432. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9433. result = PASS;
  9434. }
  9435. json_object_put(DataTransfer);
  9436. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9437. {
  9438. // Send all moudle firmware version on EVSE
  9439. createFirmwareVersionByDataTransfer();
  9440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9441. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9442. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9443. json_object_put(response);
  9444. }
  9445. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9446. {
  9447. system("/usr/bin/run_tmate_restart.sh &");
  9448. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9449. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9450. json_object_put(response);
  9451. }
  9452. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9453. {
  9454. json_object *data;
  9455. data = json_tokener_parse(tempdata);
  9456. if(!is_error(data))
  9457. {
  9458. 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))
  9459. {
  9460. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9461. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9462. if(json_object_object_get(data, "SOC") != NULL)
  9463. {
  9464. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9465. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9466. }
  9467. if(json_object_object_get(data, "Energy") != NULL)
  9468. {
  9469. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9470. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9471. }
  9472. if(json_object_object_get(data, "Duration") != NULL)
  9473. {
  9474. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9475. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9476. }
  9477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9478. }
  9479. else
  9480. {
  9481. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9482. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9483. }
  9484. }
  9485. else
  9486. {
  9487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9488. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9489. }
  9490. json_object_put(data);
  9491. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9492. json_object_put(response);
  9493. }
  9494. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9495. {
  9496. json_object *data;
  9497. data = json_tokener_parse(tempdata);
  9498. if(!is_error(data))
  9499. {
  9500. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9501. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9502. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9503. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9504. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9505. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9506. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9507. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9508. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9509. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9510. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9511. }
  9512. else
  9513. {
  9514. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9515. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9516. }
  9517. json_object_put(data);
  9518. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9519. json_object_put(response);
  9520. }
  9521. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9522. {
  9523. json_object *data;
  9524. data = json_tokener_parse(tempdata);
  9525. if(!is_error(data))
  9526. {
  9527. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9528. if(json_object_object_get(data, "idToken") != NULL)
  9529. {
  9530. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9531. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9532. }
  9533. if(json_object_object_get(data, "price") != NULL)
  9534. {
  9535. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9536. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9537. }
  9538. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9539. }
  9540. else
  9541. {
  9542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9543. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9544. }
  9545. json_object_put(data);
  9546. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9547. json_object_put(response);
  9548. }
  9549. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9550. {
  9551. json_object *data;
  9552. data = json_tokener_parse(tempdata);
  9553. if(!is_error(data))
  9554. {
  9555. if(json_object_object_get(data, "txId") != NULL)
  9556. {
  9557. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9558. for(int idx = 0;idx<gunTotalNumber;idx++)
  9559. {
  9560. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9561. {
  9562. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9563. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9564. if(json_object_object_get(data, "description") != NULL)
  9565. {
  9566. // California pricing V1.0
  9567. DEBUG_INFO("California pricing V1.0\n");
  9568. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9569. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9570. }
  9571. else
  9572. {
  9573. // California pricing V1.1
  9574. DEBUG_INFO("California pricing V1.1\n");
  9575. if(json_object_object_get(data, "timestamp") != NULL)
  9576. {
  9577. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9578. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9579. }
  9580. if(json_object_object_get(data, "meterValue") != NULL)
  9581. {
  9582. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9583. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9584. }
  9585. if(json_object_object_get(data, "cost") != NULL)
  9586. {
  9587. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9588. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9589. }
  9590. if(json_object_object_get(data, "state") != NULL)
  9591. {
  9592. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9593. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9594. }
  9595. if(json_object_object_get(data, "chargingPrice") != NULL)
  9596. {
  9597. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9598. {
  9599. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9600. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9601. }
  9602. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9603. {
  9604. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9605. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9606. }
  9607. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9608. {
  9609. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9610. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9611. }
  9612. }
  9613. if(json_object_object_get(data, "idlePrice") != NULL)
  9614. {
  9615. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9616. {
  9617. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9618. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9619. }
  9620. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9621. {
  9622. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9623. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9624. }
  9625. }
  9626. if(json_object_object_get(data, "nextPeriod") != NULL)
  9627. {
  9628. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9629. {
  9630. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9631. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9632. }
  9633. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9634. {
  9635. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9636. {
  9637. 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")));
  9638. 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"));
  9639. }
  9640. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9641. {
  9642. 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")));
  9643. 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"));
  9644. }
  9645. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9646. {
  9647. 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")));
  9648. 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"));
  9649. }
  9650. }
  9651. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9652. {
  9653. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9654. {
  9655. 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")));
  9656. 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"));
  9657. }
  9658. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9659. {
  9660. 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")));
  9661. 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"));
  9662. }
  9663. }
  9664. }
  9665. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9666. {
  9667. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9668. {
  9669. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9670. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9671. }
  9672. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9673. {
  9674. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9675. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9676. }
  9677. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9678. {
  9679. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9680. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9681. }
  9682. }
  9683. }
  9684. }
  9685. }
  9686. }
  9687. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9688. }
  9689. else
  9690. {
  9691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9692. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9693. }
  9694. json_object_put(data);
  9695. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9696. json_object_put(response);
  9697. }
  9698. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9699. {
  9700. json_object *data;
  9701. data = json_tokener_parse(tempdata);
  9702. if(!is_error(data))
  9703. {
  9704. if(json_object_object_get(data, "txId") != NULL)
  9705. {
  9706. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9707. for(int idx = 0;idx<gunTotalNumber;idx++)
  9708. {
  9709. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9710. {
  9711. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9712. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9713. if(json_object_object_get(data, "description") != NULL)
  9714. {
  9715. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9716. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9717. }
  9718. }
  9719. }
  9720. }
  9721. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9722. }
  9723. else
  9724. {
  9725. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9726. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9727. }
  9728. json_object_put(data);
  9729. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9730. json_object_put(response);
  9731. }
  9732. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9733. {
  9734. json_object *data;
  9735. data = json_tokener_parse(tempdata);
  9736. if(!is_error(data))
  9737. {
  9738. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9739. if(json_object_object_get(data, "Content_Type") != NULL)
  9740. {
  9741. 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))
  9742. {
  9743. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9744. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9745. {
  9746. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9747. }
  9748. }
  9749. else
  9750. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9751. }
  9752. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9753. }
  9754. else
  9755. {
  9756. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9757. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9758. }
  9759. json_object_put(data);
  9760. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9761. json_object_put(response);
  9762. }
  9763. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9764. {
  9765. json_object *data;
  9766. data = json_tokener_parse(tempdata);
  9767. if(!is_error(data))
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9770. if(json_object_object_get(data, "ConnectorId") != NULL)
  9771. {
  9772. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9773. }
  9774. if(json_object_object_get(data, "SerialNo") != NULL)
  9775. {
  9776. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9777. }
  9778. if(json_object_object_get(data, "Page_Index") != NULL)
  9779. {
  9780. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9781. }
  9782. if(json_object_object_get(data, "Duration") != NULL)
  9783. {
  9784. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9785. }
  9786. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9787. }
  9788. else
  9789. {
  9790. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9791. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9792. }
  9793. json_object_put(data);
  9794. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9795. json_object_put(response);
  9796. }
  9797. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9798. {
  9799. json_object *data;
  9800. data = json_tokener_parse(tempdata);
  9801. if(!is_error(data))
  9802. {
  9803. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9804. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9805. {
  9806. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9807. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9808. else
  9809. {
  9810. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9811. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9812. }
  9813. }
  9814. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9815. {
  9816. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9817. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9818. else
  9819. {
  9820. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9821. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9822. }
  9823. }
  9824. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9825. {
  9826. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9827. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9828. else
  9829. {
  9830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9831. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9832. }
  9833. }
  9834. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9835. {
  9836. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9837. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9842. }
  9843. }
  9844. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9845. {
  9846. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9847. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9848. else
  9849. {
  9850. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9851. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9852. }
  9853. }
  9854. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9855. {
  9856. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9857. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9858. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9859. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9860. else
  9861. {
  9862. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9863. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9864. }
  9865. }
  9866. if(json_object_object_get(data, "isAuthentication") != NULL)
  9867. {
  9868. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9869. {
  9870. case 0:
  9871. case 1:
  9872. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9873. break;
  9874. default:
  9875. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9876. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9877. break;
  9878. }
  9879. }
  9880. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9881. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9882. }
  9883. else
  9884. {
  9885. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9886. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9887. }
  9888. json_object_put(data);
  9889. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9890. json_object_put(response);
  9891. }
  9892. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9893. {
  9894. json_object *data;
  9895. data = json_tokener_parse(tempdata);
  9896. if(!is_error(data))
  9897. {
  9898. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9899. {
  9900. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9901. {
  9902. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9903. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9904. }
  9905. else
  9906. {
  9907. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9908. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9909. }
  9910. }
  9911. else
  9912. {
  9913. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9914. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9915. }
  9916. }
  9917. else
  9918. {
  9919. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9920. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9921. }
  9922. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9923. json_object_put(response);
  9924. }
  9925. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9926. {
  9927. json_object *data;
  9928. data = json_tokener_parse(tempdata);
  9929. if(!is_error(data))
  9930. {
  9931. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9932. if(json_object_object_get(data, "stationName") != NULL)
  9933. {
  9934. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9935. }
  9936. else
  9937. {
  9938. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9939. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9940. }
  9941. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9942. {
  9943. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9944. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9945. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9946. }
  9947. }
  9948. else
  9949. {
  9950. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9951. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9952. }
  9953. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9954. json_object_put(response);
  9955. }
  9956. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9957. {
  9958. json_object *data;
  9959. data = json_tokener_parse(tempdata);
  9960. if(!is_error(data))
  9961. {
  9962. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9963. if(json_object_object_get(data, "weatherId") != NULL)
  9964. {
  9965. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9966. }
  9967. else
  9968. {
  9969. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9970. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9971. }
  9972. if(json_object_object_get(data, "Temperature") != NULL)
  9973. {
  9974. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9975. }
  9976. else
  9977. {
  9978. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9979. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9980. }
  9981. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9982. {
  9983. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9984. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9985. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9986. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9987. );
  9988. }
  9989. }
  9990. else
  9991. {
  9992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9993. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9994. }
  9995. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9996. json_object_put(response);
  9997. }
  9998. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9999. {
  10000. json_object *data;
  10001. data = json_tokener_parse(tempdata);
  10002. if(!is_error(data))
  10003. {
  10004. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10005. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10006. {
  10007. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10008. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10009. }
  10010. else
  10011. {
  10012. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10013. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10014. }
  10015. }
  10016. else
  10017. {
  10018. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10019. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10020. }
  10021. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10022. json_object_put(response);
  10023. }
  10024. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10025. {
  10026. json_object *data;
  10027. data = json_tokener_parse(tempdata);
  10028. if(!is_error(data))
  10029. {
  10030. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10031. {
  10032. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10033. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10034. if(gun_index < gunTotalNumber)
  10035. {
  10036. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10037. {
  10038. json_object *responsedata = json_object_new_object();
  10039. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10040. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10041. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10042. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10043. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10044. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10045. }
  10046. else
  10047. {
  10048. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10049. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10050. }
  10051. }
  10052. else
  10053. {
  10054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10055. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10056. }
  10057. }
  10058. else
  10059. {
  10060. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10061. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10062. }
  10063. }
  10064. else
  10065. {
  10066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10068. }
  10069. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10070. json_object_put(response);
  10071. }
  10072. else
  10073. {
  10074. // Can not find valid message id
  10075. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10076. }
  10077. }
  10078. else
  10079. {
  10080. // Payload is null
  10081. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10082. }
  10083. LWS_Send(message);
  10084. return result;
  10085. }
  10086. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10087. {
  10088. mtrace();
  10089. int result = FAIL;
  10090. int connectorIdInt, durationInt;
  10091. char chargingRateUnitStr[4]={0};
  10092. char comfirmstr[20];
  10093. int confirmPeriods = 0;
  10094. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10095. json_object *GetCompositeSchedule;
  10096. GetCompositeSchedule = json_tokener_parse(payload);
  10097. if(!is_error(GetCompositeSchedule))
  10098. {
  10099. // Required data
  10100. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10101. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10102. else
  10103. connectorIdInt = -1;
  10104. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10105. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10106. else
  10107. durationInt = 86400;
  10108. // Optional data
  10109. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10110. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10111. }
  10112. json_object_put(GetCompositeSchedule);
  10113. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10114. if((connectorIdInt == 0) ||
  10115. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10116. {
  10117. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10118. struct StructChargingProfile tmpProfile[1];
  10119. if(strstr(chargingRateUnitStr, "W") != NULL)
  10120. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10121. else
  10122. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10123. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10124. {
  10125. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10126. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10127. }
  10128. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10129. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10130. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10131. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10132. {
  10133. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10134. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10135. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10136. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10137. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10138. {
  10139. confirmPeriods = idx;
  10140. break;
  10141. }
  10142. }
  10143. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10144. {
  10145. confirmPeriods += 1;
  10146. }
  10147. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10148. }
  10149. else
  10150. {
  10151. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10152. }
  10153. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10154. return result;
  10155. }
  10156. int handleGetConfigurationRequest(char *uuid, char *payload)
  10157. {
  10158. mtrace();
  10159. int result = FAIL;
  10160. int MaxKeySupported = 0;
  10161. int n_keys = 0;
  10162. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10163. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10164. json_object *GetConfiguration;
  10165. GetConfiguration = json_tokener_parse(payload);
  10166. if(!is_error(GetConfiguration))
  10167. {
  10168. // Optional data
  10169. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10170. {
  10171. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10172. {
  10173. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10174. n_keys = idx + 1;
  10175. }
  10176. }
  10177. }
  10178. json_object_put(GetConfiguration);
  10179. UnknownKeynum = 0;
  10180. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10181. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10182. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10183. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10184. if(n_keys != 0)
  10185. {
  10186. for(int i=0;i<n_keys;i++)
  10187. {
  10188. getKeyValue(requestKey[i]);
  10189. }
  10190. }
  10191. else
  10192. {
  10193. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10194. getKeyValue("");
  10195. }
  10196. processUnkownKey();
  10197. sendGetConfigurationConfirmation(uuid);
  10198. return result;
  10199. }
  10200. static char fnamePlusPath[100]={0};
  10201. static char fnamePWithNoPath[60]={0};
  10202. void checkUploadLog(void)
  10203. {
  10204. FILE *fp;
  10205. /* Open the command for reading. */
  10206. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10207. if (fp == NULL) {
  10208. DEBUG_WARN("Failed to run command\n" );
  10209. exit(1);
  10210. }
  10211. int ftppathlen = 0;
  10212. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10213. int i = 0;
  10214. /* Read the output a line at a time - output it. */
  10215. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10216. if(i==0)
  10217. {
  10218. ftppathlen = strlen(fnamePlusPath);
  10219. DEBUG_INFO("%s\n", fnamePlusPath);
  10220. fnamePlusPath[ftppathlen]='\0';
  10221. break;
  10222. }
  10223. i= i+1;
  10224. }
  10225. /* close */
  10226. pclose(fp);
  10227. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10228. {
  10229. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10230. {
  10231. fnamePlusPath[k]='\0';
  10232. }
  10233. }
  10234. i=1;
  10235. //char fname[60]={0};
  10236. while(i < ftppathlen)
  10237. {
  10238. int len=ftppathlen-i;
  10239. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10240. {
  10241. DEBUG_INFO("compare '/' all right\n");
  10242. break;
  10243. }
  10244. i=i+1;
  10245. }
  10246. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10247. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10248. fnamePWithNoPath[i+1] = '\0';
  10249. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10250. {
  10251. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10252. {
  10253. fnamePWithNoPath[j]='\0';
  10254. }
  10255. }
  10256. FILE* fp1 = fopen(fnamePlusPath, "r");
  10257. if (fp1)
  10258. {
  10259. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10260. // file exists
  10261. fclose(fp1);
  10262. }
  10263. else
  10264. {
  10265. // file doesn't exist
  10266. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10267. }
  10268. }
  10269. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10270. {
  10271. mtrace();
  10272. int result = FAIL;
  10273. time_t CurrentTime;
  10274. struct tm *tm;
  10275. pthread_t th_Status;
  10276. CurrentTime = time(NULL);
  10277. tm = localtime(&CurrentTime);
  10278. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10279. 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);
  10280. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10281. if(!interLock.isGetDiagnosticGoing)
  10282. {
  10283. interLock.isGetDiagnosticGoing = 1;
  10284. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10285. sleep(1);
  10286. }
  10287. else
  10288. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10289. return result;
  10290. }
  10291. void* GetDiagnosticsProcess(void* data)
  10292. {
  10293. pthread_detach(pthread_self());
  10294. mtrace();
  10295. int retriesInt=0, retryIntervalInt=0;
  10296. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10297. 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};
  10298. int port=0;
  10299. int isSuccess = FALSE;
  10300. char cmdBuf[2048];
  10301. struct tm *tmNow;
  10302. time_t CurrentTime;
  10303. struct tm tmStart;
  10304. struct tm tmStop;
  10305. CurrentTime = time(NULL);
  10306. tmNow=localtime(&CurrentTime);
  10307. uint16_t targetYear, targetMonth;
  10308. json_object *GetDiagnostics;
  10309. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10310. GetDiagnostics = json_tokener_parse(data);
  10311. if(!is_error(GetDiagnostics))
  10312. {
  10313. // Required data
  10314. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10315. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10316. // Optional data
  10317. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10318. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10319. else
  10320. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10321. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10322. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10323. else
  10324. retryIntervalInt = 30;
  10325. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10326. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10327. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10328. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10329. }
  10330. json_object_put(GetDiagnostics);
  10331. // Pack log to compress file
  10332. 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) &&
  10333. (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))
  10334. {
  10335. // Pack system log
  10336. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10337. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10338. targetYear = tmStart.tm_year;
  10339. targetMonth = tmStart.tm_mon;
  10340. do
  10341. {
  10342. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10343. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10344. if(targetMonth+1>=13)
  10345. {
  10346. targetYear += 1;
  10347. targetMonth = 1;
  10348. }
  10349. else
  10350. {
  10351. targetMonth += 1;
  10352. }
  10353. }while((targetYear < (tmNow->tm_year+1900)) ||
  10354. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10355. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10356. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10357. system(cmdBuf);
  10358. // Pack charging & event log
  10359. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10360. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10361. targetYear = tmStart.tm_year;
  10362. targetMonth = tmStart.tm_mon;
  10363. do
  10364. {
  10365. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10366. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10367. if(targetMonth+1>=13)
  10368. {
  10369. targetYear += 1;
  10370. targetMonth = 1;
  10371. }
  10372. else
  10373. {
  10374. targetMonth += 1;
  10375. }
  10376. }while((targetYear < (tmNow->tm_year+1900)) ||
  10377. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10378. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10379. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10380. system(cmdBuf);
  10381. // Combine log file
  10382. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10383. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10384. }
  10385. else
  10386. {
  10387. system("exec /root/logPackTools 'log' 6");
  10388. }
  10389. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10390. system(cmdBuf);
  10391. checkUploadLog();
  10392. //****************location*******************/
  10393. if(strcmp(locationstr,"")==0)
  10394. {
  10395. DEBUG_INFO("location is <Empty>!\n");
  10396. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10397. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10398. goto end;
  10399. }
  10400. memset(protocol, 0, ARRAY_SIZE(protocol));
  10401. memset(user, 0, ARRAY_SIZE(user) );
  10402. memset(password, 0, ARRAY_SIZE(password));
  10403. memset(host, 0, ARRAY_SIZE(host));
  10404. memset(path, 0, ARRAY_SIZE(path));
  10405. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10406. memset(host1, 0, ARRAY_SIZE(host1));
  10407. memset(path1, 0, ARRAY_SIZE(path1));
  10408. /*location: ftp://user:password@host:port/path*/
  10409. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10410. if((access(fnamePlusPath,F_OK))!=-1)
  10411. {
  10412. DEBUG_INFO("fnamePlusPath exist.\n");
  10413. }
  10414. else
  10415. {
  10416. DEBUG_INFO("fnamePlusPath not exist!\n");
  10417. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10418. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10419. goto end;
  10420. }
  10421. if(strchr(locationstr,'@')==NULL)
  10422. {
  10423. sscanf(locationstr,
  10424. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10425. protocol, host, &port, path);
  10426. strcpy(user,"anonymous");
  10427. strcpy(password,"");
  10428. }
  10429. else
  10430. {
  10431. //DEBUG_INFO("pch=%s\n", pch);
  10432. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10433. protocol, user, password, host, &port, path);
  10434. }
  10435. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10436. {
  10437. DEBUG_INFO("protocol is not ftp/http ! \n");
  10438. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10439. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10440. goto end;
  10441. }
  10442. if(strncmp(locationstr,"http", 4) == 0)
  10443. {
  10444. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10445. sprintf(ftppath,"/%s", path);
  10446. do
  10447. {
  10448. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10449. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10450. sleep(3);
  10451. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10452. if(!isSuccess)
  10453. {
  10454. DEBUG_INFO("Diagnostics fail.\n");
  10455. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10456. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10457. sleep(retryIntervalInt);
  10458. }
  10459. else
  10460. {
  10461. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10462. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10463. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10464. }
  10465. retriesInt--;
  10466. }while((isSuccess == 0)&&(retriesInt >= 0));
  10467. }
  10468. else
  10469. {
  10470. sscanf(host,"%[^/]%s",host1, path1);
  10471. if(strlen(path) > 0)
  10472. sprintf(ftppath,"/%s", path);
  10473. else
  10474. sprintf(ftppath,"/%s", path1);
  10475. int ftppathlen=strlen(ftppath);
  10476. int i=1;
  10477. char filenametemp[50];
  10478. while(i < ftppathlen)
  10479. {
  10480. int len=ftppathlen-i;
  10481. if(ftppath[len]== 47) // '/' ascll code: 47
  10482. {
  10483. DEBUG_INFO("find '/' all right\n");
  10484. break;
  10485. }
  10486. i=i+1;
  10487. }
  10488. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10489. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10490. filenametemp[i+1] = 0;
  10491. if(port == 0)
  10492. port = 21;
  10493. do
  10494. {
  10495. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10496. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10497. sleep(3);
  10498. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10499. if(!isSuccess)
  10500. {
  10501. DEBUG_INFO("Diagnostics fail.\n");
  10502. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10503. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10504. sleep(retryIntervalInt);
  10505. }
  10506. else
  10507. {
  10508. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10509. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10510. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10511. }
  10512. retriesInt--;
  10513. }while((!isSuccess)&&(retriesInt >= 0));
  10514. }
  10515. end:
  10516. system("rm -f /mnt/*");
  10517. sleep(5);
  10518. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10519. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10520. interLock.isGetDiagnosticGoing = 0;
  10521. pthread_exit(NULL);
  10522. }
  10523. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10524. {
  10525. mtrace();
  10526. int result = FAIL;
  10527. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10528. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10529. {
  10530. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10531. locallistVersion = -1;
  10532. }
  10533. else
  10534. {
  10535. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10536. locallistVersion = 0;
  10537. OCPP_getListVerion();
  10538. }
  10539. //from db.OCPP_getListVerion
  10540. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10541. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10542. sendGetLocalListVersionConfirmation(uuid,"");
  10543. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10544. return result;
  10545. }
  10546. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10547. {
  10548. mtrace();
  10549. int result = FAIL;
  10550. int connectorIdInt=-1;
  10551. int tempIndex = 0;
  10552. int connectorIdIsNULL, chargingProfileIsNULL;
  10553. char comfirmstr[20]={0};
  10554. char cmdBuf[512];
  10555. json_object *RemoteStartTransaction;
  10556. FILE *fp;
  10557. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10558. if(server_pending == TRUE)
  10559. {
  10560. return 0;
  10561. }
  10562. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10563. RemoteStartTransaction = json_tokener_parse(payload);
  10564. if(!is_error(RemoteStartTransaction))
  10565. {
  10566. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10567. {
  10568. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10569. }
  10570. else
  10571. {
  10572. connectorIdIsNULL = TRUE;
  10573. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10574. {
  10575. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10576. {
  10577. connectorIdIsNULL = FALSE;
  10578. connectorIdInt = (gun_index+1);
  10579. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10580. break;
  10581. }
  10582. }
  10583. }
  10584. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10585. {
  10586. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10587. // Required data
  10588. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10589. // Optional data
  10590. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10591. {
  10592. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10593. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10594. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10595. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10596. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10597. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10598. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10599. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10600. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10601. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10603. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10604. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10605. {
  10606. 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")));
  10607. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10608. 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"));
  10609. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10610. 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"));
  10611. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10612. 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")));
  10613. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10614. {
  10615. 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++)
  10616. {
  10617. 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"));
  10618. 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"));
  10619. 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)
  10620. 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"));
  10621. }
  10622. }
  10623. }
  10624. }
  10625. else
  10626. {
  10627. chargingProfileIsNULL = TRUE;
  10628. }
  10629. }
  10630. }
  10631. else
  10632. {
  10633. connectorIdIsNULL = TRUE;
  10634. }
  10635. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10636. {
  10637. DEBUG_WARN("Connector id is NULL\n.");
  10638. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10639. goto end;
  10640. }
  10641. /*
  10642. enum _SYSTEM_STATUS
  10643. {
  10644. S_BOOTING = 0,
  10645. S_IDLE, = 1
  10646. S_AUTHORIZING, = 2
  10647. S_REASSIGN_CHECK, = 3
  10648. S_REASSIGN, = 4
  10649. S_PRECHARGE, = 5
  10650. S_PREPARING_FOR_EV, = 6
  10651. S_PREPARING_FOR_EVSE, = 7
  10652. S_CHARGING, = 8
  10653. S_TERMINATING, = 9
  10654. S_COMPLETE, = 10
  10655. S_ALARM, = 11
  10656. S_FAULT = 12
  10657. }
  10658. */
  10659. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10660. {
  10661. //check Transaction active
  10662. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10663. {
  10664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10665. {
  10666. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10667. }
  10668. else
  10669. {
  10670. tempIndex = connectorIdInt -1;
  10671. }
  10672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10673. {
  10674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10675. {
  10676. 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))
  10677. {
  10678. //Reserved
  10679. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10680. }
  10681. 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))
  10682. {
  10683. //Reserved
  10684. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10685. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10686. goto end;
  10687. }
  10688. else
  10689. {
  10690. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10691. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10692. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10694. {
  10695. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10697. goto end;
  10698. }
  10699. }//END FOR ELSE
  10700. }
  10701. }// END FOR CHAdeMO_QUANTITY
  10702. }
  10703. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10704. {
  10705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10706. {
  10707. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10708. }
  10709. else
  10710. {
  10711. tempIndex = connectorIdInt -1;
  10712. }
  10713. for (int index = 0; index < CCS_QUANTITY; index++)
  10714. {
  10715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10716. {
  10717. 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))
  10718. {
  10719. //Reserved
  10720. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10721. }
  10722. 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))
  10723. {
  10724. //Reserved
  10725. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10726. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10727. goto end;
  10728. }
  10729. else
  10730. {
  10731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10733. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10734. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10735. {
  10736. DEBUG_WARN("CCS connector not allow start\n.");
  10737. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10738. goto end;
  10739. }
  10740. }// END FOR ELSE
  10741. }
  10742. }// END FOR CCS_QUANTITY
  10743. }
  10744. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10745. {
  10746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10747. {
  10748. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10749. }
  10750. else
  10751. {
  10752. tempIndex = connectorIdInt -1;
  10753. }
  10754. for (int index = 0; index < GB_QUANTITY; index++)
  10755. {
  10756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10757. {
  10758. 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))
  10759. {
  10760. //Reserved
  10761. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10762. }
  10763. 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))
  10764. {
  10765. //Reserved
  10766. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10767. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10768. goto end;
  10769. }
  10770. else
  10771. {
  10772. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10773. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10774. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10775. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10776. {
  10777. DEBUG_WARN("GB connector not allow start\n.");
  10778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10779. goto end;
  10780. }
  10781. }// END FOR ELSE
  10782. }
  10783. } // END FOR GB_QUANTITY
  10784. }
  10785. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10786. {
  10787. tempIndex = connectorIdInt -1;
  10788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10789. {
  10790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10791. {
  10792. 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))
  10793. {
  10794. //Reserved
  10795. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10796. }
  10797. 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))
  10798. {
  10799. //Reserved
  10800. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10802. goto end;
  10803. }
  10804. else
  10805. {
  10806. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10807. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10808. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10809. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10810. {
  10811. DEBUG_WARN("GB connector not allow start\n.");
  10812. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10813. goto end;
  10814. }
  10815. }// END FOR ELSE
  10816. }
  10817. } // END FOR GB_QUANTITY
  10818. }
  10819. else
  10820. {
  10821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10822. {
  10823. tempIndex = 2;
  10824. }
  10825. else
  10826. {
  10827. tempIndex = connectorIdInt -1;
  10828. }
  10829. for (int index = 0; index < AC_QUANTITY; index++)
  10830. {
  10831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10832. {
  10833. 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))
  10834. {
  10835. //Reserved
  10836. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10837. }
  10838. 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))
  10839. {
  10840. //Reserved
  10841. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10843. goto end;
  10844. }
  10845. else
  10846. {
  10847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10848. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10849. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10850. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10851. {
  10852. DEBUG_WARN("AC connector not allow start\n.");
  10853. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10854. goto end;
  10855. }
  10856. }//END FOR ELSE
  10857. }
  10858. }// END FOR AC_QUANTITY
  10859. }
  10860. if(chargingProfileIsNULL == FALSE)
  10861. {
  10862. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10863. {
  10864. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10865. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10866. //memset idTag
  10867. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10868. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10869. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10870. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10871. // Save profile to file
  10872. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10873. system(cmdBuf);
  10874. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10875. fp = fopen(cmdBuf, "w");
  10876. 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));
  10877. fclose(fp);
  10878. }
  10879. else
  10880. {
  10881. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10883. }
  10884. }
  10885. else
  10886. {
  10887. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10888. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10889. //memset idTag
  10890. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10891. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10892. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10893. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10894. }
  10895. }
  10896. else
  10897. {
  10898. DEBUG_WARN("Connector id over\n.");
  10899. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10900. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10901. }
  10902. end:
  10903. json_object_put(RemoteStartTransaction);
  10904. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10905. {
  10906. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10907. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10908. }
  10909. //OCPP send RemoteStartConfirmation by first.
  10910. sendRemoteStartConfirmation(uuid, comfirmstr);
  10911. return result;
  10912. }
  10913. int handleRemoteStartRequest(char *uuid, char *payload)
  10914. {
  10915. mtrace();
  10916. int result = PASS;
  10917. int connectorIdInt=-1;
  10918. int tempIndex = 0;
  10919. char comfirmstr[20]={0};
  10920. char cmdBuf[512];
  10921. json_object *RemoteStartTransaction;
  10922. FILE *fp;
  10923. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10924. if(server_pending == TRUE)
  10925. {
  10926. result = FAIL;
  10927. }
  10928. RemoteStartTransaction = json_tokener_parse(payload);
  10929. if(!is_error(RemoteStartTransaction))
  10930. {
  10931. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10932. {
  10933. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10934. }
  10935. else
  10936. {
  10937. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10938. {
  10939. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10940. {
  10941. connectorIdInt = (gun_index+1);
  10942. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10943. break;
  10944. }
  10945. }
  10946. }
  10947. if(connectorIdInt == 0)
  10948. {
  10949. DEBUG_WARN("Connector id shall not equal 0.\n");
  10950. result = FAIL;
  10951. }
  10952. else if(connectorIdInt == -1)
  10953. {
  10954. DEBUG_INFO("Connector id does not specific.\n");
  10955. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10956. {
  10957. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10958. // Required data
  10959. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10960. // Optional data
  10961. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10962. {
  10963. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10964. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10965. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10966. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10967. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10968. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10969. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10970. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10971. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10972. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10973. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10974. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10975. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10976. {
  10977. 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")));
  10978. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10979. 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"));
  10980. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10981. 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"));
  10982. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10983. 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")));
  10984. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10985. {
  10986. 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++)
  10987. {
  10988. 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"));
  10989. 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"));
  10990. 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)
  10991. 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"));
  10992. }
  10993. }
  10994. }
  10995. }
  10996. else
  10997. {
  10998. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10999. }
  11000. }
  11001. }
  11002. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11003. {
  11004. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11005. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11006. // Required data
  11007. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11008. // Optional data
  11009. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11010. {
  11011. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11012. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11013. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11014. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11015. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11016. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11020. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11022. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11024. {
  11025. 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")));
  11026. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11027. 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"));
  11028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11029. 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"));
  11030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11031. 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")));
  11032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11033. {
  11034. 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++)
  11035. {
  11036. 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"));
  11037. 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"));
  11038. 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)
  11039. 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"));
  11040. }
  11041. }
  11042. }
  11043. }
  11044. else
  11045. {
  11046. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11047. }
  11048. }
  11049. else
  11050. {
  11051. DEBUG_WARN("Connector id is over maximun value.\n");
  11052. result = FAIL;
  11053. }
  11054. }
  11055. if(result == PASS)
  11056. {
  11057. if(connectorIdInt > 0)
  11058. {
  11059. //check Transaction active
  11060. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11061. {
  11062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11063. {
  11064. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11065. }
  11066. else
  11067. {
  11068. tempIndex = connectorIdInt -1;
  11069. }
  11070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11071. {
  11072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11073. {
  11074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11075. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11076. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11077. {
  11078. //Reserved
  11079. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11080. }
  11081. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11082. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11083. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11084. {
  11085. //Reserved
  11086. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11087. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11088. goto end;
  11089. }
  11090. else
  11091. {
  11092. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11093. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11094. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11096. {
  11097. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11099. goto end;
  11100. }
  11101. }//END FOR ELSE
  11102. }
  11103. }// END FOR CHAdeMO_QUANTITY
  11104. }
  11105. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11106. {
  11107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11108. {
  11109. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11110. }
  11111. else
  11112. {
  11113. tempIndex = connectorIdInt -1;
  11114. }
  11115. for (int index = 0; index < CCS_QUANTITY; index++)
  11116. {
  11117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11118. {
  11119. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11120. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11121. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11122. {
  11123. //Reserved
  11124. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11125. }
  11126. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11128. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11129. {
  11130. //Reserved
  11131. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11132. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11133. goto end;
  11134. }
  11135. else
  11136. {
  11137. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11138. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11139. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11140. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11141. {
  11142. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11143. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11144. goto end;
  11145. }
  11146. }// END FOR ELSE
  11147. }
  11148. }// END FOR CCS_QUANTITY
  11149. }
  11150. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11151. {
  11152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11153. {
  11154. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11155. }
  11156. else
  11157. {
  11158. tempIndex = connectorIdInt -1;
  11159. }
  11160. for (int index = 0; index < GB_QUANTITY; index++)
  11161. {
  11162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11163. {
  11164. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11165. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11166. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11167. {
  11168. //Reserved
  11169. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11170. }
  11171. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11172. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11173. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11174. {
  11175. //Reserved
  11176. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11178. goto end;
  11179. }
  11180. else
  11181. {
  11182. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11183. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11184. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11185. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11186. {
  11187. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11189. goto end;
  11190. }
  11191. }// END FOR ELSE
  11192. }
  11193. } // END FOR GB_QUANTITY
  11194. }
  11195. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11196. {
  11197. tempIndex = connectorIdInt -1;
  11198. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11199. {
  11200. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11201. {
  11202. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11203. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11204. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11205. {
  11206. //Reserved
  11207. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11208. }
  11209. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11211. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11212. {
  11213. //Reserved
  11214. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11216. goto end;
  11217. }
  11218. else
  11219. {
  11220. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11221. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11222. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11223. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11224. {
  11225. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11226. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11227. goto end;
  11228. }
  11229. }// END FOR ELSE
  11230. }
  11231. } // END FOR GB_QUANTITY
  11232. }
  11233. else
  11234. {
  11235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11236. {
  11237. tempIndex = 2;
  11238. }
  11239. else
  11240. {
  11241. tempIndex = connectorIdInt -1;
  11242. }
  11243. for (int index = 0; index < AC_QUANTITY; index++)
  11244. {
  11245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11246. {
  11247. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11249. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11250. {
  11251. //Reserved
  11252. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11253. }
  11254. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11256. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11257. {
  11258. //Reserved
  11259. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11261. goto end;
  11262. }
  11263. else
  11264. {
  11265. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11266. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11267. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11268. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11269. {
  11270. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11272. goto end;
  11273. }
  11274. }//END FOR ELSE
  11275. }
  11276. }// END FOR AC_QUANTITY
  11277. }
  11278. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11279. {
  11280. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11281. {
  11282. // Save profile to file
  11283. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11284. system(cmdBuf);
  11285. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11286. fp = fopen(cmdBuf, "w");
  11287. 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));
  11288. fclose(fp);
  11289. }
  11290. else
  11291. {
  11292. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11294. goto end;
  11295. }
  11296. }
  11297. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11299. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11300. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11301. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11302. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11303. }
  11304. else
  11305. {
  11306. uint8_t isHasIdleConnector = FALSE;
  11307. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11308. {
  11309. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11310. {
  11311. isHasIdleConnector = TRUE;
  11312. break;
  11313. }
  11314. }
  11315. if(isHasIdleConnector == TRUE)
  11316. {
  11317. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11318. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11319. {
  11320. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11321. {
  11322. // Save profile to file
  11323. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11324. system(cmdBuf);
  11325. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11326. fp = fopen(cmdBuf, "w");
  11327. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11328. fclose(fp);
  11329. refreshStartTimer(&clientTime.RemoteStartWait);
  11330. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11332. }
  11333. else
  11334. {
  11335. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11337. }
  11338. }
  11339. else
  11340. {
  11341. refreshStartTimer(&clientTime.RemoteStartWait);
  11342. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11344. }
  11345. }
  11346. else
  11347. {
  11348. DEBUG_INFO("There is not any connector is idle.\n");
  11349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11350. }
  11351. }
  11352. }
  11353. else
  11354. {
  11355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11356. }
  11357. end:
  11358. json_object_put(RemoteStartTransaction);
  11359. sendRemoteStartConfirmation(uuid, comfirmstr);
  11360. return result;
  11361. }
  11362. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11363. {
  11364. mtrace();
  11365. int result = FAIL;
  11366. int match = FALSE;
  11367. int GunNO = 0;
  11368. int tempIndex = 0;
  11369. int transactionIdInt=0;
  11370. int transactionIdIsNULL= TRUE;
  11371. char comfirmstr[20];
  11372. json_object *RemoteStopTransaction;
  11373. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11374. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11375. if(server_pending == TRUE)
  11376. {
  11377. return 0;
  11378. }
  11379. RemoteStopTransaction = json_tokener_parse(payload);
  11380. if(!is_error(RemoteStopTransaction))
  11381. {
  11382. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11383. {
  11384. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11385. transactionIdIsNULL = FALSE;
  11386. }
  11387. }
  11388. json_object_put(RemoteStopTransaction);
  11389. if(transactionIdIsNULL == FALSE)
  11390. {
  11391. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11392. {
  11393. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11394. {
  11395. //check Transaction active
  11396. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11397. {
  11398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11399. {
  11400. tempIndex = ((gun_index==2) ? 1: 0);
  11401. }
  11402. else
  11403. {
  11404. tempIndex = gun_index;
  11405. }
  11406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11407. {
  11408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11409. {
  11410. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11411. {
  11412. match = TRUE;
  11413. GunNO = gun_index;
  11414. }
  11415. }
  11416. }// END FOR CHAdeMO_QUANTITY
  11417. }
  11418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11419. {
  11420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11421. {
  11422. tempIndex = ((gun_index==2) ? 1: 0);
  11423. }
  11424. else
  11425. {
  11426. tempIndex = gun_index;
  11427. }
  11428. for (int index = 0; index < CCS_QUANTITY; index++)
  11429. {
  11430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11431. {
  11432. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11433. {
  11434. match = TRUE;
  11435. GunNO = gun_index;
  11436. }
  11437. }
  11438. }// END FOR CCS_QUANTITY
  11439. }
  11440. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11441. {
  11442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11443. {
  11444. tempIndex = ((gun_index==2) ? 1: 0);
  11445. }
  11446. else
  11447. {
  11448. tempIndex = gun_index;
  11449. }
  11450. for (int index = 0; index < GB_QUANTITY; index++)
  11451. {
  11452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11453. {
  11454. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11455. {
  11456. match = TRUE;
  11457. GunNO = gun_index;
  11458. }
  11459. }
  11460. }// END FOR GB_QUANTITY
  11461. }
  11462. else if(gunType[gun_index] == GUN_TYPE_DO)
  11463. {
  11464. tempIndex = gun_index;
  11465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11466. {
  11467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11468. {
  11469. 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
  11470. {
  11471. match = TRUE;
  11472. GunNO = gun_index;
  11473. }
  11474. }
  11475. }// END FOR GB_QUANTITY
  11476. }
  11477. else
  11478. {
  11479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11480. {
  11481. tempIndex = 2;
  11482. }
  11483. else
  11484. {
  11485. tempIndex = gun_index;
  11486. }
  11487. for (int index = 0; index < AC_QUANTITY; index++)
  11488. {
  11489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11490. {
  11491. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11492. {
  11493. match = TRUE;
  11494. GunNO = gun_index;
  11495. }
  11496. }
  11497. }// END FOR CHAdeMO_QUANTITY
  11498. } // END FOR AC ELSE
  11499. }// CHECK IF ResponseTransactionId == transactionIdInt
  11500. }//END FOR
  11501. if( match == TRUE)
  11502. {
  11503. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11504. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11505. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11506. }
  11507. else
  11508. {
  11509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11510. }
  11511. }
  11512. else
  11513. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11514. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11515. return result;
  11516. }
  11517. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11518. {
  11519. mtrace();
  11520. int result = FAIL;
  11521. int connectorIdInt=0, reservationIdInt=0;
  11522. int tempIndex = 0;
  11523. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11524. char comfirmstr[20]={0};
  11525. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11526. int c = 0;
  11527. char *loc;
  11528. //char *ptr;
  11529. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11530. strcpy(sstrtemp, stringtrimspace(payload));
  11531. //***(1)connectorId ****/
  11532. c=0;
  11533. loc = strstr(sstrtemp, "connectorId");
  11534. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11535. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11536. {
  11537. sstr[c] = loc[strlen("connectorId")+2+c];
  11538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11539. c++;
  11540. }
  11541. sstr[c] = '\0';
  11542. connectorIdInt = atoi(sstr);
  11543. //***(2)expiryDate ****/
  11544. loc = strstr(sstrtemp, "expiryDate");
  11545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11546. c = 0;
  11547. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11548. {
  11549. sstr[c] = loc[3+strlen("expiryDate")+c];
  11550. c++;
  11551. }
  11552. sstr[c] = '\0';
  11553. strcpy(expiryDatestr, sstr);
  11554. //***(3)idTag ****/
  11555. loc = strstr(sstrtemp, "idTag");
  11556. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11557. c = 0;
  11558. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11559. {
  11560. sstr[c] = loc[3+strlen("idTag")+c];
  11561. c++;
  11562. }
  11563. sstr[c] = '\0';
  11564. strcpy(idTagstr, sstr);
  11565. //***(4)parentIdTag ****/
  11566. loc = strstr(sstrtemp, "parentIdTag");
  11567. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11568. c = 0;
  11569. if(loc == NULL)
  11570. {
  11571. strcpy(parentIdTagstr, "");
  11572. }
  11573. else
  11574. {
  11575. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11576. {
  11577. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11578. c++;
  11579. }
  11580. sstr[c] = '\0';
  11581. strcpy(parentIdTagstr, sstr);
  11582. }
  11583. //***(5)reservationId ****/
  11584. c=0;
  11585. loc = strstr(sstrtemp, "reservationId");
  11586. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11587. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11588. {
  11589. sstr[c] = loc[strlen("reservationId")+2+c];
  11590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11591. c++;
  11592. }
  11593. sstr[c] = '\0';
  11594. reservationIdInt = atoi(sstr);
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11596. /*
  11597. enum SYSTEM_STATUS
  11598. {
  11599. SYS_MODE_BOOTING = 0,
  11600. SYS_MODE_IDLE = 1,
  11601. SYS_MODE_AUTHORIZING = 2,
  11602. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11603. SYS_MODE_REASSIGN = 4,
  11604. SYS_MODE_PREPARING = 5,
  11605. SYS_MODE_PREPARE_FOR_EV = 6,
  11606. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11607. SYS_MODE_CHARGING = 8,
  11608. SYS_MODE_TERMINATING = 9,
  11609. SYS_MODE_COMPLETE = 10,
  11610. SYS_MODE_ALARM = 11,
  11611. SYS_MODE_FAULT = 12,
  11612. SYS_MODE_RESERVATION = 13,
  11613. SYS_MODE_BOOKING = 14,
  11614. SYS_MODE_MAINTAIN = 15,
  11615. SYS_MODE_DEBUG = 16,
  11616. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11617. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11618. SYS_MODE_UPDATE = 19
  11619. };
  11620. */
  11621. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11622. {
  11623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11624. goto end;
  11625. }
  11626. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11627. {
  11628. //check Transaction active
  11629. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11630. {
  11631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11632. {
  11633. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11634. }
  11635. else
  11636. {
  11637. tempIndex = connectorIdInt -1;
  11638. }
  11639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11640. {
  11641. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11642. {
  11643. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11644. {
  11645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11646. {
  11647. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11648. {
  11649. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11651. }
  11652. 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'))
  11653. {
  11654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11655. }
  11656. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11657. {
  11658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11659. }
  11660. else
  11661. {
  11662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11663. }
  11664. }
  11665. 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
  11666. {
  11667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11668. }
  11669. }
  11670. else
  11671. {
  11672. //replace reservation
  11673. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11675. }
  11676. }
  11677. } // END FOR CHAdeMO_QUANTITY
  11678. }
  11679. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11680. {
  11681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11682. {
  11683. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11684. }
  11685. else
  11686. {
  11687. tempIndex = connectorIdInt -1;
  11688. }
  11689. for (int index = 0; index < CCS_QUANTITY; index++)
  11690. {
  11691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11692. {
  11693. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11694. {
  11695. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11696. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11697. {
  11698. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11699. {
  11700. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11702. }
  11703. 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'))
  11704. {
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11706. }
  11707. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11708. {
  11709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11710. }
  11711. else
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11714. }
  11715. }
  11716. 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
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11719. }
  11720. }
  11721. else
  11722. {
  11723. //replace reservation
  11724. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11726. }
  11727. }
  11728. } // END FOR CCS_QUANTITY
  11729. }
  11730. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11731. {
  11732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11733. {
  11734. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11735. }
  11736. else
  11737. {
  11738. tempIndex = connectorIdInt -1;
  11739. }
  11740. for (int index = 0; index < GB_QUANTITY; index++)
  11741. {
  11742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11743. {
  11744. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11745. {
  11746. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11747. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11748. {
  11749. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11750. {
  11751. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11753. }
  11754. 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'))
  11755. {
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11757. }
  11758. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11761. }
  11762. else
  11763. {
  11764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11765. }
  11766. }
  11767. 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
  11768. {
  11769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11770. }
  11771. }
  11772. else
  11773. {
  11774. //replace reservation
  11775. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11777. }
  11778. }
  11779. }// END FOR GB_QUANTITY
  11780. }
  11781. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11782. {
  11783. tempIndex = connectorIdInt -1;
  11784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11785. {
  11786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11787. {
  11788. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11789. {
  11790. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11791. 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
  11792. {
  11793. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11794. {
  11795. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11797. }
  11798. 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'))
  11799. {
  11800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11801. }
  11802. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11803. {
  11804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11805. }
  11806. else
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11809. }
  11810. }
  11811. 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
  11812. {
  11813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11814. }
  11815. }
  11816. else
  11817. {
  11818. //replace reservation
  11819. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11821. }
  11822. }
  11823. }// END FOR GB_QUANTITY
  11824. }
  11825. else
  11826. {
  11827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11828. {
  11829. tempIndex = 2;
  11830. }
  11831. else
  11832. {
  11833. tempIndex = (connectorIdInt -1);
  11834. }
  11835. for (int index = 0; index < AC_QUANTITY; index++)
  11836. {
  11837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11838. {
  11839. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11840. {
  11841. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11842. {
  11843. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11844. {
  11845. 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))
  11846. {
  11847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11848. }
  11849. else
  11850. {
  11851. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11853. }
  11854. }
  11855. 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'))
  11856. {
  11857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11858. }
  11859. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11860. {
  11861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11862. }
  11863. else
  11864. {
  11865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11866. }
  11867. }
  11868. 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
  11869. {
  11870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11871. }
  11872. }
  11873. else
  11874. {
  11875. //replace reservation
  11876. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11878. }
  11879. }
  11880. } // END FOR AC_QUANTITY
  11881. }
  11882. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11883. }
  11884. else if(connectorIdInt == 0)
  11885. {
  11886. //check Transaction active
  11887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11888. {
  11889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11890. {
  11891. 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'))
  11892. {
  11893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11894. goto end;
  11895. }
  11896. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11897. {
  11898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11899. goto end;
  11900. }
  11901. 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
  11902. {
  11903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11904. goto end;
  11905. }
  11906. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11907. {
  11908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11909. goto end;
  11910. }
  11911. }
  11912. }// END FOR CHAdeMO_QUANTITY
  11913. for (int index = 0; index < CCS_QUANTITY; index++)
  11914. {
  11915. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11916. {
  11917. 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'))
  11918. {
  11919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11920. goto end;
  11921. }
  11922. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11923. {
  11924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11925. goto end;
  11926. }
  11927. 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
  11928. {
  11929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11930. goto end;
  11931. }
  11932. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11933. {
  11934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11935. goto end;
  11936. }
  11937. }
  11938. } // END FOR CCS_QUANTITY
  11939. for (int index = 0; index < GB_QUANTITY; index++)
  11940. {
  11941. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11942. {
  11943. 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'))
  11944. {
  11945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11946. goto end;
  11947. }
  11948. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11949. {
  11950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11951. goto end;
  11952. }
  11953. 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
  11954. {
  11955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11956. goto end;
  11957. }
  11958. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11959. {
  11960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11961. goto end;
  11962. }
  11963. }
  11964. } // END FOR GB_QUANTITY
  11965. for (int index = 0; index < AC_QUANTITY; index++)
  11966. {
  11967. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11968. {
  11969. 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'))
  11970. {
  11971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11972. goto end;
  11973. }
  11974. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11975. {
  11976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11977. goto end;
  11978. }
  11979. 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
  11980. {
  11981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11982. goto end;
  11983. }
  11984. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11985. {
  11986. 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))
  11987. {
  11988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11989. goto end;
  11990. }
  11991. }
  11992. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11993. {
  11994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11995. goto end;
  11996. }
  11997. }
  11998. }// END FOR AC_QUANTITY
  11999. //The connectorId is 0
  12000. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12002. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12003. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12004. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12005. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12006. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12007. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12008. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12009. result = TRUE;
  12010. return result;
  12011. }
  12012. else
  12013. {
  12014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12015. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12016. }
  12017. if(strcmp(comfirmstr,"Accepted") == 0)
  12018. {
  12019. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12020. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12021. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12022. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12023. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12024. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12025. result = TRUE;
  12026. return result;
  12027. }
  12028. end:
  12029. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12030. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12031. return result;
  12032. }
  12033. int handleResetRequest(char *uuid, char *payload)
  12034. {
  12035. mtrace();
  12036. int result = FAIL;
  12037. char sstr[10]={0},sstrtemp[30]={ 0 };
  12038. char typestr[10]={0};
  12039. char comfirmstr[20]={0};
  12040. int c = 0;
  12041. char *loc;
  12042. DEBUG_INFO("handleResetRequest...\n");
  12043. strcpy(sstrtemp, stringtrimspace(payload));
  12044. loc = strstr(sstrtemp, "type");
  12045. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12046. c = 0;
  12047. while (loc[3+strlen("type")+c] != '\"')
  12048. {
  12049. sstr[c] = loc[3+strlen("type")+c];
  12050. c++;
  12051. }
  12052. sstr[c] = '\0';
  12053. strcpy(typestr,sstr);
  12054. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12055. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12056. {
  12057. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12058. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12059. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12060. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12061. }
  12062. else
  12063. {
  12064. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12065. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12066. result = PASS;
  12067. }
  12068. sendResetConfirmation(uuid, comfirmstr);
  12069. return result;
  12070. }
  12071. int handleSendLocalListRequest(char *uuid, char *payload)
  12072. {
  12073. mtrace();
  12074. int result = FAIL;
  12075. char comfirmstr[20];
  12076. int checkState_Faulted = FALSE;
  12077. json_object *SendLocalList;
  12078. DEBUG_INFO("handleSendLocalListRequest...\n");
  12079. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12080. {
  12081. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12082. goto end;
  12083. }
  12084. //check Charge Point state
  12085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12086. {
  12087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12088. {
  12089. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12090. }
  12091. }
  12092. for (int index = 0; index < CCS_QUANTITY; index++)
  12093. {
  12094. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12095. {
  12096. checkState_Faulted = TRUE; //OCPP Status
  12097. }
  12098. }
  12099. for (int index = 0; index < GB_QUANTITY; index++)
  12100. {
  12101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12102. {
  12103. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12104. }
  12105. }
  12106. //check Charge Point state
  12107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12108. {
  12109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12110. {
  12111. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12112. }
  12113. }
  12114. //check Charge Point state
  12115. for (int index = 0; index < AC_QUANTITY; index++)
  12116. {
  12117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12118. {
  12119. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12120. }
  12121. }
  12122. if(checkState_Faulted == TRUE)
  12123. {
  12124. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12125. goto end;
  12126. }
  12127. // Parsing payload
  12128. SendLocalList = json_tokener_parse(payload);
  12129. if(!is_error(SendLocalList))
  12130. {
  12131. // Required data
  12132. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12133. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12134. // Optional data
  12135. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12136. {
  12137. //Check UpdateType
  12138. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12139. {
  12140. //Local list full update
  12141. DEBUG_INFO("Local list full update.\n");
  12142. locallistVersion = 0;
  12143. OCPP_getListVerion();
  12144. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12145. {
  12146. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12147. goto end;
  12148. }*/
  12149. OCPP_cleanLocalList();
  12150. }
  12151. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12152. {
  12153. //Local list different update
  12154. DEBUG_INFO("Local list different update.\n");
  12155. locallistVersion = 0;
  12156. OCPP_getListVerion();
  12157. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12158. {
  12159. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12160. goto end;
  12161. }
  12162. }
  12163. else
  12164. {
  12165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12166. goto end;
  12167. }
  12168. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12169. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12170. {
  12171. 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")));
  12172. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12173. {
  12174. 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")));
  12175. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12176. 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")));
  12177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12178. 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")));
  12179. }
  12180. // Add to db
  12181. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12182. {
  12183. //Local list full update
  12184. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12185. idx,
  12186. ShmOCPP16Data->SendLocalList.ListVersion,
  12187. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12188. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12189. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12191. // update list
  12192. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12193. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12194. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12195. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12197. }
  12198. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12199. {
  12200. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12201. idx,
  12202. ShmOCPP16Data->SendLocalList.ListVersion,
  12203. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12204. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12207. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12208. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12209. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12212. }
  12213. }
  12214. }
  12215. else
  12216. {
  12217. //Check UpdateType
  12218. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12219. {
  12220. //Local list full update
  12221. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12222. OCPP_cleanLocalList();
  12223. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12224. goto end;
  12225. }
  12226. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12227. {
  12228. //Local list different update
  12229. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12230. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12231. goto end;
  12232. }
  12233. }
  12234. result = PASS;
  12235. }
  12236. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12237. end:
  12238. json_object_put(SendLocalList);
  12239. sendSendLocalListConfirmation(uuid, comfirmstr);
  12240. return result;
  12241. }
  12242. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12243. {
  12244. mtrace();
  12245. int result = FAIL;
  12246. struct StructSetChargingProfile SetProfileReq = {0};
  12247. int tempchargingProfileIdInt;
  12248. int tempstackLevelInt;
  12249. int chargingSchedulePeriodCount = 0;
  12250. char comfirmstr[20]={0};
  12251. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12252. char rmFileCmd[128]={0};
  12253. int profileQuantity = 0;
  12254. int replaceableProfileCnt = 0;
  12255. json_object *SetChargingProfile;
  12256. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12257. SetChargingProfile = json_tokener_parse(payload);
  12258. if(!is_error(SetChargingProfile))
  12259. {
  12260. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12261. {
  12262. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12263. }
  12264. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12265. {
  12266. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12267. {
  12268. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12269. }
  12270. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12271. {
  12272. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12273. }
  12274. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12275. {
  12276. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12277. }
  12278. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12279. {
  12280. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12281. }
  12282. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12283. {
  12284. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12285. }
  12286. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12287. {
  12288. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12289. }
  12290. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12291. {
  12292. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12293. }
  12294. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12295. {
  12296. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12297. }
  12298. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12299. {
  12300. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12301. {
  12302. 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")));
  12303. }
  12304. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12305. {
  12306. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12307. }
  12308. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12309. {
  12310. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12311. }
  12312. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12313. {
  12314. 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")));
  12315. }
  12316. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12317. {
  12318. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12319. if(chargingSchedulePeriodCount <= 10)
  12320. {
  12321. 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++)
  12322. {
  12323. 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)
  12324. {
  12325. 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"));
  12326. }
  12327. 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)
  12328. {
  12329. 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"));
  12330. }
  12331. 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)
  12332. {
  12333. 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"));
  12334. }
  12335. }
  12336. }
  12337. }
  12338. }
  12339. }
  12340. }
  12341. // Profile periods quantity check
  12342. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12343. {
  12344. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12345. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12346. goto end;
  12347. }
  12348. // Check invalid limit
  12349. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12350. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12351. {
  12352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12353. {
  12354. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12355. {
  12356. 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)))) ||
  12357. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12358. {
  12359. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12360. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12361. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12362. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12363. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12364. goto end;
  12365. }
  12366. }
  12367. }
  12368. else
  12369. {
  12370. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12371. {
  12372. 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) ||
  12373. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12374. {
  12375. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12376. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12377. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12378. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12379. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12380. goto end;
  12381. }
  12382. }
  12383. }
  12384. }
  12385. // Profile purpose info check
  12386. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12387. {
  12388. FILE *fp;
  12389. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12390. if(SetProfileReq.ConnectorId != 0)
  12391. {
  12392. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12393. DEBUG_WARN("Profile connector id is not 0.\n");
  12394. goto end;
  12395. }
  12396. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12397. if (!fp)
  12398. {
  12399. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12400. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12401. }
  12402. else
  12403. {
  12404. char *line = NULL;
  12405. size_t len = 0;
  12406. while(getline(&line, &len, fp) != -1)
  12407. {
  12408. json_object *obj = NULL;
  12409. obj = json_tokener_parse(line);
  12410. if(is_error(obj))
  12411. {
  12412. DEBUG_ERROR("Parse txProfile from file error.\n");
  12413. }
  12414. else
  12415. {
  12416. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12417. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12418. {
  12419. profileQuantity += 1;
  12420. }
  12421. else
  12422. replaceableProfileCnt += 1;
  12423. }
  12424. }
  12425. }
  12426. fclose(fp);
  12427. }
  12428. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12429. {
  12430. FILE *fp;
  12431. char filename[128]={0};
  12432. int tmpProfileQuantity;
  12433. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12434. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12435. {
  12436. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12437. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12438. goto end;
  12439. }
  12440. if(SetProfileReq.ConnectorId == 0)
  12441. {
  12442. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12443. {
  12444. tmpProfileQuantity = 0;
  12445. memset(filename, 0, ARRAY_SIZE(filename));
  12446. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12447. fp = fopen(filename, "r");
  12448. if (!fp)
  12449. {
  12450. DEBUG_INFO("%s does not create.\n", filename);
  12451. fp = fopen(filename, "w+");
  12452. }
  12453. else
  12454. {
  12455. char *line = NULL;
  12456. size_t len = 0;
  12457. while(getline(&line, &len, fp) != -1)
  12458. {
  12459. json_object *obj = NULL;
  12460. obj = json_tokener_parse(line);
  12461. if(is_error(obj))
  12462. {
  12463. DEBUG_ERROR("Parse txProfile from file error.\n");
  12464. }
  12465. else
  12466. {
  12467. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12468. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12469. {
  12470. tmpProfileQuantity += 1;
  12471. }
  12472. else
  12473. replaceableProfileCnt += 1;
  12474. }
  12475. }
  12476. }
  12477. fclose(fp);
  12478. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12479. }
  12480. }
  12481. else
  12482. {
  12483. memset(filename, 0, ARRAY_SIZE(filename));
  12484. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12485. fp = fopen(filename, "r");
  12486. if (!fp)
  12487. {
  12488. DEBUG_INFO("%s does not create.\n", filename);
  12489. fp = fopen(filename, "w+");
  12490. }
  12491. else
  12492. {
  12493. char *line = NULL;
  12494. size_t len = 0;
  12495. while(getline(&line, &len, fp) != -1)
  12496. {
  12497. json_object *obj = NULL;
  12498. obj = json_tokener_parse(line);
  12499. if(is_error(obj))
  12500. {
  12501. DEBUG_ERROR("Parse txProfile from file error.\n");
  12502. }
  12503. else
  12504. {
  12505. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12506. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12507. {
  12508. profileQuantity += 1;
  12509. }
  12510. else
  12511. replaceableProfileCnt += 1;
  12512. }
  12513. }
  12514. }
  12515. fclose(fp);
  12516. }
  12517. }
  12518. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12519. {
  12520. int isMatchTransactiodId= FALSE;
  12521. FILE *fp;
  12522. char filename[128]={0};
  12523. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12524. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12525. if(SetProfileReq.ConnectorId == 0)
  12526. {
  12527. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12528. DEBUG_WARN("Profile connector id is 0.\n");
  12529. goto end;
  12530. }
  12531. int tempIndex = 0;
  12532. //check Transaction active
  12533. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12534. {
  12535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12536. {
  12537. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12538. }
  12539. else
  12540. {
  12541. tempIndex = SetProfileReq.ConnectorId -1;
  12542. }
  12543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12544. {
  12545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12546. {
  12547. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12548. {
  12549. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12550. {
  12551. isMatchTransactiodId = TRUE;
  12552. break;
  12553. }
  12554. }
  12555. }
  12556. }
  12557. }
  12558. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12559. {
  12560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12561. {
  12562. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12563. }
  12564. else
  12565. {
  12566. tempIndex = SetProfileReq.ConnectorId -1;
  12567. }
  12568. for (int index = 0; index < CCS_QUANTITY; index++)
  12569. {
  12570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12571. {
  12572. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12573. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12574. {
  12575. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12576. {
  12577. isMatchTransactiodId = TRUE;
  12578. break;
  12579. }
  12580. }
  12581. }
  12582. }
  12583. }
  12584. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12585. {
  12586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12587. {
  12588. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12589. }
  12590. else
  12591. {
  12592. tempIndex = SetProfileReq.ConnectorId -1;
  12593. }
  12594. for (int index = 0; index < GB_QUANTITY; index++)
  12595. {
  12596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12597. {
  12598. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12599. {
  12600. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12601. {
  12602. isMatchTransactiodId = TRUE;
  12603. break;
  12604. }
  12605. }
  12606. }
  12607. }
  12608. }
  12609. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12610. {
  12611. tempIndex = SetProfileReq.ConnectorId -1;
  12612. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12613. {
  12614. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12615. {
  12616. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12617. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12618. {
  12619. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12620. {
  12621. isMatchTransactiodId = TRUE;
  12622. break;
  12623. }
  12624. }
  12625. }
  12626. }
  12627. }
  12628. else
  12629. {
  12630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12631. {
  12632. tempIndex = 2;
  12633. }
  12634. else
  12635. {
  12636. tempIndex = (SetProfileReq.ConnectorId -1);
  12637. }
  12638. for (int index = 0; index < AC_QUANTITY; index++)
  12639. {
  12640. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12641. {
  12642. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12643. {
  12644. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12645. {
  12646. isMatchTransactiodId = TRUE;
  12647. break;
  12648. }
  12649. }
  12650. }
  12651. }
  12652. }
  12653. //check Transaction active
  12654. if(isMatchTransactiodId == FALSE)
  12655. {
  12656. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12657. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12658. goto end;
  12659. }
  12660. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12661. {
  12662. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12663. DEBUG_WARN("Connector id is over max gun number.\n");
  12664. goto end;
  12665. }
  12666. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12667. fp = fopen(filename, "r");
  12668. if (!fp)
  12669. {
  12670. DEBUG_INFO("%s does not create.\n", filename);
  12671. fp = fopen(filename, "w+");
  12672. }
  12673. else
  12674. {
  12675. char *line = NULL;
  12676. size_t len = 0;
  12677. while(getline(&line, &len, fp) != -1)
  12678. {
  12679. json_object *obj = NULL;
  12680. obj = json_tokener_parse(line);
  12681. if(is_error(obj))
  12682. {
  12683. DEBUG_ERROR("Parse txProfile from file error.\n");
  12684. }
  12685. else
  12686. {
  12687. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12688. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12689. {
  12690. profileQuantity += 1;
  12691. }
  12692. else
  12693. replaceableProfileCnt += 1;
  12694. }
  12695. }
  12696. }
  12697. fclose(fp);
  12698. }
  12699. // Check ChargeProfileMaxStackLevel
  12700. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12701. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12702. {
  12703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12704. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12705. goto end;
  12706. }
  12707. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12708. {
  12709. FILE *fp;
  12710. char dataLine[4096]={0};
  12711. char fnametemp[128]={0};
  12712. int tmpProfileQuantity;
  12713. //Check ChargePointMaxProfile.json exit
  12714. profileQuantity = 0;
  12715. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12716. {
  12717. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12718. //Check Charging Profile Count
  12719. tmpProfileQuantity = 0;
  12720. while(fscanf(fp, "%s", dataLine) != EOF)
  12721. {
  12722. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12723. {
  12724. profileQuantity += 1;
  12725. tmpProfileQuantity += 1;
  12726. }
  12727. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12728. }
  12729. fclose(fp);
  12730. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12731. }
  12732. //Check TxDefaultProfile_%d.json
  12733. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12734. {
  12735. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12736. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12737. if((access(fnametemp,F_OK))!=-1)
  12738. {
  12739. fp = fopen(fnametemp, "r");
  12740. //Check Charging Profile Count
  12741. tmpProfileQuantity = 0;
  12742. while(fscanf(fp, "%s", dataLine) != EOF)
  12743. {
  12744. //DEBUG_INFO("word=%s\n",word);
  12745. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12746. {
  12747. profileQuantity += 1;
  12748. tmpProfileQuantity += 1;
  12749. }
  12750. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12751. }
  12752. fclose(fp);
  12753. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12754. }
  12755. }
  12756. //Check TxProfile_%d.json
  12757. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12758. {
  12759. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12760. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12761. if((access(fnametemp,F_OK))!=-1)
  12762. {
  12763. fp = fopen(fnametemp, "r");
  12764. //Check Charging Profile Count
  12765. tmpProfileQuantity = 0;
  12766. while(fscanf(fp, "%s", dataLine) != EOF)
  12767. {
  12768. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12769. {
  12770. profileQuantity += 1;
  12771. tmpProfileQuantity += 1;
  12772. }
  12773. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12774. }
  12775. fclose(fp);
  12776. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12777. }
  12778. }
  12779. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12780. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12781. // To check total Profile quantity
  12782. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12783. {
  12784. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12785. {
  12786. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12787. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12788. goto end;
  12789. }
  12790. }
  12791. else
  12792. {
  12793. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12794. {
  12795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12796. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12797. goto end;
  12798. }
  12799. }
  12800. }
  12801. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12802. //**********************************Write to File********************************************************/
  12803. {
  12804. FILE *infile;
  12805. FILE *outfile;
  12806. char dataLine[4096]={0};
  12807. char filename[128]={0};
  12808. int chkChar=0;
  12809. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12810. {
  12811. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12812. {
  12813. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12814. }
  12815. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12816. {
  12817. if(SetProfileReq.ConnectorId==0)
  12818. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12819. else
  12820. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12821. }
  12822. else
  12823. {
  12824. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12825. }
  12826. infile = fopen (filename, "r");
  12827. outfile = fopen (tempfile, "w");
  12828. chkChar = fgetc(infile);
  12829. rewind(infile);
  12830. if(chkChar == EOF)
  12831. {
  12832. // Profile is empty
  12833. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12834. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12835. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12836. fclose(infile);
  12837. fclose(outfile);
  12838. sprintf(rmFileCmd,"rm -f %s",filename);
  12839. system(rmFileCmd);
  12840. rename(tempfile, filename);
  12841. }
  12842. else
  12843. {
  12844. // Profile is not empty
  12845. int ChargingProfileAdded = FALSE;
  12846. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12847. {
  12848. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12849. json_object *tmpChargingProfile;
  12850. tmpChargingProfile = json_tokener_parse(dataLine);
  12851. if(!is_error(SetChargingProfile))
  12852. {
  12853. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12854. {
  12855. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12856. {
  12857. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12858. }
  12859. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12860. {
  12861. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12862. }
  12863. }
  12864. }
  12865. json_object_put(tmpChargingProfile);
  12866. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12867. {
  12868. if(ChargingProfileAdded == FALSE)
  12869. {
  12870. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12871. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12872. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12873. ChargingProfileAdded = TRUE;
  12874. }
  12875. }
  12876. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12877. {
  12878. if(ChargingProfileAdded == FALSE)
  12879. {
  12880. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12881. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12882. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12883. ChargingProfileAdded = TRUE;
  12884. }
  12885. }
  12886. else
  12887. {
  12888. fprintf(outfile,"%s\n",dataLine);
  12889. if(ChargingProfileAdded == FALSE)
  12890. {
  12891. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12892. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12893. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12894. ChargingProfileAdded = TRUE;
  12895. }
  12896. }
  12897. } // end of while loop
  12898. fclose(infile);
  12899. fclose(outfile);
  12900. sprintf(rmFileCmd,"rm -f %s",filename);
  12901. system(rmFileCmd);
  12902. rename(tempfile, filename);
  12903. }
  12904. }
  12905. sleep(1);
  12906. result = TRUE;
  12907. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12908. }
  12909. end:
  12910. json_object_put(SetChargingProfile);
  12911. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12912. {
  12913. if(SetProfileReq.ConnectorId == 0)
  12914. {
  12915. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12916. {
  12917. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12918. }
  12919. }
  12920. else
  12921. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12922. }
  12923. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12924. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12925. return result;
  12926. }
  12927. int handleTriggerMessageRequest(char *uuid, char *payload)
  12928. {
  12929. mtrace();
  12930. int result = FAIL;
  12931. int connectorIdIsNULL = FALSE;
  12932. int connectorIdInt =0;
  12933. char sstr[40]={0},sstrtemp[100]={ 0 };
  12934. char requestedMessagestr[40]={0};
  12935. char comfirmstr[20]={0};
  12936. int c = 0;
  12937. char *loc;
  12938. DEBUG_INFO("handleTriggerMessageRequest\n");
  12939. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12940. strcpy(sstrtemp, stringtrimspace(payload));
  12941. c = 0;
  12942. loc = strstr(sstrtemp, "requestedMessage");
  12943. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12944. {
  12945. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12946. c++;
  12947. }
  12948. sstr[c] = '\0';
  12949. strcpy(requestedMessagestr, sstr);
  12950. c = 0;
  12951. loc = strstr(sstrtemp, "connectorId");
  12952. if(loc == NULL)
  12953. {
  12954. connectorIdIsNULL = TRUE;
  12955. }
  12956. else
  12957. {
  12958. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12959. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12960. {
  12961. sstr[c] = loc[strlen("connectorId")+2+c];
  12962. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12963. c++;
  12964. }
  12965. sstr[c] = '\0';
  12966. connectorIdInt = atoi(sstr);
  12967. }
  12968. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12969. {
  12970. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12971. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12972. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12973. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12974. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12975. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12976. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12977. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12978. {
  12979. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12980. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12981. return TRUE;
  12982. }
  12983. else
  12984. {
  12985. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12986. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12987. }
  12988. }
  12989. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12990. {
  12991. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12992. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12993. return TRUE;
  12994. }
  12995. //==========================
  12996. // Trigger message
  12997. //==========================
  12998. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12999. {
  13000. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13001. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13002. {
  13003. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13004. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13005. }
  13006. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13007. }
  13008. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13009. {
  13010. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13011. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13012. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13013. }
  13014. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13015. {
  13016. //sendBootNotificationRequest();
  13017. server_sign = FALSE;
  13018. }
  13019. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13020. {
  13021. refreshStartTimer(&clientTime.Heartbeat);
  13022. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13023. }
  13024. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13025. {
  13026. if(connectorIdIsNULL == FALSE)
  13027. {
  13028. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13029. {
  13030. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13031. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13032. }
  13033. }
  13034. else
  13035. {
  13036. for(int idx=0;idx< gunTotalNumber;idx++)
  13037. {
  13038. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13039. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13040. }
  13041. }
  13042. }
  13043. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13044. {
  13045. if(connectorIdIsNULL == FALSE)
  13046. {
  13047. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13048. {
  13049. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13050. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13051. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13052. }
  13053. }
  13054. else
  13055. {
  13056. for(int idx=0;idx< gunTotalNumber;idx++)
  13057. {
  13058. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13059. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13060. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13061. }
  13062. }
  13063. }
  13064. return result;
  13065. }
  13066. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13067. {
  13068. mtrace();
  13069. int result = FAIL;
  13070. int connectorIdInt =0;
  13071. char comfirmstr[20]={0};
  13072. int tempIndex = 0;
  13073. json_object *UnlockConnector;
  13074. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13075. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13076. UnlockConnector = json_tokener_parse(payload);
  13077. if(!is_error(UnlockConnector))
  13078. {
  13079. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13080. {
  13081. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13082. }
  13083. }
  13084. json_object_put(UnlockConnector);
  13085. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13086. if(gunTotalNumber == 0)
  13087. {
  13088. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13089. goto end;
  13090. }
  13091. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13092. {
  13093. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13094. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13095. goto end;
  13096. }
  13097. else
  13098. {
  13099. //check Transaction active
  13100. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13101. {
  13102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13103. {
  13104. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13105. }
  13106. else
  13107. {
  13108. tempIndex = connectorIdInt -1;
  13109. }
  13110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13111. {
  13112. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13113. {
  13114. //stop Transaction
  13115. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13116. }
  13117. }
  13118. }
  13119. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13120. {
  13121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13122. {
  13123. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13124. }
  13125. else
  13126. {
  13127. tempIndex = connectorIdInt -1;
  13128. }
  13129. for (int index = 0; index < CCS_QUANTITY; index++)
  13130. {
  13131. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13132. {
  13133. //stop Transaction
  13134. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13135. }
  13136. }
  13137. }
  13138. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13139. {
  13140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13141. {
  13142. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13143. }
  13144. else
  13145. {
  13146. tempIndex = connectorIdInt -1;
  13147. }
  13148. for (int index = 0; index < GB_QUANTITY; index++)
  13149. {
  13150. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13151. {
  13152. //stop Transaction
  13153. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13154. }
  13155. }
  13156. }
  13157. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13158. {
  13159. tempIndex = connectorIdInt -1;
  13160. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13161. {
  13162. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13163. {
  13164. //stop Transaction
  13165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13166. }
  13167. }
  13168. }
  13169. else
  13170. {
  13171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13172. {
  13173. tempIndex = 2;
  13174. }
  13175. else
  13176. {
  13177. tempIndex = connectorIdInt-1;
  13178. }
  13179. for (int index = 0; index < AC_QUANTITY; index++)
  13180. {
  13181. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13182. {
  13183. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13184. }
  13185. }
  13186. }
  13187. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13188. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13189. result = TRUE;
  13190. return result;
  13191. }
  13192. end:
  13193. //json_object_put(obj); --- remove temporally
  13194. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13195. return result;
  13196. }
  13197. static char UpdateFirmwarepayloadData[300]={0};
  13198. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13199. {
  13200. mtrace();
  13201. int result = FAIL;
  13202. pthread_t t;
  13203. sendUpdateFirmwareConfirmation(uuid);
  13204. memset(UpdateFirmwarepayloadData, 0, 300);
  13205. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13206. if(!interLock.isUpdateFirmwareGoing)
  13207. {
  13208. interLock.isUpdateFirmwareGoing = 1;
  13209. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13210. sleep(1);
  13211. }
  13212. else
  13213. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13214. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13215. return result;
  13216. }
  13217. void *UpdateFirmwareProcess(void *data)
  13218. {
  13219. pthread_detach(pthread_self());
  13220. mtrace();
  13221. int retriesInt =0, retryIntervalInt=0;
  13222. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13223. int port=0;
  13224. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13225. int isSuccess = 0;
  13226. char ftpbuf[1024];
  13227. char temp[1024];
  13228. char * pch;
  13229. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13230. json_object *UpdateFirmware;
  13231. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13232. if(!is_error(UpdateFirmware))
  13233. {
  13234. // Required data
  13235. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13236. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13237. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13238. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13239. // Optional data
  13240. if(json_object_object_get(UpdateFirmware, "retries"))
  13241. {
  13242. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13243. }
  13244. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13245. {
  13246. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13247. }
  13248. }
  13249. json_object_put(UpdateFirmware);
  13250. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13251. memset(path, 0, ARRAY_SIZE(path));
  13252. // Wait retrieveData
  13253. if(strlen(retrieveDatestr) > 10)
  13254. {
  13255. do
  13256. {
  13257. sleep(1);
  13258. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13259. }
  13260. // Ready to download
  13261. system("rm -f /mnt/*");
  13262. if(strncmp(locationstr,"http", 4) == 0)
  13263. {
  13264. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13265. sprintf(ftppath,"/%s", path);
  13266. DEBUG_INFO("locationstr: %s\n", locationstr);
  13267. DEBUG_INFO("protocol: %s\n",protocol);
  13268. DEBUG_INFO("host: %s\n",host);
  13269. DEBUG_INFO("path: %s\n",path);
  13270. DEBUG_INFO("ftppath: %s\n",ftppath);
  13271. int ftppathlen=strlen(ftppath);
  13272. int i=1;
  13273. char filenametemp[50];
  13274. while(i < ftppathlen)
  13275. {
  13276. int len=ftppathlen-i;
  13277. if(ftppath[len]== 47) // '/' ascll code: 47
  13278. {
  13279. DEBUG_INFO("compare '/' all right\n");
  13280. break;
  13281. }
  13282. i=i+1;
  13283. }
  13284. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13285. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13286. filenametemp[i+1] = 0;
  13287. do
  13288. {
  13289. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13290. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13291. sleep(1);
  13292. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13293. if(!isSuccess)
  13294. {
  13295. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13296. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13297. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13298. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13299. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13300. }
  13301. else
  13302. {
  13303. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13304. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13305. }
  13306. retriesInt--;
  13307. }while((isSuccess == 0)&&(retriesInt >= 0));
  13308. }
  13309. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13310. {
  13311. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13312. memset(temp, 0, ARRAY_SIZE(temp));
  13313. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13314. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13315. int ftppathlen=strlen(ftpbuf);
  13316. int i=1;
  13317. char filenametemp[50];
  13318. while(i < ftppathlen)
  13319. {
  13320. int len=ftppathlen-i;
  13321. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13322. {
  13323. DEBUG_INFO(" compare '/' all right\n");
  13324. break;
  13325. }
  13326. i=i+1;
  13327. }
  13328. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13329. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13330. filenametemp[i+1] = 0;
  13331. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13332. pch=strchr(temp,'@');
  13333. if(pch==NULL)
  13334. {
  13335. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13336. protocol, host, &port, path);
  13337. strcpy(user,"anonymous");
  13338. strcpy(password,"");
  13339. }
  13340. else
  13341. {
  13342. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13343. protocol, user, password, host, &port, path);
  13344. }
  13345. sscanf(host,"%[^/]%s",host1, path1);
  13346. sprintf(ftppath,"%s", path1);
  13347. //DEBUG_INFO("protocol =%s\n",protocol);
  13348. //DEBUG_INFO("user =%s\n",user);
  13349. //DEBUG_INFO("password =%s\n",password);
  13350. //DEBUG_INFO("host1 =%s\n",host1);
  13351. //DEBUG_INFO("port =%d\n",port);
  13352. //DEBUG_INFO("path1 =%s\n",path1);
  13353. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13354. //ftpFile(host, user, password, port, ftppath, fname);
  13355. //download firmware pthred
  13356. if(port == 0)
  13357. {
  13358. port = 21;
  13359. }
  13360. do
  13361. {
  13362. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13363. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13364. sleep(1);
  13365. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13366. if(!isSuccess)
  13367. {
  13368. //BulldogUtil.sleepMs(interval*1000);
  13369. DEBUG_INFO("Update firmware request and download file fail.\n");
  13370. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13371. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13372. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13373. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13374. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13375. }
  13376. else
  13377. {
  13378. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13379. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13380. }
  13381. retriesInt--;
  13382. }while((!isSuccess)&&(retriesInt >= 0));
  13383. }
  13384. else
  13385. {
  13386. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13387. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13388. sleep(1);
  13389. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13390. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13391. }
  13392. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13393. interLock.isUpdateFirmwareGoing = 0;
  13394. pthread_exit(NULL);
  13395. }
  13396. int handleCertificateSignedRequest(char *uuid, char *payload)
  13397. {
  13398. mtrace();
  13399. int result = PASS;
  13400. json_object *CertificateSigned;
  13401. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13402. CertificateSigned = json_tokener_parse(payload);
  13403. if(!is_error(CertificateSigned))
  13404. {
  13405. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13406. }
  13407. json_object_put(CertificateSigned);
  13408. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13409. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13410. fclose(fp);
  13411. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13412. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13413. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13414. sendCertificateSignedConfirmation(uuid);
  13415. return result;
  13416. }
  13417. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13418. {
  13419. mtrace();
  13420. int result = PASS;
  13421. json_object *DeleteCertificate;
  13422. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13423. DeleteCertificate = json_tokener_parse(payload);
  13424. if(!is_error(DeleteCertificate))
  13425. {
  13426. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13427. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13428. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13429. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13430. }
  13431. json_object_put(DeleteCertificate);
  13432. /*
  13433. * TODO: Delete certificateSigned process
  13434. */
  13435. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13436. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13437. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13438. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13439. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13440. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13441. sendDeleteCertificateConfirmation(uuid);
  13442. return result;
  13443. }
  13444. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13445. {
  13446. mtrace();
  13447. int result = PASS;
  13448. json_object *ExtendedTriggerMessage;
  13449. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13450. ExtendedTriggerMessage = json_tokener_parse(payload);
  13451. if(!is_error(ExtendedTriggerMessage))
  13452. {
  13453. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13454. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13455. {
  13456. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13457. }
  13458. else
  13459. {
  13460. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13461. }
  13462. }
  13463. json_object_put(ExtendedTriggerMessage);
  13464. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13465. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13466. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13467. {
  13468. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13469. }
  13470. else
  13471. {
  13472. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13473. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13474. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13475. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13476. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13477. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13478. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13479. {
  13480. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13481. }
  13482. else
  13483. {
  13484. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13485. }
  13486. }
  13487. sendExtendedTriggerMessageConfirmation(uuid);
  13488. //==========================
  13489. // Trigger message
  13490. //==========================
  13491. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13492. {
  13493. //sendBootNotificationRequest();
  13494. server_sign = FALSE;
  13495. }
  13496. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13497. {
  13498. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13499. }
  13500. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13501. {
  13502. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13503. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13504. {
  13505. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13506. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13507. }
  13508. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13509. }
  13510. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13511. {
  13512. refreshStartTimer(&clientTime.Heartbeat);
  13513. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13514. }
  13515. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13516. {
  13517. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13518. {
  13519. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13520. }
  13521. else
  13522. {
  13523. for(int idx=0;idx< gunTotalNumber;idx++)
  13524. {
  13525. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13526. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13527. }
  13528. }
  13529. }
  13530. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13531. {
  13532. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13533. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13534. {
  13535. 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\" &");
  13536. }
  13537. }
  13538. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13539. {
  13540. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13541. {
  13542. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13543. }
  13544. else
  13545. {
  13546. for(int idx=0;idx< gunTotalNumber;idx++)
  13547. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13548. }
  13549. }
  13550. return result;
  13551. }
  13552. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13553. {
  13554. mtrace();
  13555. int result = PASS;
  13556. json_object *GetInstalledCertificateIds;
  13557. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13558. GetInstalledCertificateIds = json_tokener_parse(payload);
  13559. if(!is_error(GetInstalledCertificateIds))
  13560. {
  13561. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13562. }
  13563. json_object_put(GetInstalledCertificateIds);
  13564. /*
  13565. * TODO: Return installed certificate process
  13566. */
  13567. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13568. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13569. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13570. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13571. sendGetInstalledCertificateIdsConfirmation(uuid);
  13572. return result;
  13573. }
  13574. int handleGetLogRequest(char *uuid, char *payload)
  13575. {
  13576. mtrace();
  13577. int result = PASS;
  13578. json_object *GetLog;
  13579. DEBUG_INFO("handleGetLogRequest...\n");
  13580. GetLog = json_tokener_parse(payload);
  13581. if(!is_error(GetLog))
  13582. {
  13583. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13584. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13585. if(json_object_object_get(GetLog, "retries") != NULL)
  13586. {
  13587. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13588. }
  13589. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13590. {
  13591. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13592. }
  13593. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13594. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13595. {
  13596. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13597. }
  13598. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13599. {
  13600. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13601. }
  13602. }
  13603. json_object_put(GetLog);
  13604. /*
  13605. * TODO: Upload log process
  13606. */
  13607. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13608. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13609. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13610. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13611. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13612. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13613. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13614. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13615. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13616. sendGetLogConfirmation(uuid);
  13617. return result;
  13618. }
  13619. int handleInstallCertificateRequest(char *uuid, char *payload)
  13620. {
  13621. mtrace();
  13622. int result = PASS;
  13623. json_object *InstallCertificate;
  13624. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13625. InstallCertificate = json_tokener_parse(payload);
  13626. if(!is_error(InstallCertificate))
  13627. {
  13628. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13629. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13630. /*
  13631. * TODO: Install certificate process
  13632. */
  13633. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13634. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13635. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13636. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13637. sendInstallCertificateConfirmation(uuid);
  13638. }
  13639. json_object_put(InstallCertificate);
  13640. return result;
  13641. }
  13642. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13643. {
  13644. mtrace();
  13645. int result = PASS;
  13646. json_object *SignedUpdateFirmware;
  13647. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13648. SignedUpdateFirmware = json_tokener_parse(payload);
  13649. if(!is_error(SignedUpdateFirmware))
  13650. {
  13651. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13652. {
  13653. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13654. }
  13655. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13656. {
  13657. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13658. }
  13659. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13660. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13661. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13662. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13663. {
  13664. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13665. }
  13666. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13667. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13668. }
  13669. json_object_put(SignedUpdateFirmware);
  13670. /*
  13671. * TODO: Upgrade firmware process
  13672. */
  13673. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13674. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13675. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13676. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13677. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13678. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13679. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13680. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13681. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13682. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13683. sendInstallCertificateConfirmation(uuid);
  13684. return result;
  13685. }
  13686. int handleUnknownRequest(char *uuid, char *payload)
  13687. {
  13688. mtrace();
  13689. int result = PASS;
  13690. DEBUG_INFO("handleUnknownRequest...\n");
  13691. sendUnknownConfirmation(uuid);
  13692. result = PASS;
  13693. return result;
  13694. }
  13695. //==========================================
  13696. // Handle server response routine
  13697. //==========================================
  13698. void handleAuthorizeResponse(char *payload, int gun_index)
  13699. {
  13700. mtrace();
  13701. char expiryDatestr[36]={0};
  13702. char parentIdTagstr[21]={0};
  13703. char statusstr[20]={0};
  13704. int expiryDateISNULL=FALSE;
  13705. int parentIdTagISNULL=FALSE;
  13706. DEBUG_INFO("handleAuthorizeResponse...\n");
  13707. json_object *Authorize;
  13708. Authorize = json_tokener_parse(payload);
  13709. if(!is_error(Authorize))
  13710. {
  13711. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13712. {
  13713. // Required data
  13714. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13715. // Optional data
  13716. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13717. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13718. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13719. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13720. }
  13721. }
  13722. json_object_put(Authorize);
  13723. if(expiryDateISNULL == FALSE)
  13724. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13725. if(parentIdTagISNULL == FALSE)
  13726. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13727. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13728. //Update idTag information to authorization cache if supproted
  13729. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13730. {
  13731. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13732. }
  13733. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13734. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13735. authorizeRetryTimes = 0;
  13736. }
  13737. void handleBootNotificationResponse(char *payload, int gun_index)
  13738. {
  13739. mtrace();
  13740. char statusStr[12]={0};
  13741. char currentTimeStr[30]={0};
  13742. int intervalInt = 0;
  13743. DEBUG_INFO("handleBootNotificationResponse...\n");
  13744. json_object *BootNotification;
  13745. BootNotification = json_tokener_parse(payload);
  13746. if(!is_error(BootNotification))
  13747. {
  13748. // Required data
  13749. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13750. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13751. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13752. }
  13753. json_object_put(BootNotification);
  13754. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13755. BootNotificationInterval = intervalInt;
  13756. //write back to ShmOCPP16Data->BootNotification
  13757. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13758. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13759. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13760. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13761. {
  13762. BootNotificationInterval = 0;
  13763. if((intervalInt == 0) || (intervalInt >= 10))
  13764. {
  13765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13766. HeartBeatWaitTime = intervalInt;
  13767. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13768. }
  13769. server_sign = TRUE;
  13770. server_pending =FALSE;
  13771. }
  13772. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13773. {
  13774. server_pending = TRUE;
  13775. }
  13776. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13777. srand(time(NULL));
  13778. refreshStartTimer(&clientTime.Heartbeat);
  13779. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13780. SetOcppConnStatus(TRUE);
  13781. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13782. }
  13783. void handleDataTransferResponse(char *payload, int gun_index)
  13784. {
  13785. json_object *DataTransfer = json_tokener_parse(payload);
  13786. if(!is_error(DataTransfer))
  13787. {
  13788. // Required data
  13789. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13790. // Optional data
  13791. if(json_object_object_get(DataTransfer, "data") != NULL)
  13792. {
  13793. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13794. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13795. if(!is_error(Data))
  13796. {
  13797. if(json_object_object_get(Data, "msgId") != NULL)
  13798. {
  13799. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13800. {
  13801. 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")));
  13802. }
  13803. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13804. {
  13805. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13806. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13807. }
  13808. }
  13809. }
  13810. json_object_put(Data);
  13811. }
  13812. }
  13813. json_object_put(DataTransfer);
  13814. }
  13815. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13816. {
  13817. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13818. //struct json_object *obj;
  13819. // obj = json_tokener_parse(payload);
  13820. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13821. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13822. //No fields are defined.
  13823. }
  13824. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13825. {
  13826. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13827. //struct json_object *obj;
  13828. // obj = json_tokener_parse(payload);
  13829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13830. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13831. //No fields are defined.
  13832. }
  13833. void handleHeartbeatResponse(char *payload, int gun_index)
  13834. {
  13835. mtrace();
  13836. DEBUG_INFO("handleHeartbeatResponse...\n");
  13837. json_object *Heartbeat;
  13838. Heartbeat = json_tokener_parse(payload);
  13839. if(!is_error(Heartbeat))
  13840. {
  13841. // Required data
  13842. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13843. }
  13844. json_object_put(Heartbeat);
  13845. if(FirstHeartBeat == 0)
  13846. {
  13847. FirstHeartBeat = 1;
  13848. DEBUG_INFO("FirstHeartBeat \n");
  13849. }
  13850. HeartBeatWithNOResponse = 0;
  13851. refreshStartTimer(&clientTime.Heartbeat);
  13852. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13853. }
  13854. void handleMeterValuesResponse(char *payload, int gun_index)
  13855. {
  13856. mtrace();
  13857. DEBUG_INFO("handleMeterValuesResponse...\n");
  13858. isQueueSendable = 1;
  13859. }
  13860. void handleStartTransactionResponse(char *payload, int gun_index)
  13861. {
  13862. mtrace();
  13863. //int transactionIdInt = 0;
  13864. FILE *outfile;
  13865. char data[100]={0};
  13866. DEBUG_INFO("handleStartTransactionResponse...\n");
  13867. json_object *StartTransaction;
  13868. StartTransaction = json_tokener_parse(payload);
  13869. if(!is_error(StartTransaction))
  13870. {
  13871. // Required data
  13872. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13873. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13874. // Optional data
  13875. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13876. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13877. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13878. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13879. }
  13880. json_object_put(StartTransaction);
  13881. isQueueSendable = 1;
  13882. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13883. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13884. //-----------Start : write to the Queue TransactionId file -----------------//
  13885. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13886. {}
  13887. else
  13888. {
  13889. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13890. if(log == NULL)
  13891. {
  13892. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13893. return ;
  13894. }
  13895. else
  13896. {
  13897. fclose(log);
  13898. }
  13899. }
  13900. // open file for writing
  13901. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13902. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13903. {
  13904. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13905. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13906. fputs(data, outfile);
  13907. fclose (outfile);
  13908. }
  13909. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13910. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13911. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13912. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13913. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13914. }
  13915. void handleStatusNotificationResponse(char *payload, int gun_index)
  13916. {
  13917. mtrace();
  13918. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13919. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13920. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13921. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13922. }
  13923. void handleStopTransactionnResponse(char *payload, int gun_index)
  13924. {
  13925. mtrace();
  13926. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13927. json_object *StopTransaction;
  13928. StopTransaction = json_tokener_parse(payload);
  13929. if(!is_error(StopTransaction))
  13930. {
  13931. // Optional data
  13932. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13933. {
  13934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13935. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13937. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13939. }
  13940. }
  13941. json_object_put(StopTransaction);
  13942. isQueueSendable = 1;
  13943. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13944. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13945. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13946. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13947. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13948. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13949. }
  13950. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13951. {
  13952. mtrace();
  13953. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13954. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13955. }
  13956. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13957. {
  13958. mtrace();
  13959. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13960. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13961. }
  13962. void handleSignCertificateResponse(char *payload, int gun_index)
  13963. {
  13964. mtrace();
  13965. DEBUG_INFO("handleSignCertificateResponse...\n");
  13966. json_object *SignCertificate;
  13967. SignCertificate = json_tokener_parse(payload);
  13968. if(!is_error(SignCertificate))
  13969. {
  13970. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13971. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13972. }
  13973. json_object_put(SignCertificate);
  13974. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13975. }
  13976. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13977. {
  13978. mtrace();
  13979. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13980. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13981. }
  13982. //==========================================
  13983. // Handle Error routine
  13984. //==========================================
  13985. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13986. {
  13987. mtrace();
  13988. #ifdef SystemLogMessage
  13989. DEBUG_INFO("errorCode: %s\n", errorCode);
  13990. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13991. DEBUG_INFO("errorDetails: %s\n", payload);
  13992. #endif
  13993. }
  13994. //===============================================
  13995. // Common routine
  13996. //===============================================
  13997. int initialConfigurationTable(void)
  13998. {
  13999. //clock_t start_t, end_t, total_t;
  14000. FILE *fp;
  14001. FILE *outfile;
  14002. char str[512]={0};
  14003. char sstr[256]={0};
  14004. int c = 0;
  14005. char *loc;
  14006. int confVersion = 15;
  14007. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14008. //start_t = clock();
  14009. //printf("Starting of the program, start_t = %ld\n", start_t);
  14010. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14011. // Check configuration file size is correct
  14012. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14013. {
  14014. struct stat st;
  14015. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14016. if(st.st_size < 3100)
  14017. {
  14018. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14019. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14020. }
  14021. }
  14022. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14023. {
  14024. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14025. if(outfile == NULL)
  14026. {
  14027. DEBUG_INFO("Error opening file\n");
  14028. return FALSE;
  14029. }
  14030. /*Core Profile*/
  14031. //AllowOfflineTxForUnknownId
  14032. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14036. //AuthorizationCacheEnabled
  14037. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14041. //AuthorizeRemoteTxRequests
  14042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14046. //BlinkRepeat
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14051. //ClockAlignedDataInterval
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14056. //ConnectionTimeOut
  14057. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14061. //GetConfigurationMaxKeys
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14066. // HeartbeatInterval
  14067. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14071. // LightIntensity
  14072. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14076. // LocalAuthorizeOffline
  14077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14081. // LocalPreAuthorize
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14086. // MaxEnergyOnInvalidId
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14091. // MeterValuesAlignedData
  14092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14095. 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" );
  14096. else
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14099. // MeterValuesAlignedDataMaxLength
  14100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14102. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14104. else
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14107. // MeterValuesSampledData
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14111. 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" );
  14112. else
  14113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14115. // MeterValuesSampledDataMaxLength
  14116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14120. else
  14121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14123. // MeterValueSampleInterval
  14124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14128. // MinimumStatusDuration
  14129. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14132. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14134. // NumberOfConnectors
  14135. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14138. {
  14139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14140. }
  14141. else
  14142. {
  14143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14144. }
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14146. // ResetRetries
  14147. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14151. // ConnectorPhaseRotation
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14156. // ConnectorPhaseRotationMaxLength
  14157. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14161. // StopTransactionOnEVSideDisconnect
  14162. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14166. // StopTransactionOnInvalidId
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14171. // StopTxnAlignedData
  14172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14176. // StopTxnAlignedDataMaxLength
  14177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14181. // StopTxnSampledData
  14182. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14186. else
  14187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14189. // StopTxnSampledDataMaxLength
  14190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14193. {
  14194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14195. }
  14196. else
  14197. {
  14198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14199. }
  14200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14201. // SupportedFeatureProfiles
  14202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14206. // SupportedFeatureProfilesMaxLength
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14211. // TransactionMessageAttempts
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14215. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14217. // TransactionMessageRetryInterval
  14218. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14221. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14223. // UnlockConnectorOnEVSideDisconnect
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14228. // WebSocketPingInterval
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14233. // QueueOffLineMeterValues
  14234. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14238. // AuthorizationKey
  14239. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14243. // SecurityProfile
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14248. // DefaultPrice
  14249. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14253. // CustomDisplayCostAndPrice
  14254. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14258. // CustomIdleFeeAfterStop
  14259. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14263. // TimeOffset
  14264. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14268. // NextTimeOffsetTransitionDateTime
  14269. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14273. // TimeOffsetNextTransition
  14274. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14278. // SystemUptimeSec
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14283. // FreeVend
  14284. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14288. // FreeVendIdtag
  14289. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14293. // OcppServer
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14296. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14298. // MaintainServer
  14299. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14301. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14303. // StatusNotificationPeriodically
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14308. // StatusNotificationInterval
  14309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14313. // PreAuthAmount
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14318. // isEnableLocalPowerSharing
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14323. // PowerSharingServerIP
  14324. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14326. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14328. // EVCCID_PREFIX
  14329. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14333. // Configuration Version
  14334. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14338. //* Local Auth List Management Profile*/
  14339. #if 0
  14340. //For OCTT Test Case
  14341. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14344. #endif
  14345. #if 1
  14346. //LocalAuthListEnabled
  14347. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14351. #endif
  14352. //LocalAuthListMaxLength
  14353. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14357. //SendLocalListMaxLength
  14358. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14362. //ReserveConnectorZeroSupported
  14363. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14367. //* Smart Charging Profile */
  14368. //ChargeProfileMaxStackLevel
  14369. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14373. // ChargingScheduleAllowedChargingRateUnit
  14374. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14378. // ChargingScheduleMaxPeriods
  14379. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14383. // ConnectorSwitch3to1PhaseSupported
  14384. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14388. // MaxChargingProfilesInstalled
  14389. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14393. fclose(outfile);
  14394. }
  14395. else
  14396. {
  14397. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14398. char keystr[60]={0};
  14399. char readonlystr[10]={0};
  14400. char valuestr[256]={0};
  14401. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14402. if(fp == NULL) {
  14403. DEBUG_INFO("Error opening file");
  14404. return FALSE;
  14405. }
  14406. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14407. {
  14408. //DEBUG_INFO("Get Configuration \n");
  14409. if(strlen(str) > 0)
  14410. {
  14411. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14412. //*************************key*********************************/
  14413. if(strstr(str, "key") != NULL)
  14414. {
  14415. loc = strstr(str, "key");
  14416. c = 0;
  14417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14418. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14419. {
  14420. sstr[c] = loc[strlen("key")+3+c];
  14421. c++;
  14422. }
  14423. sstr[c] = '\0';
  14424. strcpy(keystr,sstr);
  14425. }
  14426. //*************************readonly*********************************/
  14427. if(strstr(str, "readonly") != NULL)
  14428. {
  14429. loc = strstr(str, "readonly");
  14430. c = 0;
  14431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14432. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14433. {
  14434. sstr[c] = loc[strlen("readonly")+2+c];
  14435. c++;
  14436. }
  14437. sstr[c] = '\0';
  14438. strcpy(readonlystr,sstr);
  14439. }
  14440. //*************************value*********************************/
  14441. if(strstr(str, "value") != NULL)
  14442. {
  14443. loc = strstr(str, "value");
  14444. c = 0;
  14445. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14446. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14447. {
  14448. sstr[c] = loc[strlen("value")+3+c];
  14449. c++;
  14450. }
  14451. sstr[c] = '\0';
  14452. strcpy(valuestr,sstr);
  14453. }
  14454. // DEBUG_INFO("keystr=%s\n",keystr);
  14455. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14456. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14457. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14458. {
  14459. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14460. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14462. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14463. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14464. }
  14465. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14466. {
  14467. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14468. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14470. }
  14471. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14472. {
  14473. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14475. }
  14476. if(strcmp(keystr, "BlinkRepeat") == 0)
  14477. {
  14478. //Charger.BlinkRepeat = Integer.parseInt(value);
  14479. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14481. }
  14482. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14483. {
  14484. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14486. }
  14487. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14488. {
  14489. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14491. }
  14492. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14493. {
  14494. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14496. }
  14497. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14498. {
  14499. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14501. HeartBeatWaitTime = atoi(valuestr);
  14502. }
  14503. if(strcmp(keystr, "LightIntensity") == 0)
  14504. {
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14507. }
  14508. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14509. {
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14512. }
  14513. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14514. {
  14515. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14517. }
  14518. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14519. {
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14522. }
  14523. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14524. {
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14527. }
  14528. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14529. {
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14532. }
  14533. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14534. {
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14537. }
  14538. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14539. {
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14542. }
  14543. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14544. {
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14547. }
  14548. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14549. {
  14550. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14552. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14553. }
  14554. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14555. {
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14558. }
  14559. if(strcmp(keystr, "ResetRetries") == 0)
  14560. {
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14563. }
  14564. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14565. {
  14566. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14568. }
  14569. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14570. {
  14571. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14573. }
  14574. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14575. {
  14576. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14578. }
  14579. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14580. {
  14581. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14583. }
  14584. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14585. {
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14588. }
  14589. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14590. {
  14591. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14593. }
  14594. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14595. {
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14598. }
  14599. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14600. {
  14601. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14603. }
  14604. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14605. {
  14606. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14608. }
  14609. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14610. {
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14613. }
  14614. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14615. {
  14616. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14618. TransactionMessageAttemptsValue = atoi(valuestr);
  14619. }
  14620. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14621. {
  14622. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14624. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14625. }
  14626. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14627. {
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14630. }
  14631. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14632. {
  14633. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14635. }
  14636. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14637. {
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14640. }
  14641. if(strcmp(keystr, "AuthorizationKey") == 0)
  14642. {
  14643. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14644. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14646. }
  14647. if(strcmp(keystr, "SecurityProfile") == 0)
  14648. {
  14649. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14651. }
  14652. if(strcmp(keystr, "DefaultPrice") == 0)
  14653. {
  14654. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14656. }
  14657. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14658. {
  14659. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14661. }
  14662. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14663. {
  14664. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14666. }
  14667. if(strcmp(keystr, "TimeOffset") == 0)
  14668. {
  14669. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14671. }
  14672. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14673. {
  14674. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14676. }
  14677. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14678. {
  14679. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14681. }
  14682. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14683. {
  14684. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14686. }
  14687. if(strcmp(keystr, "FreeVend") == 0)
  14688. {
  14689. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14691. }
  14692. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14693. {
  14694. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14696. }
  14697. if(strcmp(keystr, "OcppServer") == 0)
  14698. {
  14699. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14700. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14701. }
  14702. if(strcmp(keystr, "MaintainServer") == 0)
  14703. {
  14704. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14705. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14706. }
  14707. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14708. {
  14709. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14711. }
  14712. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14713. {
  14714. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14716. }
  14717. if(strcmp(keystr, "PreAuthAmount") == 0)
  14718. {
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14721. }
  14722. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14723. {
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14726. }
  14727. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14728. {
  14729. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14731. }
  14732. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14733. {
  14734. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14736. }
  14737. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14738. {
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14741. }
  14742. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14743. {
  14744. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14746. }
  14747. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14748. {
  14749. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14751. }
  14752. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14753. {
  14754. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14756. }
  14757. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14758. {
  14759. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14761. }
  14762. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14763. {
  14764. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14766. }
  14767. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14768. {
  14769. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14771. }
  14772. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14773. {
  14774. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14776. }
  14777. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14778. {
  14779. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14781. }
  14782. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14783. {
  14784. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14786. }
  14787. }
  14788. }
  14789. fclose(fp);
  14790. }
  14791. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14792. {
  14793. return PASS;
  14794. }
  14795. else
  14796. {
  14797. return FAIL;
  14798. }
  14799. }
  14800. void StoreConfigurationTable(void)
  14801. {
  14802. FILE *outfile;
  14803. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14804. if(outfile == NULL)
  14805. {
  14806. DEBUG_INFO("Error opening file");
  14807. return ;
  14808. }
  14809. /*Core Profile*/
  14810. //AllowOfflineTxForUnknownId
  14811. /*
  14812. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14813. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14816. */
  14817. //DEBUG_INFO("data=%s\n",data);
  14818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14819. //AuthorizationCacheEnabled
  14820. /*
  14821. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14824. */
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14826. //AuthorizeRemoteTxRequests
  14827. /*
  14828. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14833. //BlinkRepeat
  14834. /*
  14835. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14840. //ClockAlignedDataInterval
  14841. /*
  14842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14847. //ConnectionTimeOut
  14848. /*
  14849. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14852. */
  14853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14854. //GetConfigurationMaxKeys
  14855. /*
  14856. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14859. */
  14860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14861. // HeartbeatInterval
  14862. /*
  14863. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14866. */
  14867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14868. // LightIntensity
  14869. /*
  14870. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14873. */
  14874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14875. // LocalAuthorizeOffline
  14876. /*
  14877. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14880. */
  14881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14882. // LocalPreAuthorize
  14883. /*
  14884. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14887. */
  14888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14889. // MaxEnergyOnInvalidId
  14890. /*
  14891. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14894. */
  14895. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14897. // MeterValuesAlignedData
  14898. /*
  14899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14902. */
  14903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14904. // MeterValuesAlignedDataMaxLength
  14905. /*
  14906. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14909. */
  14910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14911. // MeterValuesSampledData
  14912. /*
  14913. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14916. */
  14917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14918. // MeterValuesSampledDataMaxLength
  14919. /*
  14920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14923. */
  14924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14925. // MeterValueSampleInterval
  14926. /*
  14927. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14930. */
  14931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14932. // MinimumStatusDuration
  14933. /*
  14934. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14937. */
  14938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14939. // NumberOfConnectors
  14940. /*
  14941. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14943. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14944. {
  14945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14946. }
  14947. else
  14948. {
  14949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14950. }
  14951. */
  14952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14953. // ResetRetries
  14954. /*
  14955. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14958. */
  14959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14960. // ConnectorPhaseRotation
  14961. /*
  14962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14965. */
  14966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14967. // ConnectorPhaseRotationMaxLength
  14968. /*
  14969. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14972. */
  14973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14974. // StopTransactionOnEVSideDisconnect
  14975. /*
  14976. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14979. */
  14980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14981. // StopTransactionOnInvalidId
  14982. /*
  14983. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14986. */
  14987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14988. // StopTxnAlignedData
  14989. /*
  14990. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14993. */
  14994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14995. // StopTxnAlignedDataMaxLength
  14996. /*
  14997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15000. */
  15001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15002. // StopTxnSampledData
  15003. /*
  15004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15007. */
  15008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15009. // StopTxnSampledDataMaxLength
  15010. /*
  15011. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15014. */
  15015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15016. // SupportedFeatureProfiles
  15017. /*
  15018. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15021. */
  15022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15023. // SupportedFeatureProfilesMaxLength
  15024. /*
  15025. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15028. */
  15029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15030. // TransactionMessageAttempts
  15031. /*
  15032. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15035. */
  15036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15037. // TransactionMessageRetryInterval
  15038. /*
  15039. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15042. */
  15043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15044. // UnlockConnectorOnEVSideDisconnect
  15045. /*
  15046. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15049. */
  15050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15051. // WebSocketPingInterval
  15052. /*
  15053. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15056. */
  15057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15058. // QueueOffLineMeterValues
  15059. /*
  15060. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15063. */
  15064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15065. // AuthorizationKey
  15066. /*
  15067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15070. */
  15071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15072. // SecurityProfile
  15073. /*
  15074. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15077. */
  15078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15079. // DefaultPrice
  15080. /*
  15081. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15084. */
  15085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15086. // CustomDisplayCostAndPrice
  15087. /*
  15088. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15091. */
  15092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15093. // CustomIdleFeeAfterStop
  15094. /*
  15095. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15098. */
  15099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15100. // TimeOffset
  15101. /*
  15102. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15105. */
  15106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15107. // NextTimeOffsetTransitionDateTime
  15108. /*
  15109. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15112. */
  15113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15114. // TimeOffsetNextTransition
  15115. /*
  15116. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15119. */
  15120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15121. // SystemUptimeSec
  15122. /*
  15123. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15126. */
  15127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15128. // FreeVend
  15129. /*
  15130. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15133. */
  15134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15135. // FreeVendIdtag
  15136. /*
  15137. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15140. */
  15141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15142. // OcppServer
  15143. /*
  15144. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15147. */
  15148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15149. // MaintainServer
  15150. /*
  15151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15154. */
  15155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15156. // StatusNotificationPeriodically
  15157. /*
  15158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15161. */
  15162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15163. // StatusNotificationInterval
  15164. /*
  15165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15168. */
  15169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15170. // PreAuthAmount
  15171. /*
  15172. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15175. */
  15176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15177. // isEnableLocalPowerSharing
  15178. /*
  15179. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15182. */
  15183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15184. // PowerSharingServerIP
  15185. /*
  15186. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15189. */
  15190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15191. // EVCCID_PREFIX
  15192. /*
  15193. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15196. */
  15197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15198. // ConfigurationVersion
  15199. /*
  15200. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15203. */
  15204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15205. //* Local Auth List Management Profile*/
  15206. //LocalAuthListEnabled
  15207. /*
  15208. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15211. */
  15212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15213. //LocalAuthListMaxLength
  15214. /*
  15215. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15218. */
  15219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15220. //SendLocalListMaxLength
  15221. /*
  15222. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15225. */
  15226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15227. //ReserveConnectorZeroSupported
  15228. /*
  15229. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15232. */
  15233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15234. //* Smart Charging Profile */
  15235. //ChargeProfileMaxStackLevel
  15236. /*
  15237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15240. */
  15241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15242. // ChargingScheduleAllowedChargingRateUnit
  15243. /*
  15244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15247. */
  15248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15249. // ChargingScheduleMaxPeriods
  15250. /*
  15251. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15254. */
  15255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15256. // ConnectorSwitch3to1PhaseSupported
  15257. /*
  15258. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15261. */
  15262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15263. // MaxChargingProfilesInstalled
  15264. /*
  15265. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15268. */
  15269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15270. fclose(outfile);
  15271. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15272. }
  15273. void getKeyValue(char *keyReq)
  15274. {
  15275. int isEmpty = FALSE;
  15276. int isKnowKey = FALSE;
  15277. DEBUG_INFO("keyReq = %s\n", keyReq);
  15278. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15279. isEmpty = TRUE;
  15280. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15285. {
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15287. }
  15288. else
  15289. {
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15291. }
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15293. isKnowKey = TRUE;
  15294. }
  15295. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15300. {
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15302. }
  15303. else
  15304. {
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15306. }
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15308. isKnowKey = TRUE;
  15309. }
  15310. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15315. {
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15317. }
  15318. else
  15319. {
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15321. }
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15323. isKnowKey = TRUE;
  15324. }
  15325. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15326. {
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15330. {
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15332. }
  15333. else
  15334. {
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15336. }
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15338. isKnowKey = TRUE;
  15339. }
  15340. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15341. {
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15345. {
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15351. }
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15353. isKnowKey = TRUE;
  15354. }
  15355. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15356. {
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15360. {
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15362. }
  15363. else
  15364. {
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15366. }
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15368. isKnowKey = TRUE;
  15369. }
  15370. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15371. {
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15375. {
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15377. }
  15378. else
  15379. {
  15380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15381. }
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15383. isKnowKey = TRUE;
  15384. }
  15385. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15386. {
  15387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15390. {
  15391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15392. }
  15393. else
  15394. {
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15396. }
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15398. isKnowKey = TRUE;
  15399. }
  15400. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15401. {
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15405. {
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15407. }
  15408. else
  15409. {
  15410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15411. }
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15413. isKnowKey = TRUE;
  15414. }
  15415. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15416. {
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15420. {
  15421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15422. }
  15423. else
  15424. {
  15425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15426. }
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15428. isKnowKey = TRUE;
  15429. }
  15430. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15431. {
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15435. {
  15436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15437. }
  15438. else
  15439. {
  15440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15441. }
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15443. isKnowKey = TRUE;
  15444. }
  15445. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15446. {
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15450. {
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15452. }
  15453. else
  15454. {
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15456. }
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15458. isKnowKey = TRUE;
  15459. }
  15460. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15465. {
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15467. }
  15468. else
  15469. {
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15471. }
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15473. isKnowKey = TRUE;
  15474. }
  15475. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15480. {
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15482. }
  15483. else
  15484. {
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15486. }
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15488. isKnowKey = TRUE;
  15489. }
  15490. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15497. }
  15498. else
  15499. {
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15501. }
  15502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15503. isKnowKey = TRUE;
  15504. }
  15505. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15512. }
  15513. else
  15514. {
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15516. }
  15517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15518. isKnowKey = TRUE;
  15519. }
  15520. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15527. }
  15528. else
  15529. {
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15531. }
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15533. isKnowKey = TRUE;
  15534. }
  15535. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15542. }
  15543. else
  15544. {
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15546. }
  15547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15548. isKnowKey = TRUE;
  15549. }
  15550. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15557. }
  15558. else
  15559. {
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15561. }
  15562. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15564. isKnowKey = TRUE;
  15565. }
  15566. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15567. {
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15571. {
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15573. }
  15574. else
  15575. {
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15577. }
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15579. isKnowKey = TRUE;
  15580. }
  15581. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15586. {
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15588. }
  15589. else
  15590. {
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15592. }
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15594. isKnowKey = TRUE;
  15595. }
  15596. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15601. {
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15603. }
  15604. else
  15605. {
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15607. }
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15609. isKnowKey = TRUE;
  15610. }
  15611. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15612. {
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15616. {
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15618. }
  15619. else
  15620. {
  15621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15622. }
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15624. isKnowKey = TRUE;
  15625. }
  15626. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15627. {
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15631. {
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15633. }
  15634. else
  15635. {
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15637. }
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15639. isKnowKey = TRUE;
  15640. }
  15641. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15642. {
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15646. {
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15648. }
  15649. else
  15650. {
  15651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15652. }
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15654. isKnowKey = TRUE;
  15655. }
  15656. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15657. {
  15658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15661. {
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15663. }
  15664. else
  15665. {
  15666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15667. }
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15669. isKnowKey = TRUE;
  15670. }
  15671. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15672. {
  15673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15676. {
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15678. }
  15679. else
  15680. {
  15681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15682. }
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15684. isKnowKey = TRUE;
  15685. }
  15686. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15687. {
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15691. {
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15693. }
  15694. else
  15695. {
  15696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15697. }
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15699. isKnowKey = TRUE;
  15700. }
  15701. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15702. {
  15703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15706. {
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15708. }
  15709. else
  15710. {
  15711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15712. }
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15714. isKnowKey = TRUE;
  15715. }
  15716. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15717. {
  15718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15721. {
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15723. }
  15724. else
  15725. {
  15726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15727. }
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15729. isKnowKey = TRUE;
  15730. }
  15731. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15732. {
  15733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15736. {
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15738. }
  15739. else
  15740. {
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15742. }
  15743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15744. isKnowKey = TRUE;
  15745. }
  15746. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15747. {
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15751. {
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15753. }
  15754. else
  15755. {
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15757. }
  15758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15759. isKnowKey = TRUE;
  15760. }
  15761. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15766. {
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15768. }
  15769. else
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15772. }
  15773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15774. isKnowKey = TRUE;
  15775. }
  15776. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15783. }
  15784. else
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15787. }
  15788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15789. isKnowKey = TRUE;
  15790. }
  15791. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15798. }
  15799. else
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15802. }
  15803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15804. isKnowKey = TRUE;
  15805. }
  15806. /*
  15807. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15808. {
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15812. {
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15814. }
  15815. else
  15816. {
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15818. }
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15820. isKnowKey = TRUE;
  15821. }*/
  15822. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15823. {
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15827. {
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15829. }
  15830. else
  15831. {
  15832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15833. }
  15834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15835. isKnowKey = TRUE;
  15836. }
  15837. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15838. {
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15842. {
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15844. }
  15845. else
  15846. {
  15847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15848. }
  15849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15850. isKnowKey = TRUE;
  15851. }
  15852. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15853. {
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15857. {
  15858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15859. }
  15860. else
  15861. {
  15862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15863. }
  15864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15865. isKnowKey = TRUE;
  15866. }
  15867. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15868. {
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15872. {
  15873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15874. }
  15875. else
  15876. {
  15877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15878. }
  15879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15880. isKnowKey = TRUE;
  15881. }
  15882. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15883. {
  15884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15887. {
  15888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15889. }
  15890. else
  15891. {
  15892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15893. }
  15894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15895. isKnowKey = TRUE;
  15896. }
  15897. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15898. {
  15899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15902. {
  15903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15904. }
  15905. else
  15906. {
  15907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15908. }
  15909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15910. isKnowKey = TRUE;
  15911. }
  15912. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15913. {
  15914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15917. {
  15918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15919. }
  15920. else
  15921. {
  15922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15923. }
  15924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15925. isKnowKey = TRUE;
  15926. }
  15927. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15928. {
  15929. struct sysinfo s_info;
  15930. int error = sysinfo(&s_info);
  15931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15934. {
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15936. }
  15937. else
  15938. {
  15939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15940. }
  15941. if(error != 0)
  15942. {
  15943. DEBUG_WARN("System uptime get error: %d\n", error);
  15944. }
  15945. else
  15946. {
  15947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15948. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15949. }
  15950. isKnowKey = TRUE;
  15951. }
  15952. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15953. {
  15954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15957. {
  15958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15959. }
  15960. else
  15961. {
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15963. }
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15965. isKnowKey = TRUE;
  15966. }
  15967. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15968. {
  15969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15972. {
  15973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15974. }
  15975. else
  15976. {
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15978. }
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15980. isKnowKey = TRUE;
  15981. }
  15982. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15983. {
  15984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15987. {
  15988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15989. }
  15990. else
  15991. {
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15993. }
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15995. isKnowKey = TRUE;
  15996. }
  15997. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15998. {
  15999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16002. {
  16003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16004. }
  16005. else
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16008. }
  16009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16010. isKnowKey = TRUE;
  16011. }
  16012. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16013. {
  16014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16017. {
  16018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16019. }
  16020. else
  16021. {
  16022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16023. }
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16025. isKnowKey = TRUE;
  16026. }
  16027. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16028. {
  16029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16032. {
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16034. }
  16035. else
  16036. {
  16037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16038. }
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16040. isKnowKey = TRUE;
  16041. }
  16042. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16043. {
  16044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16047. {
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16049. }
  16050. else
  16051. {
  16052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16053. }
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16055. isKnowKey = TRUE;
  16056. }
  16057. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16058. {
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16062. {
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16064. }
  16065. else
  16066. {
  16067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16068. }
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16070. isKnowKey = TRUE;
  16071. }
  16072. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16073. {
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16077. {
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16079. }
  16080. else
  16081. {
  16082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16083. }
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16085. isKnowKey = TRUE;
  16086. }
  16087. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16088. {
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16092. {
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16094. }
  16095. else
  16096. {
  16097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16098. }
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16100. isKnowKey = TRUE;
  16101. }
  16102. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16103. {
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16107. {
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16109. }
  16110. else
  16111. {
  16112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16113. }
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16115. isKnowKey = TRUE;
  16116. }
  16117. #if 1
  16118. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16119. {
  16120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16123. {
  16124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16125. }
  16126. else
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16129. }
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16131. isKnowKey = TRUE;
  16132. }
  16133. #endif
  16134. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16135. {
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16138. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16139. {
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16141. }
  16142. else
  16143. {
  16144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16145. }
  16146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16147. isKnowKey = TRUE;
  16148. }
  16149. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16150. {
  16151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16153. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16154. {
  16155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16156. }
  16157. else
  16158. {
  16159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16160. }
  16161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16162. isKnowKey = TRUE;
  16163. }
  16164. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16165. {
  16166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16168. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16169. {
  16170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16171. }
  16172. else
  16173. {
  16174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16175. }
  16176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16177. isKnowKey = TRUE;
  16178. }
  16179. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16180. {
  16181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16183. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16184. {
  16185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16186. }
  16187. else
  16188. {
  16189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16190. }
  16191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16192. isKnowKey = TRUE;
  16193. }
  16194. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16195. {
  16196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16198. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16199. {
  16200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16201. }
  16202. else
  16203. {
  16204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16205. }
  16206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16207. isKnowKey = TRUE;
  16208. }
  16209. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16210. {
  16211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16213. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16214. {
  16215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16216. }
  16217. else
  16218. {
  16219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16220. }
  16221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16222. isKnowKey = TRUE;
  16223. }
  16224. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16225. {
  16226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16228. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16229. {
  16230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16231. }
  16232. else
  16233. {
  16234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16235. }
  16236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16237. isKnowKey = TRUE;
  16238. }
  16239. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16240. {
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16243. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16244. {
  16245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16246. }
  16247. else
  16248. {
  16249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16250. }
  16251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16252. isKnowKey = TRUE;
  16253. }
  16254. //=========================================================
  16255. if(!isEmpty && !isKnowKey)
  16256. {
  16257. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16258. strcpy(unknownkey[UnknownKeynum], keyReq);
  16259. UnknownKeynum = UnknownKeynum + 1;
  16260. }
  16261. }
  16262. void processUnkownKey(void)
  16263. {
  16264. DEBUG_INFO("processUnkownKey...\n");
  16265. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16266. for(int index=0; index < UnknownKeynum; index++)
  16267. {
  16268. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16269. {
  16270. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16271. }
  16272. }
  16273. }
  16274. int setKeyValue(char *key, char *value)
  16275. {
  16276. int isSuccess = NotSupported;
  16277. int check_ascii=0;
  16278. char str[501]={0};
  16279. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16280. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16281. {
  16282. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16284. {
  16285. strcpy(str, (const char*)value);
  16286. for(int i = 0; str[i]; i++){
  16287. str[i] = tolower(str[i]);
  16288. }
  16289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16290. isSuccess = ConfigurationStatus_Accepted;
  16291. }
  16292. else
  16293. {
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. }
  16297. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16298. {
  16299. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16301. {
  16302. strcpy(str, (const char*)value);
  16303. for(int i = 0; str[i]; i++){
  16304. str[i] = tolower(str[i]);
  16305. }
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16307. isSuccess = ConfigurationStatus_Accepted;
  16308. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16309. }
  16310. else
  16311. {
  16312. isSuccess = ConfigurationStatus_Rejected;
  16313. }
  16314. }
  16315. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16316. {
  16317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16318. {
  16319. strcpy(str, (const char*)value);
  16320. for(int i = 0; str[i]; i++)
  16321. {
  16322. str[i] = tolower(str[i]);
  16323. }
  16324. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16326. isSuccess = ConfigurationStatus_Accepted;
  16327. }
  16328. else
  16329. {
  16330. isSuccess = ConfigurationStatus_Rejected;
  16331. }
  16332. }
  16333. if(strcmp(key, "BlinkRepeat") == 0)
  16334. {
  16335. //Charger.BlinkRepeat = Integer.parseInt(value);
  16336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16337. {
  16338. check_ascii = value[0];
  16339. if( (check_ascii < 48) || (check_ascii > 57) )
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. else
  16344. {
  16345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16346. isSuccess = ConfigurationStatus_Accepted;
  16347. }
  16348. }
  16349. else
  16350. {
  16351. isSuccess = ConfigurationStatus_Rejected;
  16352. }
  16353. }
  16354. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16355. {
  16356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16357. {
  16358. check_ascii = value[0];
  16359. if( (check_ascii < 48) || (check_ascii > 57) )
  16360. {
  16361. isSuccess = ConfigurationStatus_Rejected;
  16362. }
  16363. else
  16364. {
  16365. if((atoi(value) == 0) || (atoi(value) >= 5))
  16366. {
  16367. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16369. isSuccess = ConfigurationStatus_Accepted;
  16370. }
  16371. else
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. }
  16375. else
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. }
  16380. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16381. {
  16382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16383. {
  16384. check_ascii = value[0];
  16385. if( (check_ascii < 48) || (check_ascii > 57) )
  16386. {
  16387. isSuccess = ConfigurationStatus_Rejected;
  16388. }
  16389. else
  16390. {
  16391. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16393. isSuccess = ConfigurationStatus_Accepted;
  16394. }
  16395. }
  16396. else
  16397. {
  16398. isSuccess = ConfigurationStatus_Rejected;
  16399. }
  16400. }
  16401. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16402. {
  16403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16404. {
  16405. check_ascii = value[0];
  16406. if( (check_ascii < 48) || (check_ascii > 57) )
  16407. {
  16408. isSuccess = ConfigurationStatus_Rejected;
  16409. }
  16410. else
  16411. {
  16412. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16414. isSuccess = ConfigurationStatus_Accepted;
  16415. }
  16416. }
  16417. else
  16418. {
  16419. isSuccess = ConfigurationStatus_Rejected;
  16420. }
  16421. }
  16422. if(strcmp(key, "HeartbeatInterval") == 0)
  16423. {
  16424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16425. {
  16426. check_ascii = value[0];
  16427. if( (check_ascii < 48) || (check_ascii > 57) )
  16428. {
  16429. isSuccess = ConfigurationStatus_Rejected;
  16430. }
  16431. else
  16432. {
  16433. if((atoi(value) == 0) || (atoi(value) >= 10))
  16434. {
  16435. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16437. HeartBeatWaitTime = atoi(value);
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. else
  16441. {
  16442. isSuccess = ConfigurationStatus_Rejected;
  16443. }
  16444. }
  16445. }
  16446. else
  16447. {
  16448. isSuccess = ConfigurationStatus_Rejected;
  16449. }
  16450. }
  16451. if(strcmp(key, "LightIntensity") == 0)
  16452. {
  16453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16454. {
  16455. check_ascii = value[0];
  16456. if( (check_ascii < 48) || (check_ascii > 57) )
  16457. {
  16458. isSuccess = ConfigurationStatus_Rejected;
  16459. }
  16460. else
  16461. {
  16462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16463. isSuccess = ConfigurationStatus_Accepted;
  16464. }
  16465. }
  16466. else
  16467. {
  16468. isSuccess = ConfigurationStatus_Rejected;
  16469. }
  16470. }
  16471. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16472. {
  16473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16474. {
  16475. strcpy(str, (const char*)value);
  16476. for(int i = 0; str[i]; i++)
  16477. {
  16478. str[i] = tolower(str[i]);
  16479. }
  16480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16481. isSuccess = ConfigurationStatus_Accepted;
  16482. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16483. }
  16484. else
  16485. {
  16486. isSuccess = ConfigurationStatus_Rejected;
  16487. }
  16488. }
  16489. if(strcmp(key, "LocalPreAuthorize") == 0)
  16490. {
  16491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16492. {
  16493. strcpy(str, (const char*)value);
  16494. for(int i = 0; str[i]; i++)
  16495. {
  16496. str[i] = tolower(str[i]);
  16497. }
  16498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16499. isSuccess = ConfigurationStatus_Accepted;
  16500. }
  16501. else
  16502. {
  16503. isSuccess = ConfigurationStatus_Rejected;
  16504. }
  16505. }
  16506. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16507. {
  16508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16509. {
  16510. check_ascii = value[0];
  16511. if( (check_ascii < 48) || (check_ascii > 57) )
  16512. {
  16513. isSuccess = ConfigurationStatus_Rejected;
  16514. }
  16515. else
  16516. {
  16517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16518. isSuccess = ConfigurationStatus_Accepted;
  16519. }
  16520. }
  16521. else
  16522. {
  16523. isSuccess = ConfigurationStatus_Rejected;
  16524. }
  16525. }
  16526. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16527. {
  16528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16529. {
  16530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16531. isSuccess = ConfigurationStatus_Accepted;
  16532. }
  16533. else
  16534. {
  16535. isSuccess = ConfigurationStatus_Rejected;
  16536. }
  16537. }
  16538. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16539. {
  16540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16541. {
  16542. check_ascii = value[0];
  16543. if( (check_ascii < 48) || (check_ascii > 57) )
  16544. {
  16545. isSuccess = ConfigurationStatus_Rejected;
  16546. }
  16547. else
  16548. {
  16549. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16551. isSuccess = ConfigurationStatus_Accepted;
  16552. }
  16553. }
  16554. else
  16555. {
  16556. isSuccess = ConfigurationStatus_Rejected;
  16557. }
  16558. }
  16559. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16560. {
  16561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16562. {
  16563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16564. isSuccess = ConfigurationStatus_Accepted;
  16565. }
  16566. else
  16567. {
  16568. isSuccess = ConfigurationStatus_Rejected;
  16569. }
  16570. }
  16571. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16572. {
  16573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16574. {
  16575. check_ascii = value[0];
  16576. if( (check_ascii < 48) || (check_ascii > 57) )
  16577. {
  16578. isSuccess = ConfigurationStatus_Rejected;
  16579. }
  16580. else
  16581. {
  16582. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16584. isSuccess = ConfigurationStatus_Accepted;
  16585. }
  16586. }
  16587. else
  16588. {
  16589. isSuccess = ConfigurationStatus_Rejected;
  16590. }
  16591. }
  16592. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16593. {
  16594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16595. {
  16596. check_ascii = value[0];
  16597. if( (check_ascii < 48) || (check_ascii > 57) )
  16598. {
  16599. isSuccess = ConfigurationStatus_Rejected;
  16600. }
  16601. else
  16602. {
  16603. if((atoi(value) == 0) || (atoi(value) >= 3))
  16604. {
  16605. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. }
  16609. else
  16610. {
  16611. isSuccess = ConfigurationStatus_Rejected;
  16612. }
  16613. }
  16614. }
  16615. else
  16616. {
  16617. isSuccess = ConfigurationStatus_Rejected;
  16618. }
  16619. }
  16620. if(strcmp(key, "MinimumStatusDuration") == 0)
  16621. {
  16622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16623. {
  16624. check_ascii = value[0];
  16625. if( (check_ascii < 48) || (check_ascii > 57) )
  16626. {
  16627. isSuccess = ConfigurationStatus_Rejected;
  16628. }
  16629. else
  16630. {
  16631. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16632. {
  16633. isSuccess = ConfigurationStatus_Rejected;
  16634. }
  16635. else
  16636. {
  16637. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16639. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16640. isSuccess = ConfigurationStatus_Accepted;
  16641. }
  16642. }
  16643. }
  16644. else
  16645. {
  16646. isSuccess = ConfigurationStatus_Rejected;
  16647. }
  16648. }
  16649. if(strcmp(key, "NumberOfConnectors") == 0)
  16650. {
  16651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16652. {
  16653. check_ascii = value[0];
  16654. if( (check_ascii < 48) || (check_ascii > 57) )
  16655. {
  16656. isSuccess = ConfigurationStatus_Rejected;
  16657. }
  16658. else
  16659. {
  16660. //Charger.ResetRetries = Integer.parseInt(value);
  16661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16662. isSuccess = ConfigurationStatus_Accepted;
  16663. }
  16664. }
  16665. else
  16666. {
  16667. isSuccess = ConfigurationStatus_Rejected;
  16668. }
  16669. }
  16670. if(strcmp(key, "ResetRetries") == 0)
  16671. {
  16672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16673. {
  16674. check_ascii = value[0];
  16675. if( (check_ascii < 48) || (check_ascii > 57) )
  16676. {
  16677. isSuccess = ConfigurationStatus_Rejected;
  16678. }
  16679. else
  16680. {
  16681. //Charger.ResetRetries = Integer.parseInt(value);
  16682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16683. isSuccess = ConfigurationStatus_Accepted;
  16684. }
  16685. }
  16686. else
  16687. {
  16688. isSuccess = ConfigurationStatus_Rejected;
  16689. }
  16690. }
  16691. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16692. {
  16693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16694. {
  16695. strcpy(str, (const char*)value);
  16696. for(int i = 0; str[i]; i++)
  16697. {
  16698. str[i] = tolower(str[i]);
  16699. }
  16700. if(strcmp(str, "notapplicable")== 0)
  16701. {
  16702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16703. isSuccess = ConfigurationStatus_Accepted;
  16704. }
  16705. else if(strcmp(str, "unknown")== 0)
  16706. {
  16707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16708. isSuccess = ConfigurationStatus_Accepted;
  16709. }
  16710. else if(strcmp(str, "rst")== 0)
  16711. {
  16712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16713. isSuccess = ConfigurationStatus_Accepted;
  16714. }
  16715. else if(strcmp(str, "rts")== 0)
  16716. {
  16717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16718. isSuccess = ConfigurationStatus_Accepted;
  16719. }
  16720. else if(strcmp(str, "srt")== 0)
  16721. {
  16722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16723. isSuccess = ConfigurationStatus_Accepted;
  16724. }
  16725. else if(strcmp(str, "str")== 0)
  16726. {
  16727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16728. isSuccess = ConfigurationStatus_Accepted;
  16729. }
  16730. else if(strcmp(str, "trs")== 0)
  16731. {
  16732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16733. isSuccess = ConfigurationStatus_Accepted;
  16734. }
  16735. else if(strcmp(str, "tsr")== 0)
  16736. {
  16737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16738. isSuccess = ConfigurationStatus_Accepted;
  16739. }
  16740. else
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. }
  16745. else
  16746. {
  16747. isSuccess = ConfigurationStatus_Rejected;
  16748. }
  16749. }
  16750. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16751. {
  16752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16753. {
  16754. check_ascii = value[0];
  16755. if( (check_ascii < 48) || (check_ascii > 57) )
  16756. {
  16757. isSuccess = ConfigurationStatus_Rejected;
  16758. }
  16759. else
  16760. {
  16761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16762. isSuccess = ConfigurationStatus_Accepted;
  16763. }
  16764. }
  16765. else
  16766. {
  16767. isSuccess = ConfigurationStatus_Rejected;
  16768. }
  16769. }
  16770. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16771. {
  16772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16773. {
  16774. strcpy(str, (const char*)value);
  16775. for(int i = 0; str[i]; i++)
  16776. {
  16777. str[i] = tolower(str[i]);
  16778. }
  16779. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16781. isSuccess = ConfigurationStatus_Accepted;
  16782. }
  16783. else
  16784. {
  16785. isSuccess = ConfigurationStatus_Rejected;
  16786. }
  16787. }
  16788. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16789. {
  16790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16791. {
  16792. strcpy(str, (const char*)value);
  16793. for(int i = 0; str[i]; i++)
  16794. {
  16795. str[i] = tolower(str[i]);
  16796. }
  16797. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16799. isSuccess = ConfigurationStatus_Accepted;
  16800. }
  16801. else
  16802. {
  16803. isSuccess = ConfigurationStatus_Rejected;
  16804. }
  16805. }
  16806. if(strcmp(key, "StopTxnAlignedData") == 0)
  16807. {
  16808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16809. {
  16810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16811. isSuccess = ConfigurationStatus_Accepted;
  16812. }
  16813. else
  16814. {
  16815. isSuccess = ConfigurationStatus_Rejected;
  16816. }
  16817. }
  16818. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16819. {
  16820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16821. {
  16822. check_ascii = value[0];
  16823. if( (check_ascii < 48) || (check_ascii > 57) )
  16824. {
  16825. isSuccess = ConfigurationStatus_Rejected;
  16826. }
  16827. else
  16828. {
  16829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16830. isSuccess = ConfigurationStatus_Accepted;
  16831. }
  16832. }
  16833. else
  16834. {
  16835. isSuccess = ConfigurationStatus_Rejected;
  16836. }
  16837. }
  16838. if(strcmp(key, "StopTxnSampledData") == 0)
  16839. {
  16840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16841. {
  16842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16843. isSuccess = ConfigurationStatus_Accepted;
  16844. }
  16845. else
  16846. {
  16847. isSuccess = ConfigurationStatus_Rejected;
  16848. }
  16849. }
  16850. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16851. {
  16852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16853. {
  16854. check_ascii = value[0];
  16855. if( (check_ascii < 48) || (check_ascii > 57) )
  16856. {
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. else
  16860. {
  16861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16862. isSuccess = ConfigurationStatus_Accepted;
  16863. }
  16864. }
  16865. else
  16866. {
  16867. isSuccess = ConfigurationStatus_Rejected;
  16868. }
  16869. }
  16870. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16871. {
  16872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16873. {
  16874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16875. isSuccess = ConfigurationStatus_Accepted;
  16876. }
  16877. else
  16878. {
  16879. isSuccess = ConfigurationStatus_Rejected;
  16880. }
  16881. }
  16882. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16883. {
  16884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16885. {
  16886. check_ascii = value[0];
  16887. if( (check_ascii < 48) || (check_ascii > 57) )
  16888. {
  16889. isSuccess = ConfigurationStatus_Rejected;
  16890. }
  16891. else
  16892. {
  16893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16894. isSuccess = ConfigurationStatus_Accepted;
  16895. }
  16896. }
  16897. else
  16898. {
  16899. isSuccess = ConfigurationStatus_Rejected;
  16900. }
  16901. }
  16902. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16903. {
  16904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16905. {
  16906. check_ascii = value[0];
  16907. if( (check_ascii < 48) || (check_ascii > 57) )
  16908. {
  16909. isSuccess = ConfigurationStatus_Rejected;
  16910. }
  16911. else
  16912. {
  16913. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16915. TransactionMessageAttemptsValue = atoi(value);
  16916. isSuccess = ConfigurationStatus_Accepted;
  16917. }
  16918. }
  16919. else
  16920. {
  16921. isSuccess = ConfigurationStatus_Rejected;
  16922. }
  16923. }
  16924. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16925. {
  16926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16927. {
  16928. check_ascii = value[0];
  16929. if( (check_ascii < 48) || (check_ascii > 57) )
  16930. {
  16931. isSuccess = ConfigurationStatus_Rejected;
  16932. }
  16933. else
  16934. {
  16935. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16937. TransactionMessageRetryIntervalValue = atoi(value);
  16938. isSuccess = ConfigurationStatus_Accepted;
  16939. }
  16940. }
  16941. else
  16942. {
  16943. isSuccess = ConfigurationStatus_Rejected;
  16944. }
  16945. }
  16946. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16947. {
  16948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16949. {
  16950. strcpy(str, (const char*)value);
  16951. for(int i = 0; str[i]; i++)
  16952. {
  16953. str[i] = tolower(str[i]);
  16954. }
  16955. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16957. isSuccess = ConfigurationStatus_Accepted;
  16958. }
  16959. else
  16960. {
  16961. isSuccess = ConfigurationStatus_Rejected;
  16962. }
  16963. }
  16964. if(strcmp(key, "WebSocketPingInterval") == 0)
  16965. {
  16966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16967. {
  16968. check_ascii = value[0];
  16969. if( (check_ascii < 48) || (check_ascii > 57) )
  16970. {
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. else
  16974. {
  16975. if((atoi(value) == 0) || (atoi(value) >= 10))
  16976. {
  16977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16978. isSuccess = ConfigurationStatus_Accepted;
  16979. }
  16980. else
  16981. isSuccess = ConfigurationStatus_Rejected;
  16982. }
  16983. }
  16984. else
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. }
  16989. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16990. {
  16991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16992. {
  16993. strcpy(str, (const char*)value);
  16994. for(int i = 0; str[i]; i++)
  16995. {
  16996. str[i] = tolower(str[i]);
  16997. }
  16998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16999. isSuccess = ConfigurationStatus_Accepted;
  17000. }
  17001. else
  17002. {
  17003. isSuccess = ConfigurationStatus_Rejected;
  17004. }
  17005. }
  17006. if(strcmp(key, "AuthorizationKey") == 0)
  17007. {
  17008. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17009. {
  17010. strcpy(str, (const char*)value);
  17011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17012. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17013. isSuccess = ConfigurationStatus_Accepted;
  17014. }
  17015. else
  17016. {
  17017. isSuccess = ConfigurationStatus_Rejected;
  17018. }
  17019. }
  17020. if(strcmp(key, "SecurityProfile") == 0)
  17021. {
  17022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17023. {
  17024. check_ascii = value[0];
  17025. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17026. {
  17027. isSuccess = ConfigurationStatus_Rejected;
  17028. }
  17029. else if(check_ascii == 0x33)
  17030. {
  17031. isSuccess = NotSupported;
  17032. }
  17033. else
  17034. {
  17035. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17036. {
  17037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17038. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17039. isSuccess = ConfigurationStatus_Accepted;
  17040. }
  17041. else
  17042. isSuccess = ConfigurationStatus_Rejected;
  17043. }
  17044. }
  17045. else
  17046. {
  17047. isSuccess = ConfigurationStatus_Rejected;
  17048. }
  17049. }
  17050. if(strcmp(key, "DefaultPrice") == 0)
  17051. {
  17052. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17053. {
  17054. strcpy(str, (const char*)value);
  17055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17056. isSuccess = ConfigurationStatus_Accepted;
  17057. }
  17058. else
  17059. {
  17060. isSuccess = ConfigurationStatus_Rejected;
  17061. }
  17062. }
  17063. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17064. {
  17065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17066. {
  17067. strcpy(str, (const char*)value);
  17068. for(int i = 0; str[i]; i++)
  17069. {
  17070. str[i] = tolower(str[i]);
  17071. }
  17072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17073. isSuccess = ConfigurationStatus_Accepted;
  17074. }
  17075. else
  17076. {
  17077. isSuccess = ConfigurationStatus_Rejected;
  17078. }
  17079. }
  17080. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17081. {
  17082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17083. {
  17084. strcpy(str, (const char*)value);
  17085. for(int i = 0; str[i]; i++)
  17086. {
  17087. str[i] = tolower(str[i]);
  17088. }
  17089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17090. isSuccess = ConfigurationStatus_Accepted;
  17091. }
  17092. else
  17093. {
  17094. isSuccess = ConfigurationStatus_Rejected;
  17095. }
  17096. }
  17097. if(strcmp(key, "TimeOffset") == 0)
  17098. {
  17099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17100. {
  17101. strcpy(str, (const char*)value);
  17102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17103. isSuccess = ConfigurationStatus_Accepted;
  17104. }
  17105. else
  17106. {
  17107. isSuccess = ConfigurationStatus_Rejected;
  17108. }
  17109. }
  17110. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17111. {
  17112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17113. {
  17114. strcpy(str, (const char*)value);
  17115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17116. isSuccess = ConfigurationStatus_Accepted;
  17117. }
  17118. else
  17119. {
  17120. isSuccess = ConfigurationStatus_Rejected;
  17121. }
  17122. }
  17123. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17124. {
  17125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17126. {
  17127. strcpy(str, (const char*)value);
  17128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17129. isSuccess = ConfigurationStatus_Accepted;
  17130. }
  17131. else
  17132. {
  17133. isSuccess = ConfigurationStatus_Rejected;
  17134. }
  17135. }
  17136. if(strcmp(key, "SystemUptimeSec") == 0)
  17137. {
  17138. isSuccess = NotSupported;
  17139. }
  17140. if(strcmp(key, "FreeVend") == 0)
  17141. {
  17142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17143. {
  17144. strcpy(str, (const char*)value);
  17145. for(int i = 0; str[i]; i++)
  17146. {
  17147. str[i] = tolower(str[i]);
  17148. }
  17149. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17151. isSuccess = ConfigurationStatus_Accepted;
  17152. }
  17153. else
  17154. {
  17155. isSuccess = ConfigurationStatus_Rejected;
  17156. }
  17157. }
  17158. if(strcmp(key, "FreeVendIdtag") == 0)
  17159. {
  17160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17161. {
  17162. strcpy(str, (const char*)value);
  17163. if(strlen(str) <= 20)
  17164. {
  17165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17166. isSuccess = ConfigurationStatus_Accepted;
  17167. }
  17168. else
  17169. {
  17170. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17171. isSuccess = ConfigurationStatus_Rejected;
  17172. }
  17173. }
  17174. else
  17175. {
  17176. isSuccess = ConfigurationStatus_Rejected;
  17177. }
  17178. }
  17179. if(strcmp(key, "OcppServer") == 0)
  17180. {
  17181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17182. {
  17183. strcpy(str, (const char*)value);
  17184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17185. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17186. isSuccess = ConfigurationStatus_Accepted;
  17187. }
  17188. else
  17189. {
  17190. isSuccess = ConfigurationStatus_Rejected;
  17191. }
  17192. }
  17193. if(strcmp(key, "MaintainServer") == 0)
  17194. {
  17195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17196. {
  17197. strcpy(str, (const char*)value);
  17198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17199. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17200. isSuccess = ConfigurationStatus_Accepted;
  17201. }
  17202. else
  17203. {
  17204. isSuccess = ConfigurationStatus_Rejected;
  17205. }
  17206. }
  17207. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17208. {
  17209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17210. {
  17211. strcpy(str, (const char*)value);
  17212. for(int i = 0; str[i]; i++)
  17213. {
  17214. str[i] = tolower(str[i]);
  17215. }
  17216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17217. isSuccess = ConfigurationStatus_Accepted;
  17218. }
  17219. else
  17220. {
  17221. isSuccess = ConfigurationStatus_Rejected;
  17222. }
  17223. }
  17224. if(strcmp(key, "StatusNotificationInterval") == 0)
  17225. {
  17226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17227. {
  17228. check_ascii = value[0];
  17229. if( (check_ascii < 48) || (check_ascii > 57) )
  17230. {
  17231. isSuccess = ConfigurationStatus_Rejected;
  17232. }
  17233. else
  17234. {
  17235. if((atoi(value) == 0) || (atoi(value) >= 10))
  17236. {
  17237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17238. isSuccess = ConfigurationStatus_Accepted;
  17239. }
  17240. else
  17241. isSuccess = ConfigurationStatus_Rejected;
  17242. }
  17243. }
  17244. else
  17245. {
  17246. isSuccess = ConfigurationStatus_Rejected;
  17247. }
  17248. }
  17249. if(strcmp(key, "PreAuthAmount") == 0)
  17250. {
  17251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17252. {
  17253. check_ascii = value[0];
  17254. if( (check_ascii < 48) || (check_ascii > 57) )
  17255. {
  17256. isSuccess = ConfigurationStatus_Rejected;
  17257. }
  17258. else
  17259. {
  17260. if(atof(value) >= 0)
  17261. {
  17262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17263. isSuccess = ConfigurationStatus_Accepted;
  17264. }
  17265. else
  17266. isSuccess = ConfigurationStatus_Rejected;
  17267. }
  17268. }
  17269. else
  17270. {
  17271. isSuccess = ConfigurationStatus_Rejected;
  17272. }
  17273. }
  17274. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17275. {
  17276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17277. {
  17278. check_ascii = value[0];
  17279. if( (check_ascii < 48) || (check_ascii > 57) )
  17280. {
  17281. isSuccess = ConfigurationStatus_Rejected;
  17282. }
  17283. else
  17284. {
  17285. if(atoi(value) >= 0)
  17286. {
  17287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17288. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17289. isSuccess = ConfigurationStatus_Accepted;
  17290. }
  17291. else
  17292. isSuccess = ConfigurationStatus_Rejected;
  17293. }
  17294. }
  17295. else
  17296. {
  17297. isSuccess = ConfigurationStatus_Rejected;
  17298. }
  17299. }
  17300. if(strcmp(key, "PowerSharingServerIP") == 0)
  17301. {
  17302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17303. {
  17304. strcpy(str, (const char*)value);
  17305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17306. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17307. isSuccess = ConfigurationStatus_Accepted;
  17308. }
  17309. else
  17310. {
  17311. isSuccess = ConfigurationStatus_Rejected;
  17312. }
  17313. }
  17314. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17315. {
  17316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17317. {
  17318. strcpy(str, (const char*)value);
  17319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17320. isSuccess = ConfigurationStatus_Accepted;
  17321. }
  17322. else
  17323. {
  17324. isSuccess = ConfigurationStatus_Rejected;
  17325. }
  17326. }
  17327. #if 0
  17328. //For OCPP Test Case
  17329. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17330. {
  17331. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17332. {
  17333. strcpy(str, (const char*)value);
  17334. for(int i = 0; str[i]; i++)
  17335. {
  17336. str[i] = tolower(str[i]);
  17337. }
  17338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17339. isSuccess = ConfigurationStatus_Accepted;
  17340. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17341. }
  17342. else
  17343. {
  17344. isSuccess = ConfigurationStatus_Rejected;
  17345. }
  17346. }
  17347. #endif
  17348. #if 1
  17349. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17350. {
  17351. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17352. {
  17353. strcpy(str, (const char*)value);
  17354. for(int i = 0; str[i]; i++)
  17355. {
  17356. str[i] = tolower(str[i]);
  17357. }
  17358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17359. isSuccess = ConfigurationStatus_Accepted;
  17360. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17361. }
  17362. else
  17363. {
  17364. isSuccess = ConfigurationStatus_Rejected;
  17365. }
  17366. }
  17367. #endif
  17368. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17369. {
  17370. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17371. {
  17372. check_ascii = value[0];
  17373. if( (check_ascii < 48) || (check_ascii > 57) )
  17374. {
  17375. isSuccess = ConfigurationStatus_Rejected;
  17376. }
  17377. else
  17378. {
  17379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17380. isSuccess = ConfigurationStatus_Accepted;
  17381. }
  17382. }
  17383. else
  17384. {
  17385. isSuccess = ConfigurationStatus_Rejected;
  17386. }
  17387. }
  17388. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17389. {
  17390. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17391. {
  17392. check_ascii = value[0];
  17393. if( (check_ascii < 48) || (check_ascii > 57) )
  17394. {
  17395. isSuccess = ConfigurationStatus_Rejected;
  17396. }
  17397. else
  17398. {
  17399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17400. isSuccess = ConfigurationStatus_Accepted;
  17401. }
  17402. }
  17403. else
  17404. {
  17405. isSuccess = ConfigurationStatus_Rejected;
  17406. }
  17407. }
  17408. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17409. {
  17410. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17411. {
  17412. strcpy(str, (const char*)value);
  17413. for(int i = 0; str[i]; i++)
  17414. {
  17415. str[i] = tolower(str[i]);
  17416. }
  17417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17418. isSuccess = ConfigurationStatus_Accepted;
  17419. }
  17420. else
  17421. {
  17422. isSuccess = ConfigurationStatus_Rejected;
  17423. }
  17424. }
  17425. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17426. {
  17427. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17428. {
  17429. check_ascii = value[0];
  17430. if( (check_ascii < 48) || (check_ascii > 57) )
  17431. {
  17432. isSuccess = ConfigurationStatus_Rejected;
  17433. }
  17434. else
  17435. {
  17436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17437. isSuccess = ConfigurationStatus_Accepted;
  17438. }
  17439. }
  17440. else
  17441. {
  17442. isSuccess = ConfigurationStatus_Rejected;
  17443. }
  17444. }
  17445. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17446. {
  17447. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17448. {
  17449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17450. isSuccess = ConfigurationStatus_Accepted;
  17451. }
  17452. else
  17453. {
  17454. isSuccess = ConfigurationStatus_Rejected;
  17455. }
  17456. }
  17457. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17458. {
  17459. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17460. {
  17461. check_ascii = value[0];
  17462. if( (check_ascii < 48) || (check_ascii > 57) )
  17463. {
  17464. isSuccess = ConfigurationStatus_Rejected;
  17465. }
  17466. else
  17467. {
  17468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17469. isSuccess = ConfigurationStatus_Accepted;
  17470. }
  17471. }
  17472. else
  17473. {
  17474. isSuccess = ConfigurationStatus_Rejected;
  17475. }
  17476. }
  17477. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17478. {
  17479. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17480. {
  17481. strcpy(str, (const char*)value);
  17482. for(int i = 0; str[i]; i++)
  17483. {
  17484. str[i] = tolower(str[i]);
  17485. }
  17486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17487. isSuccess = ConfigurationStatus_Accepted;
  17488. }
  17489. else
  17490. {
  17491. isSuccess = ConfigurationStatus_Rejected;
  17492. }
  17493. }
  17494. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17495. {
  17496. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17497. {
  17498. check_ascii = value[0];
  17499. if( (check_ascii < 48) || (check_ascii > 57) )
  17500. {
  17501. isSuccess = ConfigurationStatus_Rejected;
  17502. }
  17503. else
  17504. {
  17505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17506. isSuccess = ConfigurationStatus_Accepted;
  17507. }
  17508. }
  17509. else
  17510. {
  17511. isSuccess = ConfigurationStatus_Rejected;
  17512. }
  17513. }
  17514. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17515. return isSuccess;
  17516. }
  17517. int TransactionMessageAttemptsGet(void)
  17518. {
  17519. return TransactionMessageAttemptsValue;
  17520. }
  17521. int FirstHeartBeatResponse(void)
  17522. {
  17523. return FirstHeartBeat;
  17524. }
  17525. int TransactionMessageRetryIntervalGet(void)
  17526. {
  17527. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17528. }
  17529. int ReadHttpStatus(int sock)
  17530. {
  17531. //char c;
  17532. char buff[1024]="",*ptr=buff+1;
  17533. int bytes_received, status;
  17534. DEBUG_INFO("Begin Response ..\n");
  17535. while((bytes_received = recv(sock, ptr, 1, 0))){
  17536. if(bytes_received==-1){
  17537. perror("ReadHttpStatus");
  17538. exit(1);
  17539. }
  17540. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17541. ptr++;
  17542. }
  17543. *ptr=0;
  17544. ptr=buff+1;
  17545. sscanf(ptr,"%*s %d ", &status);
  17546. DEBUG_INFO("%s\n",ptr);
  17547. DEBUG_INFO("status=%d\n",status);
  17548. DEBUG_INFO("End Response ..\n");
  17549. return (bytes_received>0)?status:0;
  17550. }
  17551. //the only filed that it parsed is 'Content-Length'
  17552. int ParseHeader(int sock)
  17553. {
  17554. //char c;
  17555. char buff[1024]="",*ptr=buff+4;
  17556. int bytes_received;
  17557. DEBUG_INFO("Begin HEADER ..\n");
  17558. while((bytes_received = recv(sock, ptr, 1, 0))){
  17559. if(bytes_received==-1){
  17560. perror("Parse Header");
  17561. exit(1);
  17562. }
  17563. if(
  17564. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17565. (ptr[-1]=='\r') && (*ptr=='\n' )
  17566. ) break;
  17567. ptr++;
  17568. }
  17569. *ptr=0;
  17570. ptr=buff+4;
  17571. //printf("%s",ptr);
  17572. if(bytes_received){
  17573. ptr=strstr(ptr,"Content-Length:");
  17574. if(ptr){
  17575. sscanf(ptr,"%*s %d",&bytes_received);
  17576. }else
  17577. bytes_received=-1; //unknown size
  17578. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17579. }
  17580. DEBUG_INFO("End HEADER ..\n");
  17581. return bytes_received ;
  17582. }
  17583. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17584. {
  17585. int result = TRUE;
  17586. char rmFileCmd[100]={0};
  17587. char FilePath[100]={0};
  17588. char ftpbuf[200];
  17589. int systemresult;
  17590. sprintf(FilePath,"/mnt/%s",filename);
  17591. system("ping 8.8.8.8 &");
  17592. if((access(FilePath,F_OK))!=-1)
  17593. {
  17594. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17595. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17596. system(rmFileCmd);
  17597. }
  17598. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17599. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17600. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17601. systemresult = system(ftpbuf);
  17602. if(systemresult != 0)
  17603. {
  17604. DEBUG_INFO("http DownLoad error!\n");
  17605. result = FALSE;
  17606. }
  17607. system("pkill ping");
  17608. return result;
  17609. }
  17610. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17611. {
  17612. int result = TRUE;
  17613. char rmFileCmd[100]={0};
  17614. char FilePath[100]={0};
  17615. char ftpbuf[200];
  17616. int systemresult;
  17617. sprintf(FilePath,"/mnt/%s",filename);
  17618. system("ping 8.8.8.8 &");
  17619. if((access(FilePath,F_OK))!=-1)
  17620. {
  17621. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17622. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17623. system(rmFileCmd);
  17624. }
  17625. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17626. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17627. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17628. systemresult = system(ftpbuf);
  17629. if(systemresult != 0)
  17630. {
  17631. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17632. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17633. systemresult = system(ftpbuf);
  17634. if(systemresult != 0)
  17635. {
  17636. DEBUG_WARN("wget error!\n");
  17637. result = FALSE;
  17638. }
  17639. }
  17640. system("pkill ping");
  17641. return result;
  17642. }
  17643. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17644. {
  17645. char rmFileCmd[100]={0};
  17646. char FilePath[100]={0};
  17647. char buf[512];
  17648. int systemresult = 0;
  17649. //DEBUG_INFO("filename=%s\n",filename);
  17650. //DEBUG_INFO("url=%s\n",url);
  17651. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17652. if((access(FilePath,F_OK))!=-1)
  17653. {
  17654. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17655. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17656. system(rmFileCmd);
  17657. }
  17658. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17659. if(fp == NULL)
  17660. {
  17661. DEBUG_INFO("log is NULL\n");
  17662. return FALSE;
  17663. }
  17664. else
  17665. {
  17666. fprintf(fp, "%s\n", url);
  17667. fprintf(fp, "%s\n", filename);
  17668. fclose(fp);
  17669. }
  17670. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17671. if(phpFP == NULL)
  17672. {
  17673. DEBUG_INFO("PHP upload fail.\n");
  17674. return FALSE;
  17675. }
  17676. else
  17677. {
  17678. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17679. {
  17680. if(strstr(buf, "result") != NULL)
  17681. {
  17682. sscanf(buf, "result: %d", &systemresult);
  17683. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17684. }
  17685. }
  17686. pclose(phpFP);
  17687. }
  17688. if(systemresult != 1)
  17689. {
  17690. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17691. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17692. if(phpFP == NULL)
  17693. {
  17694. DEBUG_WARN("PHP PUT upload fail.\n");
  17695. return FALSE;
  17696. }
  17697. else
  17698. {
  17699. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17700. {
  17701. if(strstr(buf, "result") != NULL)
  17702. {
  17703. sscanf(buf, "result: %d", &systemresult);
  17704. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17705. }
  17706. }
  17707. pclose(phpFP);
  17708. }
  17709. }
  17710. if(systemresult != 1)
  17711. {
  17712. DEBUG_WARN("PHP PUT upload fail.\n");
  17713. return FALSE;
  17714. }
  17715. return TRUE;
  17716. }
  17717. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17718. {
  17719. int result = FALSE;
  17720. char ftpbuf[200];
  17721. int systemresult;
  17722. /*
  17723. // Domaind name transfer to IP address
  17724. struct hostent* server;
  17725. char *IPbuffer;
  17726. server = gethostbyname(location);
  17727. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17728. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17729. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17730. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17731. systemresult = system(ftpbuf);
  17732. if(systemresult != 0)
  17733. {
  17734. DEBUG_INFO("ftpput error!\n");
  17735. }
  17736. else
  17737. {
  17738. result = TRUE;
  17739. DEBUG_INFO("ftpput OK!\n");
  17740. }
  17741. return result;
  17742. }
  17743. int GetOcppServerURL()
  17744. {
  17745. int result = FALSE;
  17746. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17747. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17748. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17749. struct yuarel url;
  17750. char urlStr[512];
  17751. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17752. {
  17753. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17754. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17755. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17756. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17757. if(yuarel_parse(&url, urlStr) != -1)
  17758. {
  17759. sprintf(OcppProtocol, "%s", url.scheme);
  17760. sprintf(OcppHost, "%s", url.host);
  17761. if(url.path == NULL)
  17762. OcppTempPath[0] = '\0';
  17763. else
  17764. {
  17765. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17766. {
  17767. sprintf(OcppTempPath, "%s/", url.path);
  17768. }
  17769. else
  17770. {
  17771. sprintf(OcppTempPath, "%s", url.path);
  17772. }
  17773. }
  17774. if(url.port == 0)
  17775. {
  17776. if(strcmp(OcppProtocol, "wss") == 0)
  17777. OcppPort = 443;
  17778. else
  17779. OcppPort = 80;
  17780. }
  17781. else
  17782. OcppPort = url.port;
  17783. result = TRUE;
  17784. }
  17785. }
  17786. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17787. {
  17788. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17789. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17790. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17791. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17792. if(yuarel_parse(&url, urlStr) != -1)
  17793. {
  17794. sprintf(OcppProtocol, "%s", url.scheme);
  17795. sprintf(OcppHost, "%s", url.host);
  17796. if(url.path == NULL)
  17797. OcppTempPath[0] = '\0';
  17798. else
  17799. sprintf(OcppTempPath, "%s", url.path);
  17800. if(url.port == 0)
  17801. {
  17802. if(strcmp(OcppProtocol, "wss") == 0)
  17803. OcppPort = 443;
  17804. else
  17805. OcppPort = 80;
  17806. }
  17807. else
  17808. OcppPort = url.port;
  17809. result = TRUE;
  17810. }
  17811. }
  17812. else
  17813. {
  17814. strcpy(OcppHost,"");
  17815. }
  17816. return result;
  17817. }
  17818. int GetOcppPath()
  17819. {
  17820. int result = FALSE;
  17821. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17822. {
  17823. if(OcppTempPath == NULL)
  17824. {
  17825. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17826. }
  17827. else
  17828. {
  17829. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17830. }
  17831. result = TRUE;
  17832. goto End;
  17833. }
  17834. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17835. {
  17836. if(OcppTempPath == NULL)
  17837. {
  17838. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17839. }
  17840. else
  17841. {
  17842. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17843. }
  17844. result = TRUE;
  17845. goto End;
  17846. }
  17847. else
  17848. {
  17849. strcpy(OcppPath,"");
  17850. }
  17851. End:
  17852. return result;
  17853. }
  17854. int GetOcppPort()
  17855. {
  17856. return OcppPort;
  17857. }
  17858. int GetOcppConnStatus(void)
  17859. {
  17860. return ShmOCPP16Data->OcppConnStatus;
  17861. }
  17862. void SetOcppConnStatus(uint8_t status)
  17863. {
  17864. ShmOCPP16Data->OcppConnStatus = status;
  17865. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17866. }
  17867. int GetHeartBeatWithNOResponse(void)
  17868. {
  17869. return HeartBeatWithNOResponse;
  17870. }
  17871. void SetHeartBeatWithNOResponse(void)
  17872. {
  17873. HeartBeatWithNOResponse = 0;
  17874. }
  17875. void GetStartTransactionIdTag(int gun_index)
  17876. {
  17877. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17878. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17879. }
  17880. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17881. {
  17882. char ch;
  17883. FILE *fptr1;
  17884. int temptransactionId;
  17885. char str[100]={0};
  17886. temptransactionId = 0;
  17887. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17888. {
  17889. DEBUG_INFO("IdTag is empty.\n");
  17890. return temptransactionId;
  17891. }
  17892. /*------ Read the file ----------------*/
  17893. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17894. if (!fptr1)
  17895. {
  17896. DEBUG_INFO("QueueTransactionId file open error.\n");
  17897. //printf(" File not found or unable to open the input file!!\n");
  17898. return temptransactionId;
  17899. }
  17900. ch=fgetc(fptr1);
  17901. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17902. rewind(fptr1);
  17903. if(ch!=EOF)
  17904. {
  17905. // printf("%c",ch);
  17906. while (fgets(str, 100, fptr1) != NULL)
  17907. {
  17908. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17909. if(str[0]=='\0')
  17910. {
  17911. break;
  17912. }
  17913. char *revbuf[8] = {0}; // Variable store string split
  17914. int num = 0;// Quantity after string split
  17915. DEBUG_INFO("Transaction queue data= %s\n", str);
  17916. splitstring(str,",",revbuf,&num); // String split
  17917. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17918. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17919. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17920. DEBUG_INFO("------------------------------\n");
  17921. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17922. {
  17923. if(isStopTransaction)
  17924. {
  17925. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17926. {
  17927. temptransactionId = atoi(revbuf[2]);
  17928. //break;
  17929. }
  17930. }
  17931. else
  17932. {
  17933. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17934. {
  17935. temptransactionId = atoi(revbuf[2]);
  17936. //break;
  17937. }
  17938. }
  17939. }
  17940. }
  17941. }
  17942. else
  17943. DEBUG_INFO("EOF\n");
  17944. fclose(fptr1);
  17945. /*------- End of reading ---------------*/
  17946. return temptransactionId;
  17947. }
  17948. void SetTransactionIdZero(int transactionId)
  17949. {
  17950. char ch;
  17951. FILE *fptr1, *fptr2;
  17952. int temptransactionId = 0;
  17953. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17954. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17955. if (!fptr1)
  17956. {
  17957. //printf(" File not found or unable to open the input file!!\n");
  17958. return ;
  17959. }
  17960. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17961. if (!fptr2)
  17962. {
  17963. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17964. fclose(fptr1);
  17965. return ;
  17966. }
  17967. ch=fgetc(fptr1);
  17968. rewind(fptr1);
  17969. if(ch!=EOF)
  17970. {
  17971. // copy all contents to the temporary file except the specific line
  17972. while (fgets(str, 100, fptr1) != NULL)
  17973. {
  17974. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17975. if(str[0]=='\0')
  17976. {
  17977. break;
  17978. }
  17979. char *revbuf[8] = {0};
  17980. int num = 0;
  17981. strcpy(strtemp, str);
  17982. splitstring(str,",",revbuf,&num);
  17983. if(revbuf[2][0] != '\0')
  17984. {
  17985. temptransactionId = atoi(revbuf[2]);
  17986. if(transactionId != temptransactionId)
  17987. {
  17988. fprintf(fptr2, "%s\n", strtemp);
  17989. }
  17990. }
  17991. }
  17992. }
  17993. fclose(fptr1);
  17994. fclose(fptr2);
  17995. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17996. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17997. /*------ Read the file ----------------*/
  17998. }
  17999. int InternetDisconnect(void)
  18000. {
  18001. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18002. }
  18003. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18004. void storeTempStopTransaction(int gun_index)
  18005. {
  18006. char guid[37]={0};
  18007. int tempIndex = 0;
  18008. char TempStopTransaction[256];
  18009. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18010. DEBUG_INFO("storeTempStopTransaction...\n");
  18011. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18012. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18013. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18014. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18015. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18016. {
  18017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18018. {
  18019. tempIndex = ((gun_index==2) ? 1: 0);
  18020. }
  18021. else
  18022. {
  18023. tempIndex = gun_index;
  18024. }
  18025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18026. {
  18027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18028. {
  18029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18030. }
  18031. }// END OF CHAdeMO_QUANTITY
  18032. }
  18033. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18034. {
  18035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18036. {
  18037. tempIndex = ((gun_index==2) ? 1: 0);
  18038. }
  18039. else
  18040. {
  18041. tempIndex = gun_index;
  18042. }
  18043. for (int index = 0; index < CCS_QUANTITY; index++)
  18044. {
  18045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18046. {
  18047. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18048. }
  18049. }// END OF CCS_QUANTITY
  18050. }
  18051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18052. {
  18053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18054. {
  18055. tempIndex = ((gun_index==2) ? 1: 0);
  18056. }
  18057. else
  18058. {
  18059. tempIndex = gun_index;
  18060. }
  18061. for (int index = 0; index < GB_QUANTITY; index++)
  18062. {
  18063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18064. {
  18065. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18066. }
  18067. }// END OF GB_QUANTITY
  18068. }
  18069. else if(gunType[gun_index] == GUN_TYPE_DO)
  18070. {
  18071. tempIndex = gun_index;
  18072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18073. {
  18074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18075. {
  18076. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18077. }
  18078. }
  18079. }
  18080. else
  18081. {
  18082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18083. {
  18084. tempIndex = 2;
  18085. }
  18086. else
  18087. {
  18088. tempIndex = gun_index;
  18089. }
  18090. for (int index = 0; index < AC_QUANTITY; index++)
  18091. {
  18092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18093. {
  18094. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18095. }
  18096. }// END OF AC_QUANTITY
  18097. }
  18098. //Stop Transaction Time
  18099. struct timeval tmnow;
  18100. struct tm *tm;
  18101. char buf[28];//, usec_buf[6];
  18102. gettimeofday(&tmnow, NULL);
  18103. time_t t;
  18104. t = time(NULL);
  18105. /*UTC time and date*/
  18106. tm = gmtime(&t);
  18107. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18109. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18111. random_uuid(guid);
  18112. /***********************************transactionData******************************************************/
  18113. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18115. //=================================
  18116. //1. Transaction_Begin
  18117. //=================================
  18118. //============================== Energy.Active.Import.Interval ===========================================
  18119. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18120. {
  18121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  18122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  18124. 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*/]);
  18125. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18126. 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))
  18127. {
  18128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  18129. }
  18130. else
  18131. {
  18132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  18133. }
  18134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  18135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18136. }
  18137. //=================================
  18138. //2. Transaction_End
  18139. //=================================
  18140. //2.1====================================== Current.Import L1 ==============================================
  18141. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18142. {
  18143. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18144. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18145. {
  18146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18147. {
  18148. tempIndex = ((gun_index==2) ? 1: 0);
  18149. }
  18150. else
  18151. {
  18152. tempIndex = gun_index;
  18153. }
  18154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18155. {
  18156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18157. {
  18158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18159. }
  18160. }// End of for CHAdeMO_QUANTITY
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18162. }
  18163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18164. {
  18165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18166. {
  18167. tempIndex = ((gun_index==2) ? 1: 0);
  18168. }
  18169. else
  18170. {
  18171. tempIndex = gun_index;
  18172. }
  18173. for (int index = 0; index < CCS_QUANTITY; index++)
  18174. {
  18175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18176. {
  18177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18178. }
  18179. }// End of for CCS_QUANTITY
  18180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18181. }
  18182. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18183. {
  18184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18185. {
  18186. tempIndex = ((gun_index==2) ? 1: 0);
  18187. }
  18188. else
  18189. {
  18190. tempIndex = gun_index;
  18191. }
  18192. for (int index = 0; index < GB_QUANTITY; index++)
  18193. {
  18194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18195. {
  18196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18197. }
  18198. }// End of for GB_QUANTITY
  18199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18200. }
  18201. else if(gunType[gun_index] == GUN_TYPE_DO)
  18202. {
  18203. tempIndex = gun_index;
  18204. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18205. {
  18206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18207. {
  18208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18209. }
  18210. }
  18211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18212. }
  18213. else
  18214. {
  18215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18216. {
  18217. tempIndex = 2;
  18218. }
  18219. else
  18220. {
  18221. tempIndex = gun_index;
  18222. }
  18223. for (int index = 0; index < AC_QUANTITY; index++)
  18224. {
  18225. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18226. {
  18227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18228. }
  18229. }// End of for AC_QUANTITY
  18230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18231. }
  18232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18235. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18238. }
  18239. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18240. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18241. {
  18242. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18243. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18244. {
  18245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18246. {
  18247. tempIndex = ((gun_index==2) ? 1: 0);
  18248. }
  18249. else
  18250. {
  18251. tempIndex = gun_index;
  18252. }
  18253. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18254. {
  18255. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18256. {
  18257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18258. }
  18259. }// END OF CHAdeMO_QUANTITY
  18260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18261. }
  18262. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18263. {
  18264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18265. {
  18266. tempIndex = ((gun_index==2) ? 1: 0);
  18267. }
  18268. else
  18269. {
  18270. tempIndex = gun_index;
  18271. }
  18272. for (int index = 0; index < CCS_QUANTITY; index++)
  18273. {
  18274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18275. {
  18276. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18277. }
  18278. }// END OF CCS_QUANTITY
  18279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18280. }
  18281. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18282. {
  18283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18284. {
  18285. tempIndex = ((gun_index==2) ? 1: 0);
  18286. }
  18287. else
  18288. {
  18289. tempIndex = gun_index;
  18290. }
  18291. for (int index = 0; index < GB_QUANTITY; index++)
  18292. {
  18293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18294. {
  18295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18296. }
  18297. }// END OF GB_QUANTITY
  18298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18299. }
  18300. else if(gunType[gun_index] == GUN_TYPE_DO)
  18301. {
  18302. tempIndex = gun_index;
  18303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18304. {
  18305. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18306. {
  18307. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18308. }
  18309. }
  18310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18311. }
  18312. else
  18313. {
  18314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18315. {
  18316. tempIndex = 2;
  18317. }
  18318. else
  18319. {
  18320. tempIndex = gun_index;
  18321. }
  18322. for (int index = 0; index < AC_QUANTITY; index++)
  18323. {
  18324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18325. {
  18326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18327. }
  18328. }// END OF AC_QUANTITY
  18329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18330. }
  18331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18334. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18337. }
  18338. //2.3====================================== Power.Active.Import =========================================
  18339. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18340. {
  18341. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18342. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18343. {
  18344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18345. {
  18346. tempIndex = ((gun_index==2) ? 1: 0);
  18347. }
  18348. else
  18349. {
  18350. tempIndex = gun_index;
  18351. }
  18352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18353. {
  18354. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18355. {
  18356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18357. }
  18358. } // End for CHAdeMO_QUANTITY
  18359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18360. }
  18361. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18362. {
  18363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18364. {
  18365. tempIndex = ((gun_index==2) ? 1: 0);
  18366. }
  18367. else
  18368. {
  18369. tempIndex = gun_index;
  18370. }
  18371. for (int index = 0; index < CCS_QUANTITY; index++)
  18372. {
  18373. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18374. {
  18375. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18376. }
  18377. } // END for CCS_QUANTITY
  18378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18379. }
  18380. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18381. {
  18382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18383. {
  18384. tempIndex = ((gun_index==2) ? 1: 0);
  18385. }
  18386. else
  18387. {
  18388. tempIndex = gun_index;
  18389. }
  18390. for (int index = 0; index < GB_QUANTITY; index++)
  18391. {
  18392. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18393. {
  18394. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18395. }
  18396. }// END for GB_QUANTITY
  18397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18398. }
  18399. else if(gunType[gun_index] == GUN_TYPE_DO)
  18400. {
  18401. tempIndex = gun_index;
  18402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18403. {
  18404. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18405. {
  18406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18407. }
  18408. }
  18409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18410. }
  18411. else
  18412. {
  18413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18414. {
  18415. tempIndex = 2;
  18416. }
  18417. else
  18418. {
  18419. tempIndex = gun_index;
  18420. }
  18421. for (int index = 0; index < AC_QUANTITY; index++)
  18422. {
  18423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18424. {
  18425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18426. }
  18427. } // END for AC_QUANTITY
  18428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18429. }
  18430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18433. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18436. }
  18437. //2.4====================================== Voltage L1 ====================================================
  18438. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18439. {
  18440. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18442. {
  18443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18444. {
  18445. tempIndex = ((gun_index==2) ? 1: 0);
  18446. }
  18447. else
  18448. {
  18449. tempIndex = gun_index;
  18450. }
  18451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18452. {
  18453. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18454. {
  18455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18456. }
  18457. } // END OF FOR CHAdeMO_QUANTITY
  18458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18459. }
  18460. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18461. {
  18462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18463. {
  18464. tempIndex = ((gun_index==2) ? 1: 0);
  18465. }
  18466. else
  18467. {
  18468. tempIndex = gun_index;
  18469. }
  18470. for (int index = 0; index < CCS_QUANTITY; index++)
  18471. {
  18472. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18473. {
  18474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18475. }
  18476. } // END OF FOR CCS_QUANTITY
  18477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18478. }
  18479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18480. {
  18481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18482. {
  18483. tempIndex = ((gun_index==2) ? 1: 0);
  18484. }
  18485. else
  18486. {
  18487. tempIndex = gun_index;
  18488. }
  18489. for (int index = 0; index < GB_QUANTITY; index++)
  18490. {
  18491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18492. {
  18493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18494. }
  18495. } // END OF FOR GB_QUANTITY
  18496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18497. }
  18498. else if(gunType[gun_index] == GUN_TYPE_DO)
  18499. {
  18500. tempIndex = gun_index;
  18501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18502. {
  18503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18504. {
  18505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18506. }
  18507. }
  18508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18509. }
  18510. else
  18511. {
  18512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18513. {
  18514. tempIndex = 2;
  18515. }
  18516. else
  18517. {
  18518. tempIndex = gun_index;
  18519. }
  18520. for (int index = 0; index < AC_QUANTITY; index++)
  18521. {
  18522. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18523. {
  18524. 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
  18525. }
  18526. } // END OF FOR AC_QUANTITY
  18527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18528. }
  18529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18532. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18535. }
  18536. //2.5============================================== End SoC =========================================================
  18537. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18538. {
  18539. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18540. 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))
  18541. {
  18542. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18543. {
  18544. tempIndex = ((gun_index==2) ? 1: 0);
  18545. }
  18546. else
  18547. {
  18548. tempIndex = gun_index;
  18549. }
  18550. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18551. {
  18552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18553. {
  18554. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18555. {
  18556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18557. }
  18558. }
  18559. }
  18560. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18561. {
  18562. for (int index = 0; index < CCS_QUANTITY; index++)
  18563. {
  18564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18565. {
  18566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18567. }
  18568. }
  18569. }
  18570. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18571. {
  18572. for (int index = 0; index < GB_QUANTITY; index++)
  18573. {
  18574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18575. {
  18576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18577. }
  18578. }
  18579. }
  18580. else if(gunType[gun_index] == GUN_TYPE_DO)
  18581. {
  18582. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18583. {
  18584. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18585. {
  18586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18587. }
  18588. }
  18589. }
  18590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18596. } // END FOR DC CASE
  18597. }
  18598. //2.6====================================== Current.Import L2 ==============================================
  18599. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18600. {
  18601. // AC 3 phase L2 current
  18602. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18603. {
  18604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18605. {
  18606. tempIndex = 2;
  18607. }
  18608. else
  18609. {
  18610. tempIndex = gun_index;
  18611. }
  18612. for (int index = 0; index < AC_QUANTITY; index++)
  18613. {
  18614. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18615. {
  18616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18617. }
  18618. }// End of for AC_QUANTITY
  18619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18620. }
  18621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18626. }
  18627. //2.7====================================== Current.Import L3 ==============================================
  18628. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18629. {
  18630. // AC 3 phase L3 current
  18631. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18632. {
  18633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18634. {
  18635. tempIndex = 2;
  18636. }
  18637. else
  18638. {
  18639. tempIndex = gun_index;
  18640. }
  18641. for (int index = 0; index < AC_QUANTITY; index++)
  18642. {
  18643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18644. {
  18645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18646. }
  18647. }// End of for AC_QUANTITY
  18648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18649. }
  18650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18655. }
  18656. //2.9====================================== Voltage L2 ====================================================
  18657. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18658. {
  18659. // AC 3 phase L2 volatge
  18660. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18661. {
  18662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18663. {
  18664. tempIndex = 2;
  18665. }
  18666. else
  18667. {
  18668. tempIndex = gun_index;
  18669. }
  18670. for (int index = 0; index < AC_QUANTITY; index++)
  18671. {
  18672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18673. {
  18674. 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
  18675. }
  18676. } // END OF FOR AC_QUANTITY
  18677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18678. }
  18679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18684. }
  18685. //2.10====================================== Voltage L3 ====================================================
  18686. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18687. {
  18688. // AC 3 phase L3 volatge
  18689. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18690. {
  18691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18692. {
  18693. tempIndex = 2;
  18694. }
  18695. else
  18696. {
  18697. tempIndex = gun_index;
  18698. }
  18699. for (int index = 0; index < AC_QUANTITY; index++)
  18700. {
  18701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18702. {
  18703. 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
  18704. }
  18705. } // END OF FOR AC_QUANTITY
  18706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18707. }
  18708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18713. }
  18714. //====================== Start SoC ================================
  18715. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18716. {
  18717. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18718. 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))
  18719. {
  18720. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18721. {
  18722. tempIndex = ((gun_index==2) ? 1: 0);
  18723. }
  18724. else
  18725. {
  18726. tempIndex = gun_index;
  18727. }
  18728. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18729. {
  18730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18731. {
  18732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18733. {
  18734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18735. }
  18736. }
  18737. }
  18738. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18739. {
  18740. for (int index = 0; index < CCS_QUANTITY; index++)
  18741. {
  18742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18743. {
  18744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18745. }
  18746. }
  18747. }
  18748. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18749. {
  18750. for (int index = 0; index < GB_QUANTITY; index++)
  18751. {
  18752. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18753. {
  18754. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18755. }
  18756. }
  18757. }
  18758. else if(gunType[gun_index] == GUN_TYPE_DO)
  18759. {
  18760. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18761. {
  18762. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18763. {
  18764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18765. }
  18766. }
  18767. }
  18768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18774. } // END FOR DC CASE
  18775. }
  18776. //======================================== Message create ==============================================
  18777. json_object *StopTransaction = json_object_new_object();
  18778. json_object *transactionDatas = json_object_new_array();
  18779. json_object *sampledValues = json_object_new_array();
  18780. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18781. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18782. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18783. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18784. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18785. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18786. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18787. {
  18788. json_object *transactionData = json_object_new_object();
  18789. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18790. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18791. {
  18792. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18793. {
  18794. json_object *sampledValue = json_object_new_object();
  18795. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18796. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18797. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18798. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18799. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18800. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18801. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18802. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18803. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18804. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18805. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18806. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18807. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18808. json_object_array_add(sampledValues, sampledValue);
  18809. }
  18810. }
  18811. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18812. json_object_array_add(transactionDatas, transactionData);
  18813. }
  18814. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18815. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18816. ,MESSAGE_TYPE_CALL
  18817. ,guid
  18818. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18819. json_object_put(StopTransaction);
  18820. // Check File "TempStopTransaction" Exist
  18821. if((access(TempStopTransaction,F_OK))!=-1)
  18822. {
  18823. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18824. fclose(fopen(TempStopTransaction, "w"));
  18825. }
  18826. else
  18827. {
  18828. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18829. FILE *log = fopen(TempStopTransaction, "w+");
  18830. if(log == NULL)
  18831. {
  18832. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18833. return ;
  18834. }
  18835. else
  18836. {
  18837. fclose(log);
  18838. }
  18839. }
  18840. //Add TempStopTransaction | Update TempStopTransaction
  18841. // open file for writing
  18842. FILE *outfile;
  18843. outfile = fopen (TempStopTransaction, "a");
  18844. //DEBUG_INFO("data = %s\n", queuedata);
  18845. fputs(queuedata, outfile);
  18846. fputs("\n", outfile);
  18847. fclose (outfile);
  18848. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18849. OCPP_updatePeriodEnergy(gun_index);
  18850. }
  18851. void checkTempStopTransaction(int gun_index)
  18852. {
  18853. FILE *fptr1;
  18854. char ch;
  18855. char str[QUEUE_MESSAGE_LENGTH]={0};
  18856. char guid[37]={0};
  18857. char tempdata[65]={0};
  18858. char connectorStr[2]={0};
  18859. char TempStopTransaction[256];
  18860. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18861. fptr1 = fopen(TempStopTransaction, "r");
  18862. //TempStopTransaction格式: 槍號,StopTransaction封包
  18863. if (!fptr1)
  18864. {
  18865. //printf(" File not found or unable to open the input file!!\n");
  18866. return ;
  18867. }
  18868. ch=fgetc(fptr1);
  18869. //printf(" Now the content of the file %s is : \n",fname);
  18870. rewind(fptr1);
  18871. if(ch!=EOF)
  18872. {
  18873. // copy all contents to the temporary file except the specific line
  18874. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18875. {
  18876. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18877. if(str[0]=='\0')
  18878. {
  18879. break;
  18880. }
  18881. //TempStopTransaction格式: 槍號,StopTransaction封包
  18882. strncpy(connectorStr, str, 1);
  18883. if(atoi(connectorStr) != (gun_index+1))
  18884. {
  18885. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18886. fclose(fptr1);
  18887. return ;
  18888. }
  18889. //random_uuid(guid);
  18890. strncpy(guid, str+6, 36); //copy guid
  18891. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18892. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18893. {
  18894. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18895. }
  18896. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18897. OCPP_insert_transaction_msg(NO, str);
  18898. memset(str,0,ARRAY_SIZE(str));
  18899. }
  18900. }
  18901. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18902. fclose(fptr1);
  18903. remove(TempStopTransaction); // remove the original file
  18904. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18905. }
  18906. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18907. {
  18908. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18909. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18910. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18911. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18912. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18913. }
  18914. int GetWebSocketPingInterval(void)
  18915. {
  18916. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18917. }
  18918. int GetServerSign(void)
  18919. {
  18920. return server_sign;
  18921. }
  18922. uint8_t GetOcppSecurityProfile()
  18923. {
  18924. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18925. }
  18926. void GetOcppChargerBoxId(uint8_t *data)
  18927. {
  18928. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18929. }
  18930. void GetOcppSecurityPassword(uint8_t *data)
  18931. {
  18932. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18933. }
  18934. void SetOcppVersion(uint8_t *version)
  18935. {
  18936. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18937. DEBUG_INFO("ocpp version: %s\n", version);
  18938. if(strstr((char*)version, "ocpp1.6") != NULL)
  18939. {
  18940. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18941. }
  18942. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18943. {
  18944. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18945. system("pkill OcppBackend");
  18946. }
  18947. }
  18948. void SetServerSign(int value)
  18949. {
  18950. server_sign = value;
  18951. }
  18952. int GetBootNotificationInterval(void)
  18953. {
  18954. return BootNotificationInterval;
  18955. }
  18956. int GetInternetConn(void)
  18957. {
  18958. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18959. }
  18960. int GetBackendConnectionTimeout(void)
  18961. {
  18962. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18963. }
  18964. int isConnectorInitMode(int gun_index)
  18965. {
  18966. int tempIndex = 0;
  18967. int result = TRUE;
  18968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18970. {
  18971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18972. {
  18973. tempIndex = ((gun_index==2) ? 1: 0);
  18974. }
  18975. else
  18976. {
  18977. tempIndex = gun_index;
  18978. }
  18979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18980. {
  18981. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18982. {
  18983. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18984. } //end of the same index
  18985. }//end of for CHAdeMO_QUANTITY
  18986. }
  18987. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18988. {
  18989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18990. {
  18991. tempIndex = ((gun_index==2) ? 1: 0);
  18992. }
  18993. else
  18994. {
  18995. tempIndex = gun_index;
  18996. }
  18997. for (int index = 0; index < CCS_QUANTITY; index++)
  18998. {
  18999. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19000. {
  19001. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19002. } //end of the same index
  19003. } // end of for CCS_QUANTITY
  19004. }
  19005. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19006. {
  19007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19008. {
  19009. tempIndex = ((gun_index==2) ? 1: 0);
  19010. }
  19011. else
  19012. {
  19013. tempIndex = gun_index;
  19014. }
  19015. for (int index = 0; index < GB_QUANTITY; index++)
  19016. {
  19017. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19018. {
  19019. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19020. } //end of the same index
  19021. } // end of for GB_QUANTITY
  19022. }
  19023. else if(gunType[gun_index] == GUN_TYPE_DO)
  19024. {
  19025. tempIndex = gun_index;
  19026. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19027. {
  19028. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19029. {
  19030. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19031. } //end of the same index
  19032. }
  19033. }
  19034. else
  19035. {
  19036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19037. {
  19038. tempIndex = 2;
  19039. }
  19040. else
  19041. {
  19042. tempIndex = gun_index;
  19043. }
  19044. for (int index = 0; index < AC_QUANTITY; index++)
  19045. {
  19046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19047. {
  19048. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19049. }//end of the same index
  19050. }//end of for AC_QUANTITY
  19051. }
  19052. return result;
  19053. }
  19054. void refreshProcDogTimer()
  19055. {
  19056. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19057. }
  19058. void InitialSystemValue(void)
  19059. {
  19060. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19061. locallistVersion=0;
  19062. BootNotificationInterval = 0;
  19063. authorizeRetryTimes = 0;
  19064. GunStatusInterval = 10;
  19065. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19066. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19067. //Hear Beat
  19068. HeartBeatWithNOResponse = 0;
  19069. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19070. FirstHeartBeat = 0;
  19071. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19072. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19073. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19074. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19075. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19076. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19077. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19078. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19079. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19080. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19081. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19082. //Status && ConnectorPlugIn Setting
  19083. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19084. {
  19085. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19086. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19087. }
  19088. for (int index = 0; index < CCS_QUANTITY; index++)
  19089. {
  19090. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19091. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19092. }
  19093. for (int index = 0; index < GB_QUANTITY; index++)
  19094. {
  19095. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19096. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19097. }
  19098. for (int index = 0; index < AC_QUANTITY; index++)
  19099. {
  19100. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19101. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19102. }
  19103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19104. {
  19105. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19106. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19107. }
  19108. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19109. {
  19110. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19111. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19112. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19113. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19114. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19115. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19116. }
  19117. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19118. refreshStartTimer(&clientTime.Heartbeat);
  19119. sleep(1);
  19120. }
  19121. void LWS_Send(char *str)
  19122. {
  19123. //=====================================================
  19124. // Check InternetConn 0: disconnected, 1: connected
  19125. //====================================================
  19126. if(GetOcppConnStatus() == 0)
  19127. {
  19128. DEBUG_INFO("offline now !!!\n");
  19129. return;
  19130. }
  19131. // Only disable isWebsocketSendable operation initiated by charger
  19132. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19133. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19134. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19135. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19136. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19137. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19138. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19139. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19140. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19141. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19142. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19143. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19144. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19145. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19146. {
  19147. isWebsocketSendable = 0;
  19148. }
  19149. pthread_mutex_lock(&lock_send);
  19150. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19151. sprintf((char *)SendBuffer, "%s", str);
  19152. SendBufLen = strlen(str);
  19153. pthread_mutex_unlock(&lock_send);
  19154. lws_callback_on_writable(wsi_client);
  19155. //lws_service(context, 0);
  19156. //sleep(1);
  19157. }
  19158. void LWS_SendNow(char *str)
  19159. {
  19160. //=====================================================
  19161. // Check InternetConn 0: disconnected, 1: connected
  19162. //====================================================
  19163. if(GetOcppConnStatus() == 0)
  19164. {
  19165. DEBUG_INFO("offline now !!!\n");
  19166. return;
  19167. }
  19168. // Only disable isWebsocketSendable operation initiated by charger
  19169. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19170. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19171. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19172. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19173. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19174. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19175. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19176. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19177. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19178. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19179. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19180. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19181. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19182. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19183. {
  19184. isWebsocketSendable = 0;
  19185. }
  19186. pthread_mutex_lock(&lock_send);
  19187. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19188. sprintf((char *)SendBuffer, "%s", str);
  19189. SendBufLen = strlen(str);
  19190. pthread_mutex_unlock(&lock_send);
  19191. lws_callback_on_writable(wsi_client);
  19192. lws_service(context, 0);
  19193. //sleep(1);
  19194. }