MessageHandler.c 848 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  499. {
  500. struct tm *tmTarget;
  501. struct timeb tbTarget;
  502. tmStart.tm_year -= 1900;
  503. tmStart.tm_mon -= 1;
  504. tmStart.tm_gmtoff = 0;
  505. tbTarget.time = mktime(&tmStart);
  506. tbTarget.timezone = 0;
  507. tbTarget.time += (8*3600);
  508. tmTarget = gmtime(&tbTarget.time);
  509. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  510. tx_buf[65] = (tmTarget->tm_mon+1);
  511. tx_buf[66] = tmTarget->tm_mday;
  512. tx_buf[67] = tmTarget->tm_hour;
  513. tx_buf[68] = tmTarget->tm_min;
  514. tx_buf[69] = tmTarget->tm_sec;
  515. }
  516. // Stop date time 6 bytes
  517. 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))
  518. {
  519. struct tm *tmTarget;
  520. struct timeb tbTarget;
  521. tmEnd.tm_year -= 1900;
  522. tmEnd.tm_mon -= 1;
  523. tmEnd.tm_gmtoff = 0;
  524. tbTarget.time = mktime(&tmEnd);
  525. tbTarget.timezone = 0;
  526. tbTarget.time += (8*3600);
  527. tmTarget = gmtime(&tbTarget.time);
  528. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  529. tx_buf[71] = (tmTarget->tm_mon+1);
  530. tx_buf[72] = tmTarget->tm_mday;
  531. tx_buf[73] = tmTarget->tm_hour;
  532. tx_buf[74] = tmTarget->tm_min;
  533. tx_buf[75] = tmTarget->tm_sec;
  534. }
  535. // Session energy 2 bytes
  536. tx_buf[76] = PresentChargedEnergy & 0xff;
  537. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  538. // Start SOC 1 byte
  539. tx_buf[78] = socStart;
  540. // Stop SOC 1 byte
  541. tx_buf[79] = socEnd;
  542. // Open socket
  543. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  544. if(udp_socket_fd == -1)
  545. {
  546. DEBUG_ERROR("UDP socket create failed!\n");
  547. }
  548. else
  549. {
  550. // Get server DNS entry
  551. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  552. if (server == NULL)
  553. {
  554. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. }
  556. else
  557. {
  558. // Build the server's Internet address
  559. bzero((char *) &dest_addr, sizeof(dest_addr));
  560. dest_addr.sin_family = AF_INET;
  561. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  562. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  563. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  564. {
  565. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  566. {
  567. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  568. }
  569. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  570. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  571. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  572. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  573. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. DEBUG_TTIA_INFO("---------- Header ----------\n");
  575. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  576. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  577. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  578. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  579. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  580. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  581. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  582. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  583. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  584. DEBUG_TTIA_INFO("Len: 0x3C\n");
  585. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  586. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  587. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  588. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  589. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  590. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  591. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  592. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  593. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  594. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  596. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  597. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  598. DEBUG_TTIA_INFO("=========================================\n");
  599. sn++;
  600. result = PASS;
  601. }
  602. else
  603. {
  604. DEBUG_ERROR("UDP sent out fail.\n");
  605. }
  606. }
  607. }
  608. return result;
  609. }
  610. //=========================================
  611. // Save configuration
  612. //=========================================
  613. int runShellCmd(const char*cmd)
  614. {
  615. int result = FAIL;
  616. char buf[256];
  617. FILE *fp;
  618. fp = popen(cmd, "r");
  619. if(fp != NULL)
  620. {
  621. while(fgets(buf, sizeof(buf), fp) != NULL)
  622. {
  623. DEBUG_INFO("%s\n", buf);
  624. }
  625. result = PASS;
  626. }
  627. pclose(fp);
  628. return result;
  629. }
  630. int StoreUsrConfigData(struct SysConfigData *UsrData)
  631. {
  632. int result = PASS;
  633. int fd,wrd;
  634. unsigned int i,Chk;
  635. unsigned char *ptr, *BufTmp;
  636. int MtdBlockSize = 0x300000;
  637. Chk=0;
  638. ptr=(unsigned char *)UsrData;
  639. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  640. {
  641. memset(BufTmp,0,MtdBlockSize);
  642. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  643. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  644. Chk+=*(BufTmp+i);
  645. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  646. // Output configuration to file.
  647. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  648. if (fd < 0)
  649. {
  650. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  651. free(BufTmp);
  652. return 0;
  653. }
  654. wrd=write(fd, BufTmp, MtdBlockSize);
  655. close(fd);
  656. if(wrd<MtdBlockSize)
  657. {
  658. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  663. DEBUG_INFO("Erase /dev/mtd10.\n");
  664. runShellCmd("flash_erase /dev/mtd10 0 0");
  665. DEBUG_INFO("Write /dev/mtd10.\n");
  666. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  667. DEBUG_INFO("Erase /dev/mtd11.\n");
  668. runShellCmd("flash_erase /dev/mtd11 0 0");
  669. DEBUG_INFO("Write /dev/mtd11.\n");
  670. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  671. system("rm -f /mnt/EvseConfig.bin");
  672. DEBUG_INFO("EvseConfig write to flash OK\n");
  673. }
  674. else
  675. {
  676. DEBUG_ERROR("alloc BlockSize NG\r\n");
  677. result = FAIL;
  678. }
  679. if(BufTmp!=NULL)
  680. free(BufTmp);
  681. return result;
  682. }
  683. //=========================================
  684. // Sqlite3 related function
  685. //=========================================
  686. static int selectSqlCount = 0;
  687. static int callback(void *data, int argc, char **argv, char **azColName){
  688. int i;
  689. //printf("%s: ", (const char*)data);
  690. selectSqlCount = argc;
  691. for(i = 0; i<argc; i++){
  692. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  693. }
  694. //printf("\n");
  695. return 0;
  696. }
  697. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  698. //int i;
  699. //printf("%s:\n", (const char*)data);
  700. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  701. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  702. return 0;
  703. }
  704. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  705. //printf("%s:\n", (const char*)data);
  706. //idTag
  707. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  708. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. //parentIdTag
  710. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  711. //expir_date
  712. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  713. //status
  714. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  715. //version
  716. if(columenCount > 5)
  717. idTagQuery.listVersionInt = atoi(columnValue[5]);
  718. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  719. return 0;
  720. }
  721. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  722. {
  723. // localversion = argv[5] ? atoi(argv[5]) : 0;
  724. // printf("localversion=%d\n", localversion);
  725. return 0;
  726. }
  727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  728. {
  729. for (int i = 0; i < n_columns; i++)
  730. {
  731. DEBUG_INFO("%s\t", col_values[i]);
  732. }
  733. DEBUG_INFO("\n");
  734. return 0;
  735. }
  736. int OCPP_cleanLocalCache()
  737. {
  738. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  739. char *errMsg = 0;
  740. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  741. if (SQLITE_OK != rc)
  742. {
  743. DEBUG_INFO("SQL error: %s\n",errMsg);
  744. return FALSE;
  745. }
  746. return TRUE;
  747. }
  748. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  749. {
  750. int isSuccess = TRUE;
  751. int ret = 0;
  752. //const char* data = "Callback function called";
  753. char sql[300];
  754. char zErrMsg[200];
  755. memset(sql, 0, 300);
  756. memset(zErrMsg, 0, 200);
  757. 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);
  758. //* Execute SQL statement */
  759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  760. if( ret != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. isSuccess = FALSE;
  764. }
  765. return isSuccess;
  766. }
  767. void OCPP_getIdTagFromLocalCache(char idTag[])
  768. {
  769. int rc = 0;
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  775. memset(&idTagQuery, 0, sizeof(idTagQuery));
  776. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  777. /* Execute SQL statement */
  778. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  779. if( rc != SQLITE_OK )
  780. {
  781. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  782. }
  783. }
  784. void OCPP_getListVerion()
  785. {
  786. int rc = 0;
  787. // const char* data = "Callback function called";
  788. char sql[100];
  789. char zErrMsg[100];
  790. memset(sql, 0, 100);
  791. memset(zErrMsg, 0, 100);
  792. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  793. /* Execute SQL statement */
  794. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  795. if( rc != SQLITE_OK )
  796. {
  797. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  798. }
  799. }
  800. void OCPP_get_TableAuthlocalAllData(void)
  801. {
  802. int rc = 0;
  803. char sql[100];
  804. char zErrMsg[100];
  805. memset(sql, 0, 100);
  806. memset(zErrMsg, 0, 100);
  807. sprintf(sql,"select * from ocpp_auth_local ");
  808. /* Execute SQL statement */
  809. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  810. if( rc != SQLITE_OK )
  811. {
  812. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  813. }
  814. //return ver;
  815. }
  816. int OCPP_cleanLocalList()
  817. {
  818. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  819. char *errMsg = 0;
  820. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  821. if (SQLITE_OK != rc)
  822. {
  823. DEBUG_INFO("%s\n",errMsg);
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  829. {
  830. int isSuccess = FALSE;
  831. int ret = 0;
  832. //const char* data = "Callback function called";
  833. char sql[300];
  834. char zErrMsg[200];
  835. memset(sql, 0, 300);
  836. memset(zErrMsg, 0, 200);
  837. 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);
  838. //* Execute SQL statement */
  839. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  840. if( ret != SQLITE_OK )
  841. {
  842. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  843. return isSuccess;
  844. }
  845. memset(sql, 0, 300);
  846. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  847. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. isSuccess = TRUE;
  854. return isSuccess;
  855. }
  856. void OCPP_getIdTagFromLocalList(char idTag[])
  857. {
  858. int rc = 0;
  859. // const char* data = "Callback function called";
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  866. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  867. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  868. /* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. //return ver;
  875. }
  876. void OCPP_deleteIdTagFromLocalList(char idTag[])
  877. {
  878. //int ver = 0;
  879. //int isSuccess = FALSE;
  880. int rc = 0;
  881. char sql[100];
  882. char zErrMsg[100];
  883. memset(sql, 0, 100);
  884. memset(zErrMsg, 0, 100);
  885. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  886. //* Execute SQL statement */
  887. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  888. if( rc != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. }
  892. }
  893. int getCurrentYear()
  894. {
  895. int result = 0;
  896. time_t CurrentTime;
  897. struct tm *tm;
  898. CurrentTime = time(NULL);
  899. tm=localtime(&CurrentTime);
  900. result = (tm->tm_year + 1900);
  901. return result;
  902. }
  903. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  904. {
  905. int result = PASS;
  906. char* errMsg = NULL;
  907. char sqlStr[8192];
  908. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  909. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  913. }
  914. 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));
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  919. }
  920. return result;
  921. }
  922. //==========================================
  923. // Check time passed since today
  924. //==========================================
  925. long long DiffTimebWithNow(struct timeb ST)
  926. {
  927. //return milli-second
  928. struct timeb ET;
  929. long long StartTime,StopTime;
  930. ftime(&ET);
  931. StartTime=(long long)ST.time;
  932. StopTime=(long long)ET.time;
  933. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  934. }
  935. int getTimePassSinceToday(uint8_t gun_index)
  936. {
  937. int result = -1;
  938. static time_t lastTime[4];
  939. time_t t;
  940. struct tm *tmStartToday;
  941. struct timeb tbStartToday;
  942. t=time(NULL);
  943. if(difftime(t, lastTime[gun_index])>0)
  944. {
  945. tmStartToday=localtime(&t);
  946. tmStartToday->tm_hour = 0;
  947. tmStartToday->tm_min = 0;
  948. tmStartToday->tm_sec = 0;
  949. tbStartToday.time = mktime(tmStartToday);
  950. tbStartToday.millitm = 0;
  951. result = DiffTimebWithNow(tbStartToday)/1000;
  952. lastTime[gun_index] = t;
  953. }
  954. return result;
  955. }
  956. void getNowDatetime(uint8_t *data)
  957. {
  958. time_t t = time(NULL);
  959. struct tm tm = *localtime(&t);
  960. 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);
  961. }
  962. int syncDateTimeRTC(uint8_t *data)
  963. {
  964. struct ParsingResult
  965. {
  966. int result;
  967. int scanedElement;
  968. int year;
  969. int month;
  970. int mday;
  971. int hour;
  972. int min;
  973. int sec;
  974. int tz_hour;
  975. int tz_min;
  976. float minSec;
  977. }result;
  978. struct tm tmOrg;
  979. struct tm *tmTarget;
  980. struct timeb tbTarget;
  981. char buf[128];
  982. memset(&result, 0x00, sizeof(struct ParsingResult));
  983. result.result = PASS;
  984. if(strstr((char*)data, ".") != NULL)
  985. {
  986. // Original data with mini second
  987. if(strstr((char*)data, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  991. &result.year,
  992. &result.month,
  993. &result.mday,
  994. &result.hour,
  995. &result.min,
  996. &result.sec,
  997. &result.minSec);
  998. }
  999. else
  1000. {
  1001. // Original data without Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec,
  1009. &result.minSec,
  1010. &result.tz_hour,
  1011. &result.tz_min);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. // Original data without mini second
  1017. if(strstr((char*)data, "Z") != NULL)
  1018. {
  1019. // Original data with Z
  1020. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1021. &result.year,
  1022. &result.month,
  1023. &result.mday,
  1024. &result.hour,
  1025. &result.min,
  1026. &result.sec);
  1027. }
  1028. else
  1029. {
  1030. // Original data without Z
  1031. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1032. &result.year,
  1033. &result.month,
  1034. &result.mday,
  1035. &result.hour,
  1036. &result.min,
  1037. &result.sec,
  1038. &result.tz_hour,
  1039. &result.tz_min);
  1040. }
  1041. }
  1042. tmOrg.tm_year = result.year - 1900;
  1043. tmOrg.tm_mon = result.month - 1;
  1044. tmOrg.tm_mday = result.mday;
  1045. tmOrg.tm_hour = result.hour;
  1046. tmOrg.tm_min = result.min;
  1047. tmOrg.tm_sec = result.sec;
  1048. tmOrg.tm_gmtoff = 0;
  1049. tbTarget.time = mktime(&tmOrg);
  1050. tbTarget.timezone = 0;
  1051. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1052. tmTarget = gmtime(&tbTarget.time);
  1053. 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);
  1054. //DEBUG_INFO(" org date time: %s\n", data);
  1055. //DEBUG_INFO("parse date time: %s\n", buf);
  1056. system(buf);
  1057. system("/sbin/hwclock -w --systohc");
  1058. if(result.scanedElement < 6)
  1059. result.result = FAIL;
  1060. return result.result;
  1061. }
  1062. //==========================================
  1063. // GetCompositeSchedule logic related function
  1064. //==========================================
  1065. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1066. {
  1067. //return milli-second
  1068. unsigned int StartTime,StopTime;
  1069. StartTime=(unsigned int)ST.time;
  1070. StopTime=(unsigned int)ET.time;
  1071. return (StopTime-StartTime);
  1072. }
  1073. int DiffTimebWithNowSec(struct timeb ST)
  1074. {
  1075. //return milli-second
  1076. struct timeb ET;
  1077. unsigned int StartTime,StopTime;
  1078. ftime(&ET);
  1079. StartTime=(unsigned int)ST.time;
  1080. StopTime=(unsigned int)ET.time;
  1081. return (StopTime-StartTime);
  1082. }
  1083. int getStartStop(uint8_t *start, uint8_t *stop)
  1084. {
  1085. int result = -1;
  1086. struct tm tmStart;
  1087. struct timeb tbStart;
  1088. struct tm tmStop;
  1089. struct timeb tbStop;
  1090. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1091. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1092. {
  1093. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1094. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1095. tmStart.tm_year -= 1900;
  1096. tmStart.tm_mon -= 1;
  1097. tbStart.time = mktime(&tmStart);
  1098. tbStart.millitm = 0;
  1099. tmStop.tm_year -= 1900;
  1100. tmStop.tm_mon -= 1;
  1101. tbStop.time = mktime(&tmStop);
  1102. tbStop.millitm = 0;
  1103. result = DiffTimebSec(tbStart, tbStop);
  1104. //DEBUG_INFO("getStartStop(): %d\n", result);
  1105. }
  1106. else
  1107. {
  1108. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1109. }
  1110. return result;
  1111. }
  1112. int isOvertNow(uint8_t *start)
  1113. {
  1114. int result = NO;
  1115. struct ParsingResult
  1116. {
  1117. int result;
  1118. int scanedElement;
  1119. int year;
  1120. int month;
  1121. int mday;
  1122. int hour;
  1123. int min;
  1124. int sec;
  1125. int tz_hour;
  1126. int tz_min;
  1127. float minSec;
  1128. }parsingResult;
  1129. struct tm tmStart;
  1130. struct timeb tbStart;
  1131. if(strstr((char*)start, ".") != NULL)
  1132. {
  1133. // Original data with mini second
  1134. if(strstr((char*)start, "Z") != NULL)
  1135. {
  1136. // Original data with Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec);
  1145. }
  1146. else
  1147. {
  1148. // Original data without Z
  1149. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1150. &parsingResult.year,
  1151. &parsingResult.month,
  1152. &parsingResult.mday,
  1153. &parsingResult.hour,
  1154. &parsingResult.min,
  1155. &parsingResult.sec,
  1156. &parsingResult.minSec,
  1157. &parsingResult.tz_hour,
  1158. &parsingResult.tz_min);
  1159. }
  1160. }
  1161. else
  1162. {
  1163. // Original data without mini second
  1164. if(strstr((char*)start, "Z") != NULL)
  1165. {
  1166. // Original data with Z
  1167. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1168. &parsingResult.year,
  1169. &parsingResult.month,
  1170. &parsingResult.mday,
  1171. &parsingResult.hour,
  1172. &parsingResult.min,
  1173. &parsingResult.sec);
  1174. }
  1175. else
  1176. {
  1177. // Original data without Z
  1178. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1179. &parsingResult.year,
  1180. &parsingResult.month,
  1181. &parsingResult.mday,
  1182. &parsingResult.hour,
  1183. &parsingResult.min,
  1184. &parsingResult.sec,
  1185. &parsingResult.tz_hour,
  1186. &parsingResult.tz_min);
  1187. }
  1188. }
  1189. if(parsingResult.scanedElement >= 6)
  1190. {
  1191. tmStart.tm_year = parsingResult.year - 1900;
  1192. tmStart.tm_mon = parsingResult.month - 1;
  1193. tmStart.tm_mday = parsingResult.mday;
  1194. tmStart.tm_hour = parsingResult.hour;
  1195. tmStart.tm_min = parsingResult.min;
  1196. tmStart.tm_sec = parsingResult.sec;
  1197. tmStart.tm_gmtoff = 0;
  1198. tbStart.time = mktime(&tmStart);
  1199. tbStart.timezone = 0;
  1200. tbStart.millitm = 0;
  1201. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1202. if(DiffTimebWithNowSec(tbStart) <= 0)
  1203. result = NO;
  1204. else
  1205. result = YES;
  1206. }
  1207. else
  1208. {
  1209. DEBUG_WARN("Start date parsing error.\n");
  1210. }
  1211. return result;
  1212. }
  1213. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1214. {
  1215. int result = -1;
  1216. struct tm tmStart;
  1217. struct timeb tbStart;
  1218. struct tm tmStop;
  1219. struct timeb tbStop;
  1220. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1221. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1222. {
  1223. tmStart.tm_year -= 1900;
  1224. tmStart.tm_mon -= 1;
  1225. tbStart.time = mktime(&tmStart);
  1226. tbStart.millitm = 0;
  1227. tmStop.tm_year -= 1900;
  1228. tmStop.tm_mon -= 1;
  1229. tbStop.time = mktime(&tmStop);
  1230. tbStop.millitm = 0;
  1231. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1232. }
  1233. return result;
  1234. }
  1235. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1236. {
  1237. FILE *fp;
  1238. char profileFileName[128];
  1239. char *line = NULL;
  1240. size_t len = 0;
  1241. time_t CurrentTime;
  1242. struct tm *tmComposite;
  1243. struct StructChargingProfile maxProfile;
  1244. uint8_t limitMax=0;
  1245. int compositePeriodIdx = 0;
  1246. CurrentTime = time(NULL);
  1247. tmComposite=localtime(&CurrentTime);
  1248. 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);
  1249. if(isUnitA)
  1250. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1251. else
  1252. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1253. compositeProfile->ChargingSchedule.Duration = durationReq;
  1254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1255. {
  1256. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1259. }
  1260. compositeProfile->ChargingProfileId = 0;
  1261. compositeProfile->StackLevel = 99 ;
  1262. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1263. maxProfile.ChargingProfileId = -1;
  1264. maxProfile.ChargingSchedule.Duration = -1;
  1265. system("rm -f /tmp/*.json");
  1266. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1267. // Search max profile
  1268. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1269. if((access(profileFileName, F_OK))!=-1)
  1270. {
  1271. fp = fopen(profileFileName, "r");
  1272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1273. {
  1274. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1277. }
  1278. maxProfile.ChargingProfileId = -1;
  1279. maxProfile.StackLevel = -1;
  1280. while(getline(&line, &len, fp) != -1)
  1281. {
  1282. json_object *obj = NULL;
  1283. obj = json_tokener_parse(line);
  1284. if(is_error(obj))
  1285. {
  1286. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1287. }
  1288. else
  1289. {
  1290. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1291. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1292. )
  1293. {
  1294. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1295. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1296. )
  1297. {
  1298. struct tm tmFrom, tmTo;
  1299. struct timeb tbFrom, tbTo;
  1300. 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) &&
  1301. (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))
  1302. {
  1303. tmFrom.tm_year -= 1900;
  1304. tmFrom.tm_mon -= 1;
  1305. tbFrom.time = mktime(&tmFrom);
  1306. tmTo.tm_year -= 1900;
  1307. tmTo.tm_mon -= 1;
  1308. tbTo.time = mktime(&tmTo);
  1309. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1310. {
  1311. if(maxProfile.ChargingProfileId == -1)
  1312. DEBUG_INFO("MaxProfile found.\n");
  1313. else
  1314. DEBUG_INFO("MaxProfile updated.\n");
  1315. // Required item
  1316. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1317. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1318. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1319. if(isUnitA)
  1320. {
  1321. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1322. 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++)
  1323. {
  1324. 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"));
  1325. 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?
  1326. 3:
  1327. 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")));
  1328. 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")));
  1329. }
  1330. }
  1331. else
  1332. {
  1333. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1334. 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++)
  1335. {
  1336. 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"));
  1337. 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?
  1338. 3:
  1339. 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")));
  1340. 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));
  1341. }
  1342. }
  1343. // Optional item
  1344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1345. {
  1346. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1347. }
  1348. else
  1349. {
  1350. sprintf((char*)maxProfile.ValidFrom, " ");
  1351. }
  1352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1353. {
  1354. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1355. }
  1356. else
  1357. {
  1358. sprintf((char*)maxProfile.ValidTo, " ");
  1359. }
  1360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1361. {
  1362. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1363. }
  1364. else
  1365. {
  1366. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1367. }
  1368. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1369. {
  1370. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1371. }
  1372. else
  1373. {
  1374. maxProfile.TransactionId = -1;
  1375. }
  1376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1377. {
  1378. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1379. }
  1380. else
  1381. {
  1382. maxProfile.ChargingSchedule.Duration = 86400;
  1383. }
  1384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1385. {
  1386. 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")));
  1387. }
  1388. else
  1389. {
  1390. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1391. }
  1392. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1393. {
  1394. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1395. }
  1396. else
  1397. {
  1398. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. else
  1404. {
  1405. if(maxProfile.ChargingProfileId == -1)
  1406. DEBUG_INFO("MaxProfile found.\n");
  1407. else
  1408. DEBUG_INFO("MaxProfile updated.\n");
  1409. // Required item
  1410. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1411. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1412. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1413. if(isUnitA)
  1414. {
  1415. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1416. 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++)
  1417. {
  1418. 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"));
  1419. 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?
  1420. 3:
  1421. 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")));
  1422. 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")));
  1423. }
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1428. 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++)
  1429. {
  1430. 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"));
  1431. 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?
  1432. 3:
  1433. 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")));
  1434. 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));
  1435. }
  1436. }
  1437. // Optional item
  1438. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1439. {
  1440. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1441. }
  1442. else
  1443. {
  1444. sprintf((char*)maxProfile.ValidFrom, " ");
  1445. }
  1446. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1447. {
  1448. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1449. }
  1450. else
  1451. {
  1452. sprintf((char*)maxProfile.ValidTo, " ");
  1453. }
  1454. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1455. {
  1456. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1457. }
  1458. else
  1459. {
  1460. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1461. }
  1462. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1463. {
  1464. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1465. }
  1466. else
  1467. {
  1468. maxProfile.TransactionId = -1;
  1469. }
  1470. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1471. {
  1472. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1473. }
  1474. else
  1475. {
  1476. maxProfile.ChargingSchedule.Duration = 86400;
  1477. }
  1478. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1479. {
  1480. 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")));
  1481. }
  1482. else
  1483. {
  1484. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1485. }
  1486. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1487. {
  1488. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1489. }
  1490. else
  1491. {
  1492. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1493. }
  1494. }
  1495. }
  1496. }
  1497. json_object_put(obj);
  1498. }
  1499. fclose(fp);
  1500. /*
  1501. if(maxProfile.ChargingProfileId !=-1)
  1502. {
  1503. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1504. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1505. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1506. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1507. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1508. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1509. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1510. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1511. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1512. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1513. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1515. {
  1516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1517. {
  1518. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1519. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1520. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1521. }
  1522. }
  1523. }
  1524. else
  1525. DEBUG_INFO("MaxProfile not found.\n");
  1526. DEBUG_INFO("------------------------------------\n");*/
  1527. }
  1528. if(maxProfile.ChargingProfileId != -1)
  1529. {
  1530. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1531. {
  1532. if(maxProfile.ChargingSchedule.Duration != -1)
  1533. {
  1534. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1535. 0:
  1536. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1537. }
  1538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1539. {
  1540. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1545. if(idxPeriod > 0)
  1546. {
  1547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1556. {
  1557. if(maxProfile.ChargingSchedule.Duration != -1)
  1558. {
  1559. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1560. }
  1561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1562. {
  1563. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1566. if(idxPeriod > 0)
  1567. {
  1568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1569. {
  1570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. else
  1577. {
  1578. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1579. {
  1580. if(maxProfile.ChargingSchedule.Duration != -1)
  1581. {
  1582. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1583. 0:
  1584. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1585. }
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1589. {
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1591. 0:
  1592. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1593. if(idxPeriod > 0)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. else
  1604. {
  1605. if(maxProfile.ChargingSchedule.Duration != -1)
  1606. {
  1607. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1608. 0:
  1609. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1610. }
  1611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1612. {
  1613. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1614. {
  1615. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1616. 0:
  1617. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1618. if(idxPeriod > 0)
  1619. {
  1620. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1621. {
  1622. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. /*
  1630. DEBUG_INFO("MaxProfile after align.\n");
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. DEBUG_INFO("------------------------------------\n");*/
  1652. }
  1653. // Find each profile period quantity
  1654. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1655. {
  1656. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1657. limitMax = idx+1;
  1658. }
  1659. if(maxProfile.ChargingProfileId != -1)
  1660. {
  1661. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1662. {
  1663. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1664. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1665. (maxProfile.ChargingSchedule.Duration > 0))
  1666. {
  1667. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1668. {
  1669. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1670. compositePeriodIdx++;
  1671. }
  1672. else
  1673. {
  1674. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1675. }
  1676. }
  1677. }
  1678. }
  1679. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1680. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1681. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1682. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1684. {
  1685. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1686. {
  1687. compositeProfile->ChargingProfileId = 1;
  1688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1691. }
  1692. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1693. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1694. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1695. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1696. }
  1697. if(line)
  1698. free(line);
  1699. }
  1700. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1701. {
  1702. FILE *fp;
  1703. char profileFileName[128];
  1704. char *line = NULL;
  1705. size_t len = 0;
  1706. time_t CurrentTime;
  1707. struct tm *tmComposite;
  1708. struct StructChargingProfile maxProfile;
  1709. struct StructChargingProfile defaultTxProfile;
  1710. struct StructChargingProfile txProfile;
  1711. struct StructChargingSchedulePeriod tmpPeriod;
  1712. uint8_t limitMax=0;
  1713. uint8_t limitDef=0;
  1714. uint8_t limitTx=0;
  1715. int compositePeriodIdx = 0;
  1716. CurrentTime = time(NULL);
  1717. tmComposite=localtime(&CurrentTime);
  1718. 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);
  1719. if(isUnitA)
  1720. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1721. else
  1722. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1723. compositeProfile->ChargingSchedule.Duration = durationReq;
  1724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1725. {
  1726. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1727. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1728. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1729. }
  1730. compositeProfile->ChargingProfileId = 0;
  1731. compositeProfile->StackLevel = 99 ;
  1732. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1733. maxProfile.ChargingProfileId = -1;
  1734. defaultTxProfile.ChargingProfileId = -1;
  1735. txProfile.ChargingProfileId = -1;
  1736. maxProfile.ChargingSchedule.Duration = -1;
  1737. defaultTxProfile.ChargingSchedule.Duration = -1;
  1738. txProfile.ChargingSchedule.Duration = -1;
  1739. system("rm -f /tmp/*.json");
  1740. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1741. /*
  1742. * Search valid charging profile
  1743. */
  1744. //DEBUG_INFO("====================================\n");
  1745. // Search tx profile
  1746. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1747. if((access(profileFileName, F_OK))!=-1)
  1748. {
  1749. fp = fopen(profileFileName, "r");
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1755. }
  1756. txProfile.ChargingProfileId = -1;
  1757. txProfile.StackLevel = -1;
  1758. while(getline(&line, &len, fp) != -1)
  1759. {
  1760. json_object *obj = NULL;
  1761. obj = json_tokener_parse(line);
  1762. if(is_error(obj))
  1763. {
  1764. DEBUG_ERROR("Parse txProfile from file error.\n");
  1765. }
  1766. else
  1767. {
  1768. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1769. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1770. )
  1771. {
  1772. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1773. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1774. )
  1775. {
  1776. struct tm tmFrom, tmTo;
  1777. struct timeb tbFrom, tbTo;
  1778. 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) &&
  1779. (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))
  1780. {
  1781. tmFrom.tm_year -= 1900;
  1782. tmFrom.tm_mon -= 1;
  1783. tbFrom.time = mktime(&tmFrom);
  1784. tmTo.tm_year -= 1900;
  1785. tmTo.tm_mon -= 1;
  1786. tbTo.time = mktime(&tmTo);
  1787. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1788. {
  1789. if(txProfile.ChargingProfileId == -1)
  1790. DEBUG_INFO("TxProfile found.\n");
  1791. else
  1792. DEBUG_INFO("TxProfile updated.\n");
  1793. // Required item
  1794. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1795. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1796. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1797. if(isUnitA)
  1798. {
  1799. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1800. 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++)
  1801. {
  1802. 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"));
  1803. 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?
  1804. 3:
  1805. 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")));
  1806. 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")));
  1807. }
  1808. }
  1809. else
  1810. {
  1811. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1812. 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++)
  1813. {
  1814. 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"));
  1815. 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?
  1816. 3:
  1817. 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")));
  1818. 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));
  1819. }
  1820. }
  1821. // Optional item
  1822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1823. {
  1824. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1825. }
  1826. else
  1827. {
  1828. sprintf((char*)txProfile.ValidFrom, " ");
  1829. }
  1830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1831. {
  1832. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1833. }
  1834. else
  1835. {
  1836. sprintf((char*)txProfile.ValidTo, " ");
  1837. }
  1838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1839. {
  1840. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1841. }
  1842. else
  1843. {
  1844. sprintf((char*)txProfile.RecurrencyKind, " ");
  1845. }
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1847. {
  1848. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1849. }
  1850. else
  1851. {
  1852. txProfile.TransactionId = -1;
  1853. }
  1854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1855. {
  1856. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1857. }
  1858. else
  1859. {
  1860. txProfile.ChargingSchedule.Duration = 86400;
  1861. }
  1862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1863. {
  1864. 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")));
  1865. }
  1866. else
  1867. {
  1868. 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));
  1869. }
  1870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1871. {
  1872. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1873. }
  1874. else
  1875. {
  1876. txProfile.ChargingSchedule.MinChargingRate = -1;
  1877. }
  1878. }
  1879. }
  1880. }
  1881. else
  1882. {
  1883. if(txProfile.ChargingProfileId == -1)
  1884. DEBUG_INFO("TxProfile found.\n");
  1885. else
  1886. DEBUG_INFO("TxProfile updated.\n");
  1887. // Required item
  1888. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1889. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1890. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1891. if(isUnitA)
  1892. {
  1893. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1894. 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++)
  1895. {
  1896. 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"));
  1897. 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?
  1898. 3:
  1899. 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")));
  1900. 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")));
  1901. }
  1902. }
  1903. else
  1904. {
  1905. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1906. 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++)
  1907. {
  1908. 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"));
  1909. 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?
  1910. 3:
  1911. 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")));
  1912. 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));
  1913. }
  1914. }
  1915. // Optional item
  1916. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1917. {
  1918. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)txProfile.ValidFrom, " ");
  1923. }
  1924. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. {
  1926. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1927. }
  1928. else
  1929. {
  1930. sprintf((char*)txProfile.ValidTo, " ");
  1931. }
  1932. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1933. {
  1934. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1935. }
  1936. else
  1937. {
  1938. sprintf((char*)txProfile.RecurrencyKind, " ");
  1939. }
  1940. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1941. {
  1942. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1943. }
  1944. else
  1945. {
  1946. txProfile.TransactionId = -1;
  1947. }
  1948. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1949. {
  1950. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1951. }
  1952. else
  1953. {
  1954. txProfile.ChargingSchedule.Duration = 86400;
  1955. }
  1956. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1957. {
  1958. 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")));
  1959. }
  1960. else
  1961. {
  1962. 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));
  1963. }
  1964. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1965. {
  1966. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1967. }
  1968. else
  1969. {
  1970. txProfile.ChargingSchedule.MinChargingRate = -1;
  1971. }
  1972. }
  1973. }
  1974. }
  1975. json_object_put(obj);
  1976. }
  1977. fclose(fp);
  1978. /*
  1979. if(txProfile.ChargingProfileId != -1)
  1980. {
  1981. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1982. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1983. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1984. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1985. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1986. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1987. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1988. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1989. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1990. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1991. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1993. {
  1994. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1995. {
  1996. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1997. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1998. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1999. }
  2000. }
  2001. }
  2002. else
  2003. DEBUG_INFO("TxProfile not found.\n");*/
  2004. }
  2005. // Search default tx profile
  2006. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2007. if((access(profileFileName, F_OK))==-1)
  2008. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2009. if((access(profileFileName, F_OK))!=-1)
  2010. {
  2011. fp = fopen(profileFileName, "r");
  2012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2013. {
  2014. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2017. }
  2018. defaultTxProfile.ChargingProfileId = -1;
  2019. defaultTxProfile.StackLevel = -1;
  2020. while(getline(&line, &len, fp) != -1)
  2021. {
  2022. json_object *obj = NULL;
  2023. obj = json_tokener_parse(line);
  2024. if(is_error(obj))
  2025. {
  2026. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2027. }
  2028. else
  2029. {
  2030. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2031. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2032. )
  2033. {
  2034. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2035. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2036. )
  2037. {
  2038. struct tm tmFrom, tmTo;
  2039. struct timeb tbFrom, tbTo;
  2040. 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) &&
  2041. (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))
  2042. {
  2043. tmFrom.tm_year -= 1900;
  2044. tmFrom.tm_mon -= 1;
  2045. tbFrom.time = mktime(&tmFrom);
  2046. tmTo.tm_year -= 1900;
  2047. tmTo.tm_mon -= 1;
  2048. tbTo.time = mktime(&tmTo);
  2049. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2050. {
  2051. if(defaultTxProfile.ChargingProfileId == -1)
  2052. DEBUG_INFO("TxDefaultProfile found.\n");
  2053. else
  2054. DEBUG_INFO("TxDefaultProfile updated.\n");
  2055. // Required item
  2056. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2057. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2058. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2059. if(isUnitA)
  2060. {
  2061. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2062. 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++)
  2063. {
  2064. 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"));
  2065. 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?
  2066. 3:
  2067. 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")));
  2068. 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")));
  2069. }
  2070. }
  2071. else
  2072. {
  2073. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2074. 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++)
  2075. {
  2076. 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"));
  2077. 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?
  2078. 3:
  2079. 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")));
  2080. 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));
  2081. }
  2082. }
  2083. // Optional item
  2084. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2085. {
  2086. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2091. }
  2092. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2093. {
  2094. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2095. }
  2096. else
  2097. {
  2098. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2099. }
  2100. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2101. {
  2102. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2103. }
  2104. else
  2105. {
  2106. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2107. }
  2108. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2109. {
  2110. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2111. }
  2112. else
  2113. {
  2114. defaultTxProfile.TransactionId = -1;
  2115. }
  2116. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2117. {
  2118. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2119. }
  2120. else
  2121. {
  2122. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2123. }
  2124. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2125. {
  2126. 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")));
  2127. }
  2128. else
  2129. {
  2130. 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));
  2131. }
  2132. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2133. {
  2134. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2135. }
  2136. else
  2137. {
  2138. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. else
  2144. {
  2145. if(defaultTxProfile.ChargingProfileId == -1)
  2146. DEBUG_INFO("TxDefaultProfile found.\n");
  2147. else
  2148. DEBUG_INFO("TxDefaultProfile updated.\n");
  2149. // Required item
  2150. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2151. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2152. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2153. if(isUnitA)
  2154. {
  2155. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2156. 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++)
  2157. {
  2158. 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"));
  2159. 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?
  2160. 3:
  2161. 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")));
  2162. 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")));
  2163. }
  2164. }
  2165. else
  2166. {
  2167. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2168. 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++)
  2169. {
  2170. 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"));
  2171. 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?
  2172. 3:
  2173. 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")));
  2174. 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));
  2175. }
  2176. }
  2177. // Optional item
  2178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2179. {
  2180. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2181. }
  2182. else
  2183. {
  2184. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2185. }
  2186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2187. {
  2188. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2193. }
  2194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2195. {
  2196. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2197. }
  2198. else
  2199. {
  2200. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2201. }
  2202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2203. {
  2204. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2205. }
  2206. else
  2207. {
  2208. defaultTxProfile.TransactionId = -1;
  2209. }
  2210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2211. {
  2212. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2213. }
  2214. else
  2215. {
  2216. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2217. }
  2218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2219. {
  2220. 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")));
  2221. }
  2222. else
  2223. {
  2224. 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));
  2225. }
  2226. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2227. {
  2228. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2229. }
  2230. else
  2231. {
  2232. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. json_object_put(obj);
  2238. }
  2239. fclose(fp);
  2240. /*
  2241. if(defaultTxProfile.ChargingProfileId != -1)
  2242. {
  2243. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2244. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2245. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2246. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2247. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2248. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2249. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2250. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2251. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2252. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2253. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2255. {
  2256. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2257. {
  2258. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2259. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2260. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2261. }
  2262. }
  2263. }
  2264. else
  2265. DEBUG_INFO("TxDefaultProfile not found.\n");
  2266. DEBUG_INFO("------------------------------------\n");*/
  2267. }
  2268. // Search max profile
  2269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2270. if((access(profileFileName, F_OK))!=-1)
  2271. {
  2272. fp = fopen(profileFileName, "r");
  2273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2274. {
  2275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2278. }
  2279. maxProfile.ChargingProfileId = -1;
  2280. maxProfile.StackLevel = -1;
  2281. while(getline(&line, &len, fp) != -1)
  2282. {
  2283. json_object *obj = NULL;
  2284. obj = json_tokener_parse(line);
  2285. if(is_error(obj))
  2286. {
  2287. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2288. }
  2289. else
  2290. {
  2291. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2292. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2293. )
  2294. {
  2295. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2296. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2297. )
  2298. {
  2299. struct tm tmFrom, tmTo;
  2300. struct timeb tbFrom, tbTo;
  2301. 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) &&
  2302. (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))
  2303. {
  2304. tmFrom.tm_year -= 1900;
  2305. tmFrom.tm_mon -= 1;
  2306. tbFrom.time = mktime(&tmFrom);
  2307. tmTo.tm_year -= 1900;
  2308. tmTo.tm_mon -= 1;
  2309. tbTo.time = mktime(&tmTo);
  2310. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2311. {
  2312. if(maxProfile.ChargingProfileId == -1)
  2313. DEBUG_INFO("MaxProfile found.\n");
  2314. else
  2315. DEBUG_INFO("MaxProfile updated.\n");
  2316. // Required item
  2317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2320. if(isUnitA)
  2321. {
  2322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2323. 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++)
  2324. {
  2325. 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"));
  2326. 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?
  2327. 3:
  2328. 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")));
  2329. 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")));
  2330. }
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. 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++)
  2336. {
  2337. 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"));
  2338. 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?
  2339. 3:
  2340. 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")));
  2341. 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));
  2342. }
  2343. }
  2344. // Optional item
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2346. {
  2347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)maxProfile.ValidFrom, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2354. {
  2355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ValidTo, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2362. {
  2363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2368. }
  2369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2370. {
  2371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2372. }
  2373. else
  2374. {
  2375. maxProfile.TransactionId = -1;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2378. {
  2379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2380. }
  2381. else
  2382. {
  2383. maxProfile.ChargingSchedule.Duration = 86400;
  2384. }
  2385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2386. {
  2387. 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")));
  2388. }
  2389. else
  2390. {
  2391. 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));
  2392. }
  2393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2394. {
  2395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2396. }
  2397. else
  2398. {
  2399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. else
  2405. {
  2406. if(maxProfile.ChargingProfileId == -1)
  2407. DEBUG_INFO("MaxProfile found.\n");
  2408. else
  2409. DEBUG_INFO("MaxProfile updated.\n");
  2410. // Required item
  2411. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2412. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2413. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2414. if(isUnitA)
  2415. {
  2416. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2417. 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++)
  2418. {
  2419. 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"));
  2420. 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?
  2421. 3:
  2422. 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")));
  2423. 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")));
  2424. }
  2425. }
  2426. else
  2427. {
  2428. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2429. 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++)
  2430. {
  2431. 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"));
  2432. 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?
  2433. 3:
  2434. 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")));
  2435. 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));
  2436. }
  2437. }
  2438. // Optional item
  2439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2440. {
  2441. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2442. }
  2443. else
  2444. {
  2445. sprintf((char*)maxProfile.ValidFrom, " ");
  2446. }
  2447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2448. {
  2449. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2450. }
  2451. else
  2452. {
  2453. sprintf((char*)maxProfile.ValidTo, " ");
  2454. }
  2455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2456. {
  2457. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2462. }
  2463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2464. {
  2465. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2466. }
  2467. else
  2468. {
  2469. maxProfile.TransactionId = -1;
  2470. }
  2471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2472. {
  2473. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2474. }
  2475. else
  2476. {
  2477. maxProfile.ChargingSchedule.Duration = 86400;
  2478. }
  2479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2480. {
  2481. 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")));
  2482. }
  2483. else
  2484. {
  2485. 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));
  2486. }
  2487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2488. {
  2489. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2490. }
  2491. else
  2492. {
  2493. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. json_object_put(obj);
  2499. }
  2500. fclose(fp);
  2501. /*
  2502. if(maxProfile.ChargingProfileId !=-1)
  2503. {
  2504. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2505. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2506. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2507. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2508. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2510. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2511. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2512. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2513. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2514. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2518. {
  2519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2522. }
  2523. }
  2524. }
  2525. else
  2526. DEBUG_INFO("MaxProfile not found.\n");
  2527. DEBUG_INFO("------------------------------------\n");*/
  2528. }
  2529. /*
  2530. * Align found profile start schedule & periods
  2531. */
  2532. //DEBUG_INFO("====================================\n");
  2533. /*
  2534. // For local test usage, force modify found profile start schedule info
  2535. 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);
  2536. 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);
  2537. 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);
  2538. */
  2539. if(txProfile.ChargingProfileId != -1)
  2540. {
  2541. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2542. {
  2543. if(txProfile.ChargingSchedule.Duration != -1)
  2544. {
  2545. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2546. 0:
  2547. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2548. }
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2552. {
  2553. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2554. 0:
  2555. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2556. if(idxPeriod > 0)
  2557. {
  2558. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2559. {
  2560. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2567. {
  2568. if(txProfile.ChargingSchedule.Duration != -1)
  2569. {
  2570. 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?
  2571. 0:
  2572. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2573. }
  2574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2575. {
  2576. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2577. {
  2578. 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?
  2579. 0:
  2580. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2581. if(idxPeriod > 0)
  2582. {
  2583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2584. {
  2585. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2586. }
  2587. }
  2588. }
  2589. }
  2590. }
  2591. else
  2592. {
  2593. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2594. {
  2595. if(txProfile.ChargingSchedule.Duration != -1)
  2596. {
  2597. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2598. 0:
  2599. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2600. }
  2601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2602. {
  2603. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2604. {
  2605. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2606. 0:
  2607. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2608. if(idxPeriod > 0)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2611. {
  2612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. else
  2619. {
  2620. if(txProfile.ChargingSchedule.Duration != -1)
  2621. {
  2622. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2623. 0:
  2624. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2625. }
  2626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2627. {
  2628. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2629. {
  2630. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2631. 0:
  2632. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2633. if(idxPeriod > 0)
  2634. {
  2635. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2636. {
  2637. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. /*
  2645. DEBUG_INFO("txProfile after align.\n");
  2646. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2647. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2648. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2649. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2650. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2651. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2652. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2653. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2654. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2655. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2656. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2657. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2658. {
  2659. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2660. {
  2661. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2662. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2663. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2664. }
  2665. }*/
  2666. }
  2667. if(defaultTxProfile.ChargingProfileId != -1)
  2668. {
  2669. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2670. {
  2671. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2674. 0:
  2675. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2682. 0:
  2683. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2684. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2685. {
  2686. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2687. }
  2688. if(idxPeriod > 0)
  2689. {
  2690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2691. {
  2692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2693. }
  2694. }
  2695. }
  2696. }
  2697. }
  2698. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2699. {
  2700. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2701. {
  2702. 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?
  2703. 0:
  2704. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2705. }
  2706. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2707. {
  2708. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2709. {
  2710. 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?
  2711. 0:
  2712. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2713. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2716. }
  2717. if(idxPeriod > 0)
  2718. {
  2719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2720. {
  2721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. else
  2728. {
  2729. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2732. {
  2733. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2734. 0:
  2735. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2736. }
  2737. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2738. {
  2739. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2740. {
  2741. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2742. 0:
  2743. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2745. {
  2746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2747. }
  2748. if(idxPeriod > 0)
  2749. {
  2750. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. else
  2759. {
  2760. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2761. {
  2762. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2763. 0:
  2764. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2765. }
  2766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2767. {
  2768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2769. {
  2770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2771. 0:
  2772. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2773. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2774. {
  2775. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2776. }
  2777. if(idxPeriod > 0)
  2778. {
  2779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2780. {
  2781. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2782. }
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. /*
  2789. DEBUG_INFO("defaultTxProfile after align.\n");
  2790. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2791. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2792. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2793. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2794. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2795. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2796. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2797. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2798. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2799. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2800. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2802. {
  2803. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2804. {
  2805. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2806. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2807. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2808. }
  2809. }
  2810. DEBUG_INFO("------------------------------------\n");*/
  2811. }
  2812. if(maxProfile.ChargingProfileId != -1)
  2813. {
  2814. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2815. {
  2816. if(maxProfile.ChargingSchedule.Duration != -1)
  2817. {
  2818. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2819. 0:
  2820. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2821. }
  2822. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2823. {
  2824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2825. {
  2826. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2827. 0:
  2828. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2829. if(idxPeriod > 0)
  2830. {
  2831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2832. {
  2833. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2834. }
  2835. }
  2836. }
  2837. }
  2838. }
  2839. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2840. {
  2841. if(maxProfile.ChargingSchedule.Duration != -1)
  2842. {
  2843. 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?
  2844. 0:
  2845. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2846. }
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2850. {
  2851. 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?
  2852. 0:
  2853. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2854. if(idxPeriod > 0)
  2855. {
  2856. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2857. {
  2858. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2867. {
  2868. if(maxProfile.ChargingSchedule.Duration != -1)
  2869. {
  2870. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2871. 0:
  2872. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2873. }
  2874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2875. {
  2876. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2877. {
  2878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2879. 0:
  2880. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2881. if(idxPeriod > 0)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2884. {
  2885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2886. }
  2887. }
  2888. }
  2889. }
  2890. }
  2891. else
  2892. {
  2893. if(maxProfile.ChargingSchedule.Duration != -1)
  2894. {
  2895. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2896. 0:
  2897. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2898. }
  2899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2900. {
  2901. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2902. {
  2903. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2904. 0:
  2905. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2906. if(idxPeriod > 0)
  2907. {
  2908. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2909. {
  2910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. /*
  2918. DEBUG_INFO("MaxProfile after align.\n");
  2919. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2920. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2921. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2922. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2923. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2924. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2925. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2926. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2927. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2928. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2929. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2930. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2931. {
  2932. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2933. {
  2934. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2935. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2936. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2937. }
  2938. }
  2939. DEBUG_INFO("------------------------------------\n");*/
  2940. }
  2941. /*
  2942. * Merge to conposite schedule
  2943. */
  2944. //DEBUG_INFO("====================================\n");
  2945. // Find each profile period quantity
  2946. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2947. {
  2948. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2949. limitMax = idx+1;
  2950. }
  2951. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2952. {
  2953. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2954. limitDef = idx+1;
  2955. }
  2956. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2957. {
  2958. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2959. limitTx = idx+1;
  2960. }
  2961. // TxProfile found, composite schedule based on it
  2962. if(txProfile.ChargingProfileId != -1)
  2963. {
  2964. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2965. {
  2966. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2967. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2968. (txProfile.ChargingSchedule.Duration > 0))
  2969. {
  2970. if(maxProfile.ChargingProfileId != -1)
  2971. {
  2972. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2973. {
  2974. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2975. {
  2976. if((maxProfile.ChargingSchedule.Duration > 0))
  2977. {
  2978. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2979. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2980. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2981. }
  2982. else
  2983. {
  2984. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2985. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2986. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2987. }
  2988. }
  2989. if(idxMaxPeriod == (limitMax-1))
  2990. {
  2991. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2992. {
  2993. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2994. {
  2995. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2996. compositePeriodIdx++;
  2997. }
  2998. else
  2999. {
  3000. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3001. }
  3002. }
  3003. }
  3004. }
  3005. }
  3006. else
  3007. {
  3008. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3009. {
  3010. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3011. compositePeriodIdx++;
  3012. }
  3013. else
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3016. }
  3017. }
  3018. }
  3019. if(idxTxPeriod == (limitTx-1))
  3020. {
  3021. if(defaultTxProfile.ChargingProfileId != -1)
  3022. {
  3023. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3024. {
  3025. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3026. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3027. (defaultTxProfile.ChargingSchedule.Duration>0))
  3028. {
  3029. if(maxProfile.ChargingProfileId != -1)
  3030. {
  3031. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3032. {
  3033. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3034. {
  3035. if((maxProfile.ChargingSchedule.Duration > 0))
  3036. {
  3037. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3038. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3039. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3040. }
  3041. else
  3042. {
  3043. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3044. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3045. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3046. }
  3047. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3048. {
  3049. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3050. {
  3051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3052. compositePeriodIdx++;
  3053. }
  3054. else
  3055. {
  3056. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3057. }
  3058. }
  3059. // Delete duplicate period
  3060. if(compositePeriodIdx > 1)
  3061. {
  3062. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3063. {
  3064. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3065. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3066. compositePeriodIdx -= 1;
  3067. }
  3068. }
  3069. }
  3070. else
  3071. break;
  3072. }
  3073. }
  3074. else
  3075. {
  3076. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3077. {
  3078. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3079. compositePeriodIdx++;
  3080. }
  3081. else
  3082. {
  3083. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3084. }
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. }
  3092. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3093. else if(defaultTxProfile.ChargingProfileId != -1)
  3094. {
  3095. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3096. {
  3097. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3098. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3099. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3100. {
  3101. if(maxProfile.ChargingProfileId != -1)
  3102. {
  3103. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3104. {
  3105. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3106. {
  3107. if((maxProfile.ChargingSchedule.Duration > 0))
  3108. {
  3109. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3110. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3111. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3112. }
  3113. else
  3114. {
  3115. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3116. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3117. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3118. }
  3119. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3120. {
  3121. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3122. {
  3123. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3124. compositePeriodIdx++;
  3125. }
  3126. else
  3127. {
  3128. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3129. }
  3130. }
  3131. // Delete duplicate period
  3132. if(compositePeriodIdx > 1)
  3133. {
  3134. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3135. {
  3136. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3137. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3138. compositePeriodIdx -= 1;
  3139. }
  3140. }
  3141. }
  3142. else
  3143. break;
  3144. }
  3145. }
  3146. else
  3147. {
  3148. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3149. {
  3150. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3151. compositePeriodIdx++;
  3152. }
  3153. else
  3154. {
  3155. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. // Fill other period by MaxProfile
  3162. if(maxProfile.ChargingProfileId != -1)
  3163. {
  3164. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3165. {
  3166. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3167. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3168. (maxProfile.ChargingSchedule.Duration > 0))
  3169. {
  3170. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3171. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3172. {
  3173. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3174. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3175. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3176. }
  3177. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3178. {
  3179. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3180. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3181. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3182. }
  3183. if(tmpPeriod.Limit != -1)
  3184. {
  3185. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3186. {
  3187. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3188. {
  3189. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3190. compositePeriodIdx++;
  3191. }
  3192. else
  3193. {
  3194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3195. }
  3196. }
  3197. // Delete duplicate period
  3198. if(compositePeriodIdx > 1)
  3199. {
  3200. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3201. {
  3202. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3203. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3204. compositePeriodIdx -= 1;
  3205. }
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3212. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3213. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3214. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3216. {
  3217. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3218. {
  3219. compositeProfile->ChargingProfileId = 1;
  3220. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3221. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3222. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3223. }
  3224. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3225. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3226. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3227. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3228. }
  3229. if(line)
  3230. free(line);
  3231. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3232. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3233. }
  3234. //==========================================
  3235. // Init all share memory
  3236. //==========================================
  3237. int InitShareMemory()
  3238. {
  3239. int result = PASS;
  3240. int MeterSMId;
  3241. //creat ShmSysConfigAndInfo
  3242. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3243. {
  3244. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3245. result = FAIL;
  3246. }
  3247. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3248. {
  3249. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3250. result = FAIL;
  3251. }
  3252. else
  3253. {}
  3254. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3255. {
  3256. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3257. result = FAIL;
  3258. }
  3259. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3260. {
  3261. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3262. result = FAIL;
  3263. }
  3264. else
  3265. {}
  3266. //creat ShmPsuData
  3267. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3268. {
  3269. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3270. result = FAIL;
  3271. }
  3272. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3273. {
  3274. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3275. result = FAIL;
  3276. }
  3277. else
  3278. {}
  3279. //creat ShmOCPP16Data
  3280. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3281. {
  3282. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3283. result = FAIL;
  3284. }
  3285. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3286. {
  3287. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3288. result = FAIL;
  3289. }
  3290. else
  3291. {}
  3292. /****************************** For Initial Settings************************************************/
  3293. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3294. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3295. // allocate Configuration memory address
  3296. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3297. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3298. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3299. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3300. //offline MeterValue Interval
  3301. TempMeterValueInterval = 0;
  3302. return result;
  3303. }
  3304. int ProcessShareMemory()
  3305. {
  3306. if(InitShareMemory() == FAIL)
  3307. {
  3308. DEBUG_ERROR("InitShareMemory NG\n");
  3309. if(ShmStatusCodeData!=NULL)
  3310. {
  3311. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3312. }
  3313. sleep(5);
  3314. return FAIL;
  3315. }
  3316. return PASS;
  3317. }
  3318. void CheckSystemValue(void)
  3319. {
  3320. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3321. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3322. char filenmae[100]={0};
  3323. char str[100]={0};
  3324. int tempIndex = 0;
  3325. //===============================
  3326. // send Heartbeat
  3327. //===============================
  3328. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3329. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3330. {
  3331. clientTime.Heartbeat=time((time_t*)NULL);
  3332. if(server_sign == TRUE)
  3333. {
  3334. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3335. }
  3336. else
  3337. {
  3338. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3339. }
  3340. }
  3341. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3342. {
  3343. //parameter for test
  3344. sendHeartbeatRequest(0);
  3345. //==============================================
  3346. // Reset Waiting Time
  3347. //==============================================
  3348. HeartBeatWithNOResponse += 1;
  3349. }
  3350. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3351. {
  3352. //==========================================
  3353. // csu trigger DataTransferReq
  3354. //==========================================
  3355. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3356. {
  3357. sendDataTransferRequest(gun_index);
  3358. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3359. }
  3360. //===============================
  3361. // CSU Trigger Authorize Request
  3362. //===============================
  3363. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3364. {
  3365. sendAuthorizeRequest(0);
  3366. authorizeRetryTimes = authorizeRetryTimes + 1;
  3367. if(authorizeRetryTimes < 3)
  3368. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3369. }
  3370. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3371. {
  3372. authorizeRetryTimes = 0;
  3373. SetOcppConnStatus(FALSE);
  3374. server_sign = FALSE;
  3375. }
  3376. 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))
  3377. {
  3378. sendAuthorizeRequest(0);
  3379. }
  3380. //==============================================
  3381. // Charger start transaction
  3382. //==============================================
  3383. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3384. {
  3385. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3386. sendStartTransactionRequest(gun_index);
  3387. clientTime.StartTransaction = time((time_t*)NULL);
  3388. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3389. storeTempStopTransaction(gun_index);
  3390. }
  3391. //==============================================
  3392. // Charger stop transaction
  3393. //==============================================
  3394. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3395. {
  3396. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3397. sendStopTransactionRequest(gun_index);
  3398. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3399. clientTime.StopTransaction = time((time_t*)NULL);
  3400. }
  3401. //==============================================
  3402. // Charger status report
  3403. //==============================================
  3404. //--- Check Mode Change ---//
  3405. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3407. {
  3408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3409. {
  3410. tempIndex = ((gun_index==2) ? 1: 0);
  3411. }
  3412. else
  3413. {
  3414. tempIndex = gun_index;
  3415. }
  3416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3417. {
  3418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3419. {
  3420. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3421. {
  3422. // Sent unplug message for California pricing logic
  3423. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3424. {
  3425. uint8_t ts[20];
  3426. getNowDatetime(ts);
  3427. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3428. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3429. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3430. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3431. }
  3432. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3433. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3434. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3435. }
  3436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3437. {
  3438. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3439. if((access(filenmae,F_OK))!=-1)
  3440. {
  3441. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3442. sprintf(str,"rm -f %s",filenmae);
  3443. system(str);
  3444. }
  3445. }
  3446. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3447. #if 1 // for TempStopTransaction
  3448. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3449. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3450. {
  3451. checkTempStopTransaction(gun_index);
  3452. }
  3453. #endif
  3454. }
  3455. }
  3456. }
  3457. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3458. {
  3459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3460. {
  3461. tempIndex = ((gun_index==2) ? 1: 0);
  3462. }
  3463. else
  3464. {
  3465. tempIndex = gun_index;
  3466. }
  3467. for (int index = 0; index < CCS_QUANTITY; index++)
  3468. {
  3469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3470. {
  3471. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  3472. {
  3473. // Sent unplug message for California pricing logic
  3474. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3475. {
  3476. uint8_t ts[20];
  3477. getNowDatetime(ts);
  3478. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3480. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3481. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3482. }
  3483. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3484. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3485. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3486. }
  3487. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3488. {
  3489. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3490. if((access(filenmae,F_OK))!=-1)
  3491. {
  3492. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3493. sprintf(str,"rm -f %s",filenmae);
  3494. system(str);
  3495. }
  3496. }
  3497. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3498. #if 1 // for TempStopTransaction
  3499. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3500. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3501. {
  3502. checkTempStopTransaction(gun_index);
  3503. }
  3504. #endif
  3505. }
  3506. }
  3507. }
  3508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3509. {
  3510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3511. {
  3512. tempIndex = ((gun_index==2) ? 1: 0);
  3513. }
  3514. else
  3515. {
  3516. tempIndex = gun_index;
  3517. }
  3518. for (int index = 0; index < GB_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3521. {
  3522. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3523. {
  3524. // Sent unplug message for California pricing logic
  3525. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3526. {
  3527. uint8_t ts[20];
  3528. getNowDatetime(ts);
  3529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3531. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3532. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3533. }
  3534. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3535. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3536. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3537. }
  3538. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3539. {
  3540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3541. if((access(filenmae,F_OK))!=-1)
  3542. {
  3543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3544. sprintf(str,"rm -f %s",filenmae);
  3545. system(str);
  3546. }
  3547. }
  3548. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3549. #if 1 // for TempStopTransaction
  3550. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3551. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3552. {
  3553. checkTempStopTransaction(gun_index);
  3554. }
  3555. #endif
  3556. }
  3557. }
  3558. }
  3559. else if(gunType[gun_index] == GUN_TYPE_DO)
  3560. {
  3561. tempIndex = gun_index;
  3562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3563. {
  3564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3565. {
  3566. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3567. {
  3568. // Sent unplug message for California pricing logic
  3569. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3570. {
  3571. uint8_t ts[20];
  3572. getNowDatetime(ts);
  3573. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3574. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3575. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3576. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3577. }
  3578. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3579. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3580. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3581. }
  3582. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  3583. {
  3584. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3585. if((access(filenmae,F_OK))!=-1)
  3586. {
  3587. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3588. sprintf(str,"rm -f %s",filenmae);
  3589. system(str);
  3590. }
  3591. }
  3592. 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);
  3593. #if 1 // for TempStopTransaction
  3594. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3595. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3596. {
  3597. checkTempStopTransaction(gun_index);
  3598. }
  3599. #endif
  3600. }
  3601. }
  3602. }
  3603. else
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3606. {
  3607. tempIndex = 2;
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < AC_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3616. {
  3617. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3618. {
  3619. // Sent unplug message for California pricing logic
  3620. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3621. {
  3622. uint8_t ts[20];
  3623. getNowDatetime(ts);
  3624. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3625. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3627. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3628. }
  3629. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3630. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3631. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3632. }
  3633. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3634. {
  3635. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3636. if((access(filenmae,F_OK))!=-1)
  3637. {
  3638. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3639. sprintf(str,"rm -f %s",filenmae);
  3640. system(str);
  3641. }
  3642. }
  3643. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3644. #if 1 // for TempStopTransaction
  3645. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3646. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3647. {
  3648. checkTempStopTransaction(gun_index);
  3649. }
  3650. #endif
  3651. }
  3652. }// END
  3653. }
  3654. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3655. (
  3656. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3657. )
  3658. )
  3659. {
  3660. if(SystemInitial > 0)
  3661. SystemInitial -= 1;
  3662. sendStatusNotificationRequest(gun_index);
  3663. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3664. }
  3665. //==============================================
  3666. // CSU Trigger Smart Charging Profilw
  3667. //==============================================
  3668. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3669. {
  3670. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3671. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3672. }
  3673. //==============================================
  3674. // Meter report
  3675. //==============================================
  3676. // Trigger MeterValue
  3677. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3678. {
  3679. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3680. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3681. }
  3682. // ClockAlign MeterValue
  3683. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3684. {
  3685. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3696. {
  3697. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3698. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3699. {
  3700. reqClockAlignMeter[gun_index] = 1;
  3701. }
  3702. }// End for CHAdeMO
  3703. }
  3704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((gun_index==2) ? 1: 0);
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3717. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. reqClockAlignMeter[gun_index] = 1;
  3720. }
  3721. } // End for CCS
  3722. }
  3723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3726. {
  3727. tempIndex = ((gun_index==2) ? 1: 0);
  3728. }
  3729. else
  3730. {
  3731. tempIndex = gun_index;
  3732. }
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3736. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3737. {
  3738. reqClockAlignMeter[gun_index] = 1;
  3739. }
  3740. }// End for GB
  3741. }
  3742. else if(gunType[gun_index] == GUN_TYPE_DO)
  3743. {
  3744. tempIndex = gun_index;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3748. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3749. {
  3750. reqClockAlignMeter[gun_index] = 1;
  3751. }
  3752. }
  3753. }
  3754. else
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3757. {
  3758. tempIndex = 2;
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < AC_QUANTITY; index++)
  3765. {
  3766. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3767. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3768. {
  3769. reqClockAlignMeter[gun_index] = 1;
  3770. }
  3771. }//End for AC
  3772. }
  3773. if(reqClockAlignMeter[gun_index] == 1)
  3774. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3775. }
  3776. // Sample period MeterValue
  3777. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3778. {
  3779. //check Transaction active
  3780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3783. {
  3784. tempIndex = ((gun_index==2) ? 1: 0);
  3785. }
  3786. else
  3787. {
  3788. tempIndex = gun_index;
  3789. }
  3790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3791. {
  3792. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3793. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3794. {
  3795. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3796. {
  3797. reqSampleMeter[gun_index] = 1;
  3798. }
  3799. }
  3800. }// End for CHAdeMO
  3801. }
  3802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3803. {
  3804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3805. {
  3806. tempIndex = ((gun_index==2) ? 1: 0);
  3807. }
  3808. else
  3809. {
  3810. tempIndex = gun_index;
  3811. }
  3812. for (int index = 0; index < CCS_QUANTITY; index++)
  3813. {
  3814. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3815. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3816. {
  3817. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3818. {
  3819. reqSampleMeter[gun_index] = 1;
  3820. }
  3821. }
  3822. } // End for CCS
  3823. }
  3824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3825. {
  3826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3827. {
  3828. tempIndex = ((gun_index==2) ? 1: 0);
  3829. }
  3830. else
  3831. {
  3832. tempIndex = gun_index;
  3833. }
  3834. for (int index = 0; index < GB_QUANTITY; index++)
  3835. {
  3836. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3837. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3838. {
  3839. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3840. {
  3841. reqSampleMeter[gun_index] = 1;
  3842. }
  3843. }
  3844. }// End for GB
  3845. }
  3846. else if(gunType[gun_index] == GUN_TYPE_DO)
  3847. {
  3848. tempIndex = gun_index;
  3849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3850. {
  3851. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3852. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3853. {
  3854. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3855. {
  3856. reqSampleMeter[gun_index] = 1;
  3857. }
  3858. }
  3859. }
  3860. }
  3861. else
  3862. {
  3863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3864. {
  3865. tempIndex = 2;
  3866. }
  3867. else
  3868. {
  3869. tempIndex = gun_index;
  3870. }
  3871. for (int index = 0; index < AC_QUANTITY; index++)
  3872. {
  3873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3875. {
  3876. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3877. {
  3878. reqSampleMeter[gun_index] = 1;
  3879. }
  3880. }
  3881. }//End for AC
  3882. }
  3883. if(reqSampleMeter[gun_index] == 1)
  3884. {
  3885. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3886. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3887. storeTempStopTransaction(gun_index);
  3888. }
  3889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3890. }
  3891. //==============================================
  3892. // Check Connector reserved
  3893. //==============================================
  3894. //===============================
  3895. // Check if Reserve is expired
  3896. //===============================
  3897. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3898. {
  3899. double diff_t;
  3900. struct tm tp;
  3901. // current time
  3902. time_t t = time(NULL);
  3903. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3904. tp.tm_isdst = -1;
  3905. time_t utc = mktime(&tp);
  3906. diff_t = difftime(utc, t);
  3907. if(diff_t <= 0)
  3908. {
  3909. DEBUG_INFO("reserve expired.\n");
  3910. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3911. }
  3912. }//END OF Check if Reserve is expired
  3913. //==========================================
  3914. // csu trigger FirmwareStatusNotificationReq
  3915. //==========================================
  3916. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3917. {
  3918. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3919. }
  3920. //==========================================
  3921. // csu trigger DiagnosticsStatusNotificationReq
  3922. //==========================================
  3923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3924. {
  3925. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3926. }
  3927. //==========================================
  3928. // csu trigger CancelReservationConf
  3929. //==========================================
  3930. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3931. {
  3932. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3933. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3934. }
  3935. //==========================================
  3936. // csu trigger ChangeAvailabilityConf
  3937. //==========================================
  3938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3939. {
  3940. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3941. }
  3942. //==========================================
  3943. // csu trigger UnlockConnectorConf
  3944. //==========================================
  3945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3946. {
  3947. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3948. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3949. }
  3950. //==========================================
  3951. // csu trigger ReserveNowConf
  3952. //==========================================
  3953. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3954. {
  3955. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3956. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3957. }
  3958. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3959. {
  3960. sendSignCertificateRequest();
  3961. }
  3962. }
  3963. }
  3964. //==========================================
  3965. // send request routine
  3966. //==========================================
  3967. int sendAuthorizeRequest(int gun_index)
  3968. {
  3969. mtrace();
  3970. int result = FAIL;
  3971. char message[100]={0};
  3972. char guid[37];
  3973. char tempdata[65]={0};
  3974. DEBUG_INFO("sendAuthorizeRequest...\n");
  3975. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3976. //Local Authorize
  3977. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3978. {
  3979. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3980. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3981. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3982. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3983. result = PASS;
  3984. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3985. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3986. authorizeRetryTimes = 0;
  3987. return result;
  3988. }
  3989. 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))||
  3990. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3991. {
  3992. // Query from cache
  3993. DEBUG_INFO("Authorize from cache.\n");
  3994. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3995. // Query from list
  3996. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3997. {
  3998. DEBUG_INFO("Authorize from list.\n");
  3999. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4000. }
  4001. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4002. {
  4003. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4004. {
  4005. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4006. }
  4007. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4008. {
  4009. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4010. }
  4011. if(!GetOcppConnStatus())
  4012. {
  4013. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4015. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4016. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4017. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4018. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4019. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4020. authorizeRetryTimes = 0;
  4021. return result;
  4022. }
  4023. }
  4024. else
  4025. {
  4026. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4027. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4028. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4029. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4030. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4031. else
  4032. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4033. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4034. result = PASS;
  4035. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4036. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4037. authorizeRetryTimes = 0;
  4038. return result;
  4039. }
  4040. }
  4041. //initialize struct Authorize
  4042. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4043. //get data from shared memory
  4044. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4045. random_uuid(guid);
  4046. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4047. LWS_Send(message);
  4048. sprintf(tempdata, "Authorize,%d", gun_index);
  4049. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4050. {
  4051. result = PASS;
  4052. DEBUG_INFO("Authorize mapItem pass\n");
  4053. }
  4054. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4055. return result;
  4056. }
  4057. int sendBootNotificationRequest(void)
  4058. {
  4059. mtrace();
  4060. int result = FAIL;
  4061. char message[500]={0}, payload[700]={0};
  4062. char guid[37]={0};
  4063. char tempdata[65]={0};
  4064. // Fill BootNotification fields
  4065. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4066. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4067. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4068. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4069. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4070. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4071. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4072. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4073. ShmOCPP16Data->ChargeBoxId
  4074. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4075. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4076. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4077. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4078. ,ShmOCPP16Data->BootNotification.CpIccid
  4079. ,ShmOCPP16Data->BootNotification.CpImsi);
  4080. random_uuid(guid);
  4081. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4082. LWS_Send(message);
  4083. sprintf(tempdata, "BootNotification,0");
  4084. 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*/)
  4085. {
  4086. result = PASS;
  4087. }
  4088. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4089. strcpy(queuedata,message);
  4090. return result;
  4091. }
  4092. int sendDataTransferRequest(int gun_index)
  4093. {
  4094. mtrace();
  4095. char message[1000]={0};
  4096. char guid[37]={0};
  4097. char tempdata[65]={0};
  4098. int result = FAIL;
  4099. random_uuid(guid);
  4100. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4101. MESSAGE_TYPE_CALL,
  4102. guid,
  4103. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4104. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4105. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4106. LWS_Send(message);
  4107. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4108. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4109. {
  4110. result = PASS;
  4111. DEBUG_INFO("DataTransfer mapItem pass\n");
  4112. }
  4113. return result;
  4114. }
  4115. int sendDiagnosticsStatusNotificationRequest(char *status)
  4116. {
  4117. mtrace();
  4118. int result = FAIL;
  4119. char message[110]={0};
  4120. char guid[37]={0};
  4121. char tempdata[65]={0};
  4122. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4123. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4124. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4125. random_uuid(guid);
  4126. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4127. LWS_SendNow(message);
  4128. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4129. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4130. {
  4131. result = PASS;
  4132. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4133. }
  4134. //#ifdef SystemLogMessage
  4135. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4136. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4137. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4138. //#endif
  4139. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4140. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4141. //record status
  4142. if(strcmp(status,"Idle")==0)
  4143. {
  4144. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4145. }
  4146. else if(strcmp(status,"Uploaded")==0)
  4147. {
  4148. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4149. }
  4150. else if(strcmp(status,"UploadFailed")==0)
  4151. {
  4152. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4153. }
  4154. else if(strcmp(status,"Uploading")==0)
  4155. {
  4156. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4157. }
  4158. return result;
  4159. }
  4160. int sendFirmwareStatusNotificationRequest(char *status)
  4161. {
  4162. mtrace();
  4163. int result = FAIL;
  4164. char message[110]={0};
  4165. char guid[37]={0};
  4166. char tempdata[65]={0};
  4167. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4168. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4169. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4170. random_uuid(guid);
  4171. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4172. LWS_SendNow(message);
  4173. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4174. 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*/)
  4175. {
  4176. result = PASS;
  4177. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4178. }
  4179. //#ifdef SystemLogMessage
  4180. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4181. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4182. //#endif
  4183. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4184. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4185. //record status
  4186. if(strcmp(status,"Downloaded")==0)
  4187. {
  4188. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4189. }
  4190. else if(strcmp(status,"DownloadFailed")==0)
  4191. {
  4192. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4193. }
  4194. else if(strcmp(status,"Downloading")==0)
  4195. {
  4196. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4197. }
  4198. else if(strcmp(status,"Idle")==0)
  4199. {
  4200. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4201. }
  4202. else if(strcmp(status,"InstallationFailed")==0)
  4203. {
  4204. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4205. }
  4206. else if(strcmp(status,"Installing")==0)
  4207. {
  4208. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4209. }
  4210. else if(strcmp(status,"Installed")==0)
  4211. {
  4212. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4213. }
  4214. return result;
  4215. }
  4216. int sendHeartbeatRequest(int gun_index)
  4217. {
  4218. mtrace();
  4219. int result = FAIL;
  4220. char message[80]={0};
  4221. char guid[37]={0};
  4222. char tempdata[65]={0};
  4223. random_uuid(guid);
  4224. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4225. , MESSAGE_TYPE_CALL
  4226. , guid );
  4227. LWS_Send(message);
  4228. sprintf(tempdata, "Heartbeat,%d", 0);
  4229. 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*/)
  4230. {
  4231. result = PASS;
  4232. }
  4233. return result;
  4234. }
  4235. int sendStartTransactionRequest(int gun_index)
  4236. {
  4237. mtrace();
  4238. int result = FAIL;
  4239. char message[250]={0};
  4240. char guid[37]={0};
  4241. struct timeval tmnow;
  4242. struct tm *tm;
  4243. char buf[28];//, usec_buf[6];
  4244. char tempdata[65]={0};
  4245. int tempIndex = 0;
  4246. DEBUG_INFO("sendStartTransactionRequest...\n");
  4247. gettimeofday(&tmnow, NULL);
  4248. time_t t;
  4249. t = time(NULL);
  4250. /*UTC time and date*/
  4251. tm = gmtime(&t);
  4252. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4253. #if 0 // remove temporally
  4254. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4255. strcat(buf,".");
  4256. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4257. strcat(buf,usec_buf);
  4258. #endif
  4259. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4260. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4261. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4262. // clear StartTransaction Response
  4263. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4264. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4265. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4266. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4267. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4268. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4269. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4270. {
  4271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4272. {
  4273. tempIndex = ((gun_index==2) ? 1: 0);
  4274. }
  4275. else
  4276. {
  4277. tempIndex = gun_index;
  4278. }
  4279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4282. {
  4283. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4284. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4285. }
  4286. }
  4287. }
  4288. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4289. {
  4290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4291. {
  4292. tempIndex = ((gun_index==2) ? 1: 0);
  4293. }
  4294. else
  4295. {
  4296. tempIndex = gun_index;
  4297. }
  4298. for (int index = 0; index < CCS_QUANTITY; index++)
  4299. {
  4300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4301. {
  4302. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4303. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4304. }
  4305. }
  4306. }
  4307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < GB_QUANTITY; index++)
  4318. {
  4319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4320. {
  4321. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4322. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4323. }
  4324. }
  4325. }
  4326. else if(gunType[gun_index] == GUN_TYPE_DO)
  4327. {
  4328. tempIndex = gun_index;
  4329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4332. {
  4333. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4334. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4335. }
  4336. }
  4337. }
  4338. else
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4341. {
  4342. tempIndex = 2;
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < AC_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4351. {
  4352. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4353. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4354. }
  4355. }
  4356. }
  4357. random_uuid(guid);
  4358. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4359. {
  4360. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4361. , gun_index +1
  4362. , MESSAGE_TYPE_CALL
  4363. , guid
  4364. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4365. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4366. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4367. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4368. }
  4369. else
  4370. {
  4371. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4372. , gun_index +1
  4373. , MESSAGE_TYPE_CALL
  4374. , guid
  4375. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4376. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4377. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4378. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4379. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4380. }
  4381. #if 1
  4382. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4383. 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*/)
  4384. {
  4385. result = PASS;
  4386. }
  4387. #endif
  4388. strcpy(queuedata, message);
  4389. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4390. OCPP_insert_transaction_msg(YES, queuedata);
  4391. return result;
  4392. }
  4393. int sendStatusNotificationRequest(int gun_index)
  4394. {
  4395. mtrace();
  4396. int result = FAIL;
  4397. char message[600]={0};
  4398. char guid[37];
  4399. int currentStatus = 0;
  4400. struct timeval tmnow;
  4401. struct tm *tm;
  4402. char buf[28];//, usec_buf[6];
  4403. char tempdata[65]={0};
  4404. int tempIndex = 0;
  4405. uint8_t isStateChanged = TRUE;
  4406. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4407. gettimeofday(&tmnow, NULL);
  4408. time_t t;
  4409. t = time(NULL);
  4410. /*UTC time and date*/
  4411. tm = gmtime(&t);
  4412. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4413. #if 0 // remove temporally
  4414. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4415. strcat(buf,".");
  4416. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4417. strcat(buf,usec_buf);
  4418. #endif
  4419. //printf("%s",buf);
  4420. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4421. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4422. // it's option
  4423. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4424. /*
  4425. enum _SYSTEM_STATUS
  4426. {
  4427. S_BOOTING = 0,
  4428. S_IDLE, = 1
  4429. S_AUTHORIZING, =2
  4430. S_REASSIGN_CHECK, =3
  4431. S_REASSIGN, =4
  4432. S_PRECHARGE, =5
  4433. S_PREPARING_FOR_EV, =6
  4434. S_PREPARING_FOR_EVSE, =7
  4435. S_CHARGING, =8
  4436. S_TERMINATING, =9
  4437. S_COMPLETE, =10
  4438. S_ALARM, =11
  4439. S_FAULT =12
  4440. }
  4441. */
  4442. //check Transaction active
  4443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4445. {
  4446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4447. {
  4448. tempIndex = ((gun_index==2) ? 1: 0);
  4449. }
  4450. else
  4451. {
  4452. tempIndex = gun_index;
  4453. }
  4454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4455. {
  4456. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4457. {
  4458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4459. {
  4460. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4461. {
  4462. currentStatus = Preparing; //OCPP Status: Preparing
  4463. }
  4464. else
  4465. {
  4466. currentStatus = Available; //OCPP Status: Available
  4467. }
  4468. }
  4469. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4470. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4471. ) //S_PRECHARGE
  4472. {
  4473. currentStatus = Preparing; //OCPP Status: Preparing
  4474. }
  4475. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4476. {
  4477. currentStatus = Charging; //OCPP Status: Charging
  4478. }
  4479. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4480. {
  4481. currentStatus = Finishing; //OCPP Status: Finishing
  4482. }
  4483. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4484. {
  4485. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4486. }
  4487. 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
  4488. {
  4489. currentStatus = Unavailable; //OCPP Status: Unavailable
  4490. }
  4491. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4492. {
  4493. currentStatus = Faulted; //OCPP Status: Faulted
  4494. }
  4495. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4496. {
  4497. currentStatus = Reserved; //OCPP Status: Reserved
  4498. }
  4499. } //end of the same index
  4500. }//end of for CHAdeMO_QUANTITY
  4501. }
  4502. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4503. {
  4504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4505. {
  4506. tempIndex = ((gun_index==2) ? 1: 0);
  4507. }
  4508. else
  4509. {
  4510. tempIndex = gun_index;
  4511. }
  4512. for (int index = 0; index < CCS_QUANTITY; index++)
  4513. {
  4514. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4515. {
  4516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4517. {
  4518. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4519. {
  4520. currentStatus = Preparing; //OCPP Status: Preparing
  4521. }
  4522. else
  4523. {
  4524. currentStatus = Available; //OCPP Status: Available
  4525. }
  4526. }
  4527. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4528. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4529. ) //S_PRECHARGE
  4530. {
  4531. currentStatus = Preparing; //OCPP Status: Preparing
  4532. }
  4533. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4534. {
  4535. currentStatus = Charging; //OCPP Status: Charging
  4536. }
  4537. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4538. {
  4539. currentStatus = Finishing; //OCPP Status: Finishing
  4540. }
  4541. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4542. {
  4543. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4544. }
  4545. 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
  4546. {
  4547. currentStatus = Unavailable; //OCPP Status : Unavailable
  4548. }
  4549. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4550. {
  4551. currentStatus = Faulted; //OCPP Status: Faulted
  4552. }
  4553. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4554. {
  4555. currentStatus = Reserved; //OCPP Status: Reserved
  4556. }
  4557. } //end of the same index
  4558. } // end of for CCS_QUANTITY
  4559. }
  4560. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4561. {
  4562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4563. {
  4564. tempIndex = ((gun_index==2) ? 1: 0);
  4565. }
  4566. else
  4567. {
  4568. tempIndex = gun_index;
  4569. }
  4570. for (int index = 0; index < GB_QUANTITY; index++)
  4571. {
  4572. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4573. {
  4574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4575. {
  4576. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4577. {
  4578. currentStatus = Preparing; //OCPP Status: Preparing
  4579. }
  4580. else
  4581. {
  4582. currentStatus = Available; //OCPP Status: Available
  4583. }
  4584. }
  4585. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4586. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4587. ) //S_PRECHARGE
  4588. {
  4589. currentStatus = Preparing; //OCPP Status: Preparing
  4590. }
  4591. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4592. {
  4593. currentStatus = Charging; //OCPP Status: Charging
  4594. }
  4595. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4596. {
  4597. currentStatus = Finishing; //OCPP Status: Finishing
  4598. }
  4599. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4600. {
  4601. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4602. }
  4603. 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
  4604. {
  4605. currentStatus = Unavailable; //OCPP Status: Unavailable
  4606. }
  4607. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4608. {
  4609. currentStatus = Faulted; //OCPP Status: Faulted
  4610. }
  4611. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4612. {
  4613. currentStatus = Reserved; //OCPP Status: Reserved
  4614. }
  4615. } //end of the same index
  4616. } // end of for GB_QUANTITY
  4617. }
  4618. else if(gunType[gun_index] == GUN_TYPE_DO)
  4619. {
  4620. tempIndex = gun_index;
  4621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4622. {
  4623. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4624. {
  4625. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4626. {
  4627. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4628. {
  4629. currentStatus = Preparing; //OCPP Status: Preparing
  4630. }
  4631. else
  4632. {
  4633. currentStatus = Available; //OCPP Status: Available
  4634. }
  4635. }
  4636. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4637. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4638. ) //S_PRECHARGE
  4639. {
  4640. currentStatus = Preparing; //OCPP Status: Preparing
  4641. }
  4642. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4643. {
  4644. currentStatus = Charging; //OCPP Status: Charging
  4645. }
  4646. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4647. {
  4648. currentStatus = Finishing; //OCPP Status: Finishing
  4649. }
  4650. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4651. {
  4652. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4653. }
  4654. 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
  4655. {
  4656. currentStatus = Unavailable; //OCPP Status: Unavailable
  4657. }
  4658. 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
  4659. {
  4660. currentStatus = Faulted; //OCPP Status: Faulted
  4661. }
  4662. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4663. {
  4664. currentStatus = Reserved; //OCPP Status: Reserved
  4665. }
  4666. } //end of the same index
  4667. }
  4668. }
  4669. else
  4670. {
  4671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4672. {
  4673. tempIndex = 2;
  4674. }
  4675. else
  4676. {
  4677. tempIndex = gun_index;
  4678. }
  4679. for (int index = 0; index < AC_QUANTITY; index++)
  4680. {
  4681. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4682. {
  4683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4684. {
  4685. 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))
  4686. {
  4687. currentStatus = Preparing; //OCPP Status: Preparing
  4688. }
  4689. else
  4690. {
  4691. currentStatus = Available; //OCPP Status: Available
  4692. }
  4693. }
  4694. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4695. {
  4696. currentStatus = Preparing; //OCPP Status: Preparing
  4697. }
  4698. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4699. {
  4700. currentStatus = Charging; //OCPP Status: Charging
  4701. }
  4702. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4703. {
  4704. currentStatus = Finishing; //OCPP Status: Finishing
  4705. }
  4706. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4707. {
  4708. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4709. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4710. else
  4711. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4712. }
  4713. 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
  4714. {
  4715. currentStatus = Unavailable; //OCPP Status: Unavailable
  4716. }
  4717. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4718. {
  4719. currentStatus = Faulted; //OCPP Status: Faulted
  4720. }
  4721. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4722. {
  4723. currentStatus = Reserved; //OCPP Status: Reserved
  4724. }
  4725. }//end of the same index
  4726. }//end of for AC_QUANTITY
  4727. }
  4728. //it's option
  4729. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4730. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4731. {
  4732. isStateChanged = FALSE;
  4733. }
  4734. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4735. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4736. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4737. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4738. random_uuid(guid);
  4739. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4740. , MESSAGE_TYPE_CALL
  4741. , guid
  4742. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4743. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4744. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4745. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4746. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4747. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4748. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4749. if((server_sign == TRUE) && isStateChanged)
  4750. {
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4753. 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*/)
  4754. {
  4755. //DEBUG_ERROR("statusNotification mapitem pass");
  4756. result = PASS;
  4757. }
  4758. }
  4759. else
  4760. {
  4761. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4762. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4763. result = PASS;
  4764. }
  4765. return result;
  4766. }
  4767. int sendStopTransactionRequest(int gun_index)
  4768. {
  4769. mtrace();
  4770. int result = FAIL;
  4771. //char message[1500]={0};
  4772. char guid[37]={0};
  4773. char tempdata[65]={0};
  4774. int tempIndex = 0;
  4775. char TempStopTransaction[256];
  4776. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4777. //int idx_sample=0;
  4778. DEBUG_INFO("sendStopTransactionRequest \n");
  4779. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4780. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4781. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4784. {
  4785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4786. {
  4787. tempIndex = ((gun_index==2) ? 1: 0);
  4788. }
  4789. else
  4790. {
  4791. tempIndex = gun_index;
  4792. }
  4793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4796. {
  4797. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4798. }
  4799. }// END OF CHAdeMO_QUANTITY
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < CCS_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4814. {
  4815. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4816. }
  4817. }// END OF CCS_QUANTITY
  4818. }
  4819. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4820. {
  4821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4822. {
  4823. tempIndex = ((gun_index==2) ? 1: 0);
  4824. }
  4825. else
  4826. {
  4827. tempIndex = gun_index;
  4828. }
  4829. for (int index = 0; index < GB_QUANTITY; index++)
  4830. {
  4831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4832. {
  4833. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4834. }
  4835. }// END OF GB_QUANTITY
  4836. }
  4837. else if(gunType[gun_index] == GUN_TYPE_DO)
  4838. {
  4839. tempIndex = gun_index;
  4840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4841. {
  4842. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4843. {
  4844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4845. }
  4846. }// END OF GB_QUANTITY
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4863. }
  4864. }// END OF AC_QUANTITY
  4865. }
  4866. //====================================== Stop Transaction Time =====================================================
  4867. struct timeval tmnow;
  4868. struct tm *tm;
  4869. char buf[28];//, usec_buf[6];
  4870. gettimeofday(&tmnow, NULL);
  4871. time_t t;
  4872. t = time(NULL);
  4873. /*UTC time and date*/
  4874. tm = gmtime(&t);
  4875. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4877. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4878. random_uuid(guid);
  4879. /***********************************transactionData******************************************************/
  4880. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4882. //=================================
  4883. // Transaction_Begin
  4884. //=================================
  4885. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4886. {
  4887. //============================================ Energy.Active.Import.Interval ================================
  4888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4891. 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*/]);
  4892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4893. 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))
  4894. {
  4895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4896. }
  4897. else
  4898. {
  4899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4903. }
  4904. //=================================
  4905. // Transaction_End
  4906. //=================================
  4907. // ================================= Current.Import L1 ===============================================
  4908. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4909. {
  4910. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4912. {
  4913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4914. {
  4915. tempIndex = ((gun_index==2) ? 1: 0);
  4916. }
  4917. else
  4918. {
  4919. tempIndex = gun_index;
  4920. }
  4921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4922. {
  4923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4924. {
  4925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4926. }
  4927. }// End of for CHAdeMO_QUANTITY
  4928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4929. }
  4930. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4931. {
  4932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4933. {
  4934. tempIndex = ((gun_index==2) ? 1: 0);
  4935. }
  4936. else
  4937. {
  4938. tempIndex = gun_index;
  4939. }
  4940. for (int index = 0; index < CCS_QUANTITY; index++)
  4941. {
  4942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4943. {
  4944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4945. }
  4946. }// End of for CCS_QUANTITY
  4947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4948. }
  4949. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4950. {
  4951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4952. {
  4953. tempIndex = ((gun_index==2) ? 1: 0);
  4954. }
  4955. else
  4956. {
  4957. tempIndex = gun_index;
  4958. }
  4959. for (int index = 0; index < GB_QUANTITY; index++)
  4960. {
  4961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4962. {
  4963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4964. }
  4965. }// End of for GB_QUANTITY
  4966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_DO)
  4969. {
  4970. tempIndex = gun_index;
  4971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4972. {
  4973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4974. {
  4975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4976. }
  4977. }
  4978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4979. }
  4980. else
  4981. {
  4982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4983. {
  4984. tempIndex = 2;
  4985. }
  4986. else
  4987. {
  4988. tempIndex = gun_index;
  4989. }
  4990. for (int index = 0; index < AC_QUANTITY; index++)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4993. {
  4994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4995. }
  4996. }// End of for AC_QUANTITY
  4997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4998. }
  4999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5004. }
  5005. // ================================= Energy.Active.Import.Interval ==============================================
  5006. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5007. {
  5008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5010. {
  5011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5012. {
  5013. tempIndex = ((gun_index==2) ? 1: 0);
  5014. }
  5015. else
  5016. {
  5017. tempIndex = gun_index;
  5018. }
  5019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5022. {
  5023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5024. }
  5025. }// END OF CHAdeMO_QUANTITY
  5026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5027. }
  5028. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5029. {
  5030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5031. {
  5032. tempIndex = ((gun_index==2) ? 1: 0);
  5033. }
  5034. else
  5035. {
  5036. tempIndex = gun_index;
  5037. }
  5038. for (int index = 0; index < CCS_QUANTITY; index++)
  5039. {
  5040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5041. {
  5042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5043. }
  5044. }// END OF CCS_QUANTITY
  5045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5046. }
  5047. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5048. {
  5049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5050. {
  5051. tempIndex = ((gun_index==2) ? 1: 0);
  5052. }
  5053. else
  5054. {
  5055. tempIndex = gun_index;
  5056. }
  5057. for (int index = 0; index < GB_QUANTITY; index++)
  5058. {
  5059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5060. {
  5061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5062. }
  5063. }// END OF GB_QUANTITY
  5064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5065. }
  5066. else if(gunType[gun_index] == GUN_TYPE_DO)
  5067. {
  5068. tempIndex = gun_index;
  5069. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5072. {
  5073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5074. }
  5075. }
  5076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5077. }
  5078. else
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5081. {
  5082. tempIndex = 2;
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < AC_QUANTITY; index++)
  5089. {
  5090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5091. {
  5092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5093. }
  5094. }// END OF AC_QUANTITY
  5095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5096. }
  5097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5102. }
  5103. //=================================== Power.Active.Import ==================================================
  5104. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5105. {
  5106. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5107. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5110. {
  5111. tempIndex = ((gun_index==2) ? 1: 0);
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5122. }
  5123. } // End for CHAdeMO_QUANTITY
  5124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5125. }
  5126. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5127. {
  5128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5129. {
  5130. tempIndex = ((gun_index==2) ? 1: 0);
  5131. }
  5132. else
  5133. {
  5134. tempIndex = gun_index;
  5135. }
  5136. for (int index = 0; index < CCS_QUANTITY; index++)
  5137. {
  5138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5139. {
  5140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5141. }
  5142. } // END for CCS_QUANTITY
  5143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5144. }
  5145. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5146. {
  5147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5148. {
  5149. tempIndex = ((gun_index==2) ? 1: 0);
  5150. }
  5151. else
  5152. {
  5153. tempIndex = gun_index;
  5154. }
  5155. for (int index = 0; index < GB_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5160. }
  5161. }// END for GB_QUANTITY
  5162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else if(gunType[gun_index] == GUN_TYPE_DO)
  5165. {
  5166. tempIndex = gun_index;
  5167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5170. {
  5171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5172. }
  5173. }
  5174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5175. }
  5176. else
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5179. {
  5180. tempIndex = 2;
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < AC_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5189. {
  5190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5191. }
  5192. } // END for AC_QUANTITY
  5193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5194. }
  5195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5200. }
  5201. //============================ Voltage L1 ====================================
  5202. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5203. {
  5204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5206. {
  5207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5208. {
  5209. tempIndex = ((gun_index==2) ? 1: 0);
  5210. }
  5211. else
  5212. {
  5213. tempIndex = gun_index;
  5214. }
  5215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5216. {
  5217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5218. {
  5219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5220. }
  5221. } // END OF FOR CHAdeMO_QUANTITY
  5222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5223. }
  5224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5225. {
  5226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5227. {
  5228. tempIndex = ((gun_index==2) ? 1: 0);
  5229. }
  5230. else
  5231. {
  5232. tempIndex = gun_index;
  5233. }
  5234. for (int index = 0; index < CCS_QUANTITY; index++)
  5235. {
  5236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5237. {
  5238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5239. }
  5240. } // END OF FOR CCS_QUANTITY
  5241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5242. }
  5243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5244. {
  5245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5246. {
  5247. tempIndex = ((gun_index==2) ? 1: 0);
  5248. }
  5249. else
  5250. {
  5251. tempIndex = gun_index;
  5252. }
  5253. for (int index = 0; index < GB_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5258. }
  5259. } // END OF FOR GB_QUANTITY
  5260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5261. }
  5262. else if(gunType[gun_index] == GUN_TYPE_DO)
  5263. {
  5264. tempIndex = gun_index;
  5265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5266. {
  5267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5268. {
  5269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5270. }
  5271. }
  5272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5273. }
  5274. else
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5277. {
  5278. tempIndex = 2;
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < AC_QUANTITY; index++)
  5285. {
  5286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5287. {
  5288. 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
  5289. }
  5290. } // END OF FOR AC_QUANTITY
  5291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5292. }
  5293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5298. }
  5299. //====================== End SoC ================================
  5300. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5301. {
  5302. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5303. 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))
  5304. {
  5305. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5306. {
  5307. tempIndex = ((gun_index==2) ? 1: 0);
  5308. }
  5309. else
  5310. {
  5311. tempIndex = gun_index;
  5312. }
  5313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5314. {
  5315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5316. {
  5317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5318. {
  5319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5320. }
  5321. }
  5322. }
  5323. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5324. {
  5325. for (int index = 0; index < CCS_QUANTITY; index++)
  5326. {
  5327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5328. {
  5329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5330. }
  5331. }
  5332. }
  5333. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5334. {
  5335. for (int index = 0; index < GB_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5340. }
  5341. }
  5342. }
  5343. else if(gunType[gun_index] == GUN_TYPE_DO)
  5344. {
  5345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5346. {
  5347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5348. {
  5349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5350. }
  5351. }
  5352. }
  5353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5359. } // END FOR DC CASE
  5360. }
  5361. // ================================= Current.Import L2 ===============================================
  5362. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5363. {
  5364. // AC 3 phse L2 current
  5365. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5366. {
  5367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5368. {
  5369. tempIndex = 2;
  5370. }
  5371. else
  5372. {
  5373. tempIndex = gun_index;
  5374. }
  5375. for (int index = 0; index < AC_QUANTITY; index++)
  5376. {
  5377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5378. {
  5379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5380. }
  5381. }// End of for AC_QUANTITY
  5382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5383. }
  5384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5389. }
  5390. // ================================= Current.Import L3 ===============================================
  5391. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5392. {
  5393. // AC 3 phse L3 current
  5394. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5395. {
  5396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5397. {
  5398. tempIndex = 2;
  5399. }
  5400. else
  5401. {
  5402. tempIndex = gun_index;
  5403. }
  5404. for (int index = 0; index < AC_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5407. {
  5408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5409. }
  5410. }// End of for AC_QUANTITY
  5411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5412. }
  5413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5418. }
  5419. //============================ Voltage L2 ====================================
  5420. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5421. {
  5422. // AC 3 phse L2 voltage
  5423. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5426. {
  5427. tempIndex = 2;
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5436. {
  5437. 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
  5438. }
  5439. } // END OF FOR AC_QUANTITY
  5440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5441. }
  5442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5447. }
  5448. //============================ Voltage L3 ====================================
  5449. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5450. {
  5451. // AC 3 phse L3 voltage
  5452. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5453. {
  5454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5455. {
  5456. tempIndex = 2;
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. for (int index = 0; index < AC_QUANTITY; index++)
  5463. {
  5464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5465. {
  5466. 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
  5467. }
  5468. } // END OF FOR AC_QUANTITY
  5469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5470. }
  5471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5476. }
  5477. //====================== Start SoC ================================
  5478. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5479. {
  5480. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5481. 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))
  5482. {
  5483. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5484. {
  5485. tempIndex = ((gun_index==2) ? 1: 0);
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5492. {
  5493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5494. {
  5495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5496. {
  5497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5498. }
  5499. }
  5500. }
  5501. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5502. {
  5503. for (int index = 0; index < CCS_QUANTITY; index++)
  5504. {
  5505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5506. {
  5507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5508. }
  5509. }
  5510. }
  5511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5512. {
  5513. for (int index = 0; index < GB_QUANTITY; index++)
  5514. {
  5515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5516. {
  5517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5518. }
  5519. }
  5520. }
  5521. else if(gunType[gun_index] == GUN_TYPE_DO)
  5522. {
  5523. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5524. {
  5525. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5526. {
  5527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5528. }
  5529. }
  5530. }
  5531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5537. } // END FOR DC CASE
  5538. }
  5539. //================================================ Message create ====================================================
  5540. json_object *StopTransaction = json_object_new_object();
  5541. json_object *transactionDatas = json_object_new_array();
  5542. json_object *sampledValues = json_object_new_array();
  5543. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5544. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5545. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5546. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5547. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5549. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5550. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5551. {
  5552. json_object *transactionData = json_object_new_object();
  5553. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5554. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5555. {
  5556. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5557. {
  5558. json_object *sampledValue = json_object_new_object();
  5559. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5561. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5563. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5565. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5567. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5569. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5571. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5572. json_object_array_add(sampledValues, sampledValue);
  5573. }
  5574. }
  5575. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5576. json_object_array_add(transactionDatas, transactionData);
  5577. }
  5578. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5579. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5580. ,MESSAGE_TYPE_CALL
  5581. ,guid
  5582. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5583. json_object_put(StopTransaction);
  5584. #if 1 // for TempStopTransaction
  5585. //Delete TempStopTransaction
  5586. if((access(TempStopTransaction,F_OK))!=-1)
  5587. {
  5588. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5589. }
  5590. #endif
  5591. #if 1
  5592. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5593. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5594. {
  5595. result = PASS;
  5596. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5597. }
  5598. #endif
  5599. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5600. OCPP_insert_transaction_msg(NO, queuedata);
  5601. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5602. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5603. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5604. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5605. {
  5606. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5607. }
  5608. //for test
  5609. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5610. return result;
  5611. }
  5612. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5613. {
  5614. mtrace();
  5615. int result = FAIL;
  5616. char guid[37]={0};
  5617. char tempdata[65]={0};
  5618. int tempIndex = 0;
  5619. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5620. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5621. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5622. //set value
  5623. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5624. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5625. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5626. -1);
  5627. random_uuid(guid);
  5628. //UTC Date time
  5629. struct timeval tmnow;
  5630. struct tm *tm;
  5631. char buf[28];//, usec_buf[6];
  5632. gettimeofday(&tmnow, NULL);
  5633. time_t t;
  5634. t = time(NULL);
  5635. /*UTC time and date*/
  5636. tm = gmtime(&t);
  5637. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5639. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5640. //********************************(1)Current.Import L1************************************************/
  5641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5643. (dataType == ReadingContext_Trigger))
  5644. {
  5645. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5647. {
  5648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5649. {
  5650. tempIndex = ((gun_index==2) ? 1: 0);
  5651. }
  5652. else
  5653. {
  5654. tempIndex = gun_index;
  5655. }
  5656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5659. {
  5660. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5661. }
  5662. }
  5663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5664. }
  5665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5666. {
  5667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5668. {
  5669. tempIndex = ((gun_index==2) ? 1: 0);
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. for (int index = 0; index < CCS_QUANTITY; index++)
  5676. {
  5677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5678. {
  5679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5680. }
  5681. }
  5682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5683. }
  5684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5685. {
  5686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5687. {
  5688. tempIndex = ((gun_index==2) ? 1: 0);
  5689. }
  5690. else
  5691. {
  5692. tempIndex = gun_index;
  5693. }
  5694. for (int index = 0; index < GB_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5697. {
  5698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5699. }
  5700. }
  5701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5702. }
  5703. else if(gunType[gun_index] == GUN_TYPE_DO)
  5704. {
  5705. tempIndex = gun_index;
  5706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5707. {
  5708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5709. {
  5710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5711. }
  5712. }
  5713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5714. }
  5715. else
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5718. {
  5719. tempIndex = 2;
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < AC_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5730. }
  5731. }
  5732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5733. }
  5734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5739. }
  5740. //********************************(2)Energy.Active.Import.Register ************************************************/
  5741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5743. (dataType == ReadingContext_Trigger))
  5744. {
  5745. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5747. {
  5748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5749. {
  5750. tempIndex = ((gun_index==2) ? 1: 0);
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5757. {
  5758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5759. {
  5760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5761. }
  5762. }
  5763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5764. }
  5765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5766. {
  5767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5768. {
  5769. tempIndex = ((gun_index==2) ? 1: 0);
  5770. }
  5771. else
  5772. {
  5773. tempIndex = gun_index;
  5774. }
  5775. for (int index = 0; index < CCS_QUANTITY; index++)
  5776. {
  5777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5778. {
  5779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5780. }
  5781. }
  5782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5783. }
  5784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5787. {
  5788. tempIndex = ((gun_index==2) ? 1: 0);
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < GB_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5799. }
  5800. }
  5801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5802. }
  5803. else if(gunType[gun_index] == GUN_TYPE_DO)
  5804. {
  5805. tempIndex = gun_index;
  5806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5807. {
  5808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5809. {
  5810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5811. }
  5812. }
  5813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5814. }
  5815. else
  5816. {
  5817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5818. {
  5819. tempIndex = 2;
  5820. }
  5821. else
  5822. {
  5823. tempIndex = gun_index;
  5824. }
  5825. for (int index = 0; index < AC_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5828. {
  5829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5830. }
  5831. }
  5832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5833. }
  5834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5839. }
  5840. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5843. (dataType == ReadingContext_Trigger))
  5844. {
  5845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5849. {
  5850. tempIndex = ((gun_index==2) ? 1: 0);
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5861. }
  5862. } // END OF FOR CHAdeMO_QUANTITY
  5863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5866. {
  5867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5868. {
  5869. tempIndex = ((gun_index==2) ? 1: 0);
  5870. }
  5871. else
  5872. {
  5873. tempIndex = gun_index;
  5874. }
  5875. for (int index = 0; index < CCS_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5878. {
  5879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5880. }
  5881. } // END OF CCS_QUANTITY
  5882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5883. }
  5884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5885. {
  5886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5887. {
  5888. tempIndex = ((gun_index==2) ? 1: 0);
  5889. }
  5890. else
  5891. {
  5892. tempIndex = gun_index;
  5893. }
  5894. for (int index = 0; index < GB_QUANTITY; index++)
  5895. {
  5896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5897. {
  5898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5899. }
  5900. } // END OF GB_QUANTITY
  5901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5902. }
  5903. else if(gunType[gun_index] == GUN_TYPE_DO)
  5904. {
  5905. tempIndex = gun_index;
  5906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5909. {
  5910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5911. }
  5912. }
  5913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5914. }
  5915. else
  5916. {
  5917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5918. {
  5919. tempIndex = 2;
  5920. }
  5921. else
  5922. {
  5923. tempIndex = gun_index;
  5924. }
  5925. for (int index = 0; index < AC_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5928. {
  5929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5930. }
  5931. }
  5932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5933. }
  5934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5939. }
  5940. //********************************(4)Power.Active.Import************************************************/
  5941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5943. (dataType == ReadingContext_Trigger))
  5944. {
  5945. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5947. {
  5948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5949. {
  5950. tempIndex = ((gun_index==2) ? 1: 0);
  5951. }
  5952. else
  5953. {
  5954. tempIndex = gun_index;
  5955. }
  5956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5959. {
  5960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5961. }
  5962. } // END OF FOR
  5963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5964. }
  5965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5966. {
  5967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5968. {
  5969. tempIndex = ((gun_index==2) ? 1: 0);
  5970. }
  5971. else
  5972. {
  5973. tempIndex = gun_index;
  5974. }
  5975. for (int index = 0; index < CCS_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5978. {
  5979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5980. }
  5981. }
  5982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5983. }
  5984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5985. {
  5986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5987. {
  5988. tempIndex = ((gun_index==2) ? 1: 0);
  5989. }
  5990. else
  5991. {
  5992. tempIndex = gun_index;
  5993. }
  5994. for (int index = 0; index < GB_QUANTITY; index++)
  5995. {
  5996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5997. {
  5998. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6000. }
  6001. }
  6002. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6003. }
  6004. else if(gunType[gun_index] == GUN_TYPE_DO)
  6005. {
  6006. tempIndex = gun_index;
  6007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6008. {
  6009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6010. {
  6011. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6013. }
  6014. }
  6015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6016. }
  6017. else
  6018. {
  6019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6020. {
  6021. tempIndex = 2;
  6022. }
  6023. else
  6024. {
  6025. tempIndex = gun_index;
  6026. }
  6027. for (int index = 0; index < AC_QUANTITY; index++)
  6028. {
  6029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6030. {
  6031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6032. }
  6033. }
  6034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6035. }
  6036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6041. }
  6042. //***********************************************(5)VOLTAGE L1******************************************************/
  6043. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6044. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6045. (dataType == ReadingContext_Trigger))
  6046. {
  6047. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6049. {
  6050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6051. {
  6052. tempIndex = ((gun_index==2) ? 1: 0);
  6053. }
  6054. else
  6055. {
  6056. tempIndex = gun_index;
  6057. }
  6058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6059. {
  6060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6061. {
  6062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6063. }
  6064. }
  6065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6066. }
  6067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6068. {
  6069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. for (int index = 0; index < CCS_QUANTITY; index++)
  6078. {
  6079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6080. {
  6081. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6082. }
  6083. }
  6084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6085. }
  6086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6087. {
  6088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6089. {
  6090. tempIndex = ((gun_index==2) ? 1: 0);
  6091. }
  6092. else
  6093. {
  6094. tempIndex = gun_index;
  6095. }
  6096. for (int index = 0; index < GB_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6099. {
  6100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6101. }
  6102. }
  6103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6104. }
  6105. else if(gunType[gun_index] == GUN_TYPE_DO)
  6106. {
  6107. tempIndex = gun_index;
  6108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6113. }
  6114. }
  6115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6116. }
  6117. else
  6118. {
  6119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6120. {
  6121. tempIndex = 2;
  6122. }
  6123. else
  6124. {
  6125. tempIndex = gun_index;
  6126. }
  6127. for (int index = 0; index < AC_QUANTITY; index++)
  6128. {
  6129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6130. {
  6131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6132. }
  6133. }
  6134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6135. }
  6136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6141. }
  6142. //***********************************************(6)SOC******************************************************/
  6143. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6144. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6145. (dataType == ReadingContext_Trigger))
  6146. {
  6147. 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))
  6148. {
  6149. //idx_sample=5;
  6150. //sampledValue = NULL;
  6151. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6160. {
  6161. //tempIndex = ((gun_index==2) ? 1: 0);
  6162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6165. {
  6166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6167. }
  6168. }
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6171. {
  6172. //tempIndex = ((gun_index==2) ? 1: 0);
  6173. for (int index = 0; index < CCS_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6178. }
  6179. }
  6180. }
  6181. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6182. {
  6183. //tempIndex = ((gun_index==2) ? 1: 0);
  6184. for (int index = 0; index < GB_QUANTITY; index++)
  6185. {
  6186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6187. {
  6188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6189. }
  6190. }
  6191. }
  6192. else if(gunType[gun_index] == GUN_TYPE_DO)
  6193. {
  6194. //tempIndex = ((gun_index==2) ? 1: 0);
  6195. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6196. {
  6197. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6198. {
  6199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6200. }
  6201. }
  6202. }
  6203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6209. }
  6210. }
  6211. //********************************(7)Current.Import L2************************************************/
  6212. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6213. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6214. (dataType == ReadingContext_Trigger))
  6215. {
  6216. // Only for AC 3 phase
  6217. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6218. {
  6219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6220. {
  6221. tempIndex = 2;
  6222. }
  6223. else
  6224. {
  6225. tempIndex = gun_index;
  6226. }
  6227. for (int index = 0; index < AC_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6232. }
  6233. }
  6234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6235. }
  6236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6241. }
  6242. //********************************(8)Current.Import L3************************************************/
  6243. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6244. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6245. (dataType == ReadingContext_Trigger))
  6246. {
  6247. // Only for AC 3 phase
  6248. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6249. {
  6250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6251. {
  6252. tempIndex = 2;
  6253. }
  6254. else
  6255. {
  6256. tempIndex = gun_index;
  6257. }
  6258. for (int index = 0; index < AC_QUANTITY; index++)
  6259. {
  6260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6261. {
  6262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6263. }
  6264. }
  6265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6266. }
  6267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6272. }
  6273. //***********************************************(9)VOLTAGE L2******************************************************/
  6274. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6275. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6276. (dataType == ReadingContext_Trigger))
  6277. {
  6278. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6279. {
  6280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6281. {
  6282. tempIndex = 2;
  6283. }
  6284. else
  6285. {
  6286. tempIndex = gun_index;
  6287. }
  6288. for (int index = 0; index < AC_QUANTITY; index++)
  6289. {
  6290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6291. {
  6292. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6293. }
  6294. }
  6295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6296. }
  6297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6302. }
  6303. //***********************************************(10)VOLTAGE L3******************************************************/
  6304. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6305. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6306. (dataType == ReadingContext_Trigger))
  6307. {
  6308. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6311. {
  6312. tempIndex = 2;
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < AC_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6321. {
  6322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6323. }
  6324. }
  6325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6326. }
  6327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6332. }
  6333. //***********************************************(11)Current.Offered******************************************************/
  6334. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6335. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6336. (dataType == ReadingContext_Trigger))
  6337. {
  6338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6354. }
  6355. } // END OF FOR CHAdeMO_QUANTITY
  6356. }
  6357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6360. {
  6361. tempIndex = ((gun_index==2) ? 1: 0);
  6362. }
  6363. else
  6364. {
  6365. tempIndex = gun_index;
  6366. }
  6367. for (int index = 0; index < CCS_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6372. }
  6373. } // END OF CCS_QUANTITY
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6376. {
  6377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6378. {
  6379. tempIndex = ((gun_index==2) ? 1: 0);
  6380. }
  6381. else
  6382. {
  6383. tempIndex = gun_index;
  6384. }
  6385. for (int index = 0; index < GB_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6390. }
  6391. } // END OF GB_QUANTITY
  6392. }
  6393. else if(gunType[gun_index] == GUN_TYPE_DO)
  6394. {
  6395. tempIndex = gun_index;
  6396. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6397. {
  6398. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6399. {
  6400. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6401. }
  6402. }
  6403. }
  6404. else
  6405. {
  6406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6407. {
  6408. tempIndex = 2;
  6409. }
  6410. else
  6411. {
  6412. tempIndex = gun_index;
  6413. }
  6414. for (int index = 0; index < AC_QUANTITY; index++)
  6415. {
  6416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6417. {
  6418. uint16_t currentOffer;
  6419. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6420. {
  6421. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6422. }
  6423. else
  6424. {
  6425. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6426. }
  6427. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6428. }
  6429. }
  6430. }
  6431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6436. }
  6437. //***********************************************(12)Power.Offered******************************************************/
  6438. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6439. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6440. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6441. {
  6442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6443. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6444. {
  6445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6446. {
  6447. tempIndex = ((gun_index==2) ? 1: 0);
  6448. }
  6449. else
  6450. {
  6451. tempIndex = gun_index;
  6452. }
  6453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6454. {
  6455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6456. {
  6457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*10));
  6458. }
  6459. } // END OF FOR CHAdeMO_QUANTITY
  6460. }
  6461. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < CCS_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*10));
  6476. }
  6477. } // END OF CCS_QUANTITY
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < GB_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*10));
  6494. }
  6495. } // END OF GB_QUANTITY
  6496. }
  6497. else if(gunType[gun_index] == GUN_TYPE_DO)
  6498. {
  6499. tempIndex = gun_index;
  6500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6503. {
  6504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*10));
  6505. }
  6506. }
  6507. }
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Power_Offered]);
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6513. }
  6514. // Message create ====================================================================================================
  6515. if(TRUE)
  6516. {
  6517. json_object *MeterValueReq = json_object_new_object();
  6518. json_object *MeterValues = json_object_new_array();
  6519. json_object *sampledValues = json_object_new_array();
  6520. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6521. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6522. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6523. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6524. {
  6525. json_object *MeterValue = json_object_new_object();
  6526. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6527. {
  6528. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6529. {
  6530. json_object *sampledValue = json_object_new_object();
  6531. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6532. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6533. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6534. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6535. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6536. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6537. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6538. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6539. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6541. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6542. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6543. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6544. json_object_array_add(sampledValues, sampledValue);
  6545. }
  6546. }
  6547. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6548. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6549. json_object_array_add(MeterValues, MeterValue);
  6550. }
  6551. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6552. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6553. ,gun_index + 1
  6554. ,MESSAGE_TYPE_CALL
  6555. ,guid
  6556. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6557. json_object_put(MeterValueReq);
  6558. }
  6559. // Put request guid to hash map
  6560. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6561. 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*/)
  6562. {
  6563. result = PASS;
  6564. //DEBUG_INFO("MeterValues mapitem pass\n");
  6565. }
  6566. if((dataType != ReadingContext_Trigger) &&
  6567. (dataType != ReadingContext_Sample_Clock) &&
  6568. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6569. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6570. else
  6571. {
  6572. if(FirstHeartBeat)
  6573. LWS_Send(queuedata +2);
  6574. }
  6575. return result;
  6576. }
  6577. int sendLogStatusNotificationRequest(char *status)
  6578. {
  6579. mtrace();
  6580. int result = PASS;
  6581. char message[4096]={0};
  6582. char guid[37]={0};
  6583. char tempdata[128]={0};
  6584. json_object *LogStatusNotification = json_object_new_object();
  6585. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6586. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6587. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6588. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6589. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6590. random_uuid(guid);
  6591. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6592. json_object_put(LogStatusNotification);
  6593. LWS_Send(message);
  6594. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6595. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6596. {
  6597. result = PASS;
  6598. }
  6599. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6600. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6601. return result;
  6602. }
  6603. int sendSecurityEventNotificationRequest()
  6604. {
  6605. mtrace();
  6606. int result = PASS;
  6607. char message[4096]={0};
  6608. char guid[37]={0};
  6609. char tempdata[128]={0};
  6610. json_object *SecurityEventNotification = json_object_new_object();
  6611. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6612. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6613. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6614. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6615. random_uuid(guid);
  6616. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6617. json_object_put(SecurityEventNotification);
  6618. LWS_Send(message);
  6619. sprintf(tempdata, "SecurityEventNotification,0");
  6620. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6621. {
  6622. result = PASS;
  6623. }
  6624. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6625. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6626. return result;
  6627. }
  6628. int sendSignCertificateRequest()
  6629. {
  6630. mtrace();
  6631. int result = PASS;
  6632. char message[4096]={0};
  6633. char guid[37]={0};
  6634. char tempdata[128]={0};
  6635. json_object *SignCertificate = json_object_new_object();
  6636. DEBUG_INFO("sendSignCertificateRequest...\n");
  6637. // Read csr file content
  6638. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6639. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6640. char *line = NULL;
  6641. size_t len = 0;
  6642. while(getline(&line, &len, fp) != -1)
  6643. {
  6644. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6645. {
  6646. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6647. }
  6648. }
  6649. fclose(fp);
  6650. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6651. random_uuid(guid);
  6652. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6653. json_object_put(SignCertificate);
  6654. LWS_Send(message);
  6655. sprintf(tempdata, "SignCertificate,0");
  6656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6657. {
  6658. result = PASS;
  6659. }
  6660. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6661. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6662. return result;
  6663. }
  6664. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6665. {
  6666. mtrace();
  6667. int result = PASS;
  6668. char message[110]={0};
  6669. char guid[37]={0};
  6670. char tempdata[65]={0};
  6671. json_object *FirmwareStatusNotification = json_object_new_object();
  6672. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6673. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6674. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6675. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6676. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6677. random_uuid(guid);
  6678. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6679. json_object_put(FirmwareStatusNotification);
  6680. LWS_Send(message);
  6681. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6682. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6683. {
  6684. result = PASS;
  6685. }
  6686. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6687. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6688. return result;
  6689. }
  6690. //==========================================
  6691. // send confirm routine
  6692. //==========================================
  6693. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6694. {
  6695. mtrace();
  6696. int result = FAIL;
  6697. char message[100]={0};
  6698. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6700. LWS_Send(message);
  6701. result = TRUE;
  6702. return result;
  6703. }
  6704. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6705. {
  6706. mtrace();
  6707. int result = FAIL;
  6708. char message[100]={0};
  6709. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6711. LWS_Send(message);
  6712. result = TRUE;
  6713. return result;
  6714. }
  6715. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6716. {
  6717. mtrace();
  6718. int result = FAIL;
  6719. char message[100]={0};
  6720. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6722. LWS_Send(message);
  6723. result = TRUE;
  6724. return result;
  6725. }
  6726. int sendClearCacheConfirmation(char *uuid,char *payload)
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. char message[500]={0};
  6731. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6732. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6733. LWS_Send(message);
  6734. return result;
  6735. }
  6736. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6737. {
  6738. mtrace();
  6739. int result = FAIL;
  6740. char message[500]={0};
  6741. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6742. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6743. LWS_Send(message);
  6744. return result;
  6745. }
  6746. int sendDataTransferConfirmation(char *uuid,char *payload)
  6747. {
  6748. mtrace();
  6749. char statusStr[20]={0};
  6750. char dataStr[10]={0};
  6751. char sstr[20]={0};
  6752. int c = 0;
  6753. char *loc;
  6754. int result = FAIL;
  6755. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6756. /**********************status**************************/
  6757. loc = strstr(payload, "status");
  6758. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6759. c = 0;
  6760. while (loc[3+strlen("status")+c] != '\"')
  6761. {
  6762. sstr[c] = loc[3+strlen("status")+c];
  6763. c++;
  6764. }
  6765. sstr[c] = '\0';
  6766. strcpy(statusStr, sstr);
  6767. /**********************data**************************/
  6768. loc = strstr(payload, "data");
  6769. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6770. c = 0;
  6771. while (loc[3+strlen("data")+c] != '\"')
  6772. {
  6773. sstr[c] = loc[3+strlen("data")+c];
  6774. c++;
  6775. }
  6776. sstr[c] = '\0';
  6777. strcpy(dataStr, sstr);
  6778. return result;
  6779. }
  6780. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char message[1000]={0};
  6785. int CompositeScheduleIndex = 0;
  6786. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6787. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6788. if(nPeriod == 0)
  6789. {
  6790. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6791. {
  6792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6793. ,MESSAGE_TYPE_CALLRESULT
  6794. ,uuid
  6795. ,payload
  6796. ,connectorIdInt);
  6797. }
  6798. else
  6799. {
  6800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6801. ,MESSAGE_TYPE_CALLRESULT
  6802. ,uuid
  6803. ,payload
  6804. ,connectorIdInt
  6805. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6806. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6809. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6810. }
  6811. }
  6812. else
  6813. {
  6814. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6815. ,MESSAGE_TYPE_CALLRESULT
  6816. ,uuid
  6817. ,payload
  6818. ,connectorIdInt
  6819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6821. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6822. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6823. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6824. {
  6825. if (idx_sample == 0)
  6826. {
  6827. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6828. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6829. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6831. }
  6832. else
  6833. {
  6834. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6835. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6836. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6837. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6838. }
  6839. }
  6840. sprintf(message + strlen(message), "]}}]");
  6841. }
  6842. LWS_Send(message);
  6843. result = TRUE;
  6844. return result;
  6845. }
  6846. int sendGetConfigurationConfirmation(char *uuid)
  6847. {
  6848. mtrace();
  6849. int result = FAIL;
  6850. int MaxKeySupported = 0;
  6851. int sentConfigurationNumber= 0;
  6852. int sentunConfigurationNumber= 0;
  6853. char message[4000]={0};
  6854. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6855. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6856. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6857. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6858. ,MESSAGE_TYPE_CALLRESULT
  6859. ,uuid );
  6860. //configuration key
  6861. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6862. {
  6863. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6864. {
  6865. if (sentConfigurationNumber == 0)
  6866. {
  6867. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6868. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6869. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6870. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6871. }
  6872. else
  6873. {
  6874. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6875. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6876. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6877. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6878. }
  6879. sentConfigurationNumber = sentConfigurationNumber + 1;
  6880. }
  6881. }
  6882. sprintf(message + strlen(message), "]");
  6883. if(UnknownKeynum != 0)
  6884. {
  6885. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6886. //unkown key
  6887. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6888. {
  6889. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6890. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6891. if(sentunConfigurationNumber == 0)
  6892. {
  6893. sprintf(message + strlen(message), "\"%s\""
  6894. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6895. }
  6896. else
  6897. {
  6898. sprintf(message + strlen(message), ",\"%s\""
  6899. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6900. }
  6901. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6902. }
  6903. sprintf(message + strlen(message), "]");
  6904. }
  6905. sprintf(message + strlen(message), "}]");
  6906. LWS_Send(message);
  6907. return result;
  6908. }
  6909. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. char message[400]={0};
  6914. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6915. if(strcmp(payload,"")==0)
  6916. {
  6917. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6918. }
  6919. else
  6920. {
  6921. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6922. }
  6923. LWS_Send(message);
  6924. result = TRUE;
  6925. return result;
  6926. }
  6927. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6928. {
  6929. mtrace();
  6930. int result = FAIL;
  6931. char message[80]={0};
  6932. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6933. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6934. LWS_Send(message);
  6935. result = TRUE;
  6936. return result;
  6937. }
  6938. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6939. {
  6940. mtrace();
  6941. int result = FAIL;
  6942. char message[80]={0};
  6943. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6945. LWS_Send(message);
  6946. result = TRUE;
  6947. return result;
  6948. }
  6949. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6950. {
  6951. mtrace();
  6952. int result = FAIL;
  6953. char message[80]={0};
  6954. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6956. LWS_Send(message);
  6957. result = TRUE;
  6958. return result;
  6959. }
  6960. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6961. {
  6962. mtrace();
  6963. int result = FAIL;
  6964. char message[80]={0};
  6965. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6966. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6968. LWS_Send(message);
  6969. result = TRUE;
  6970. return result;
  6971. }
  6972. int sendResetConfirmation(char *uuid,char *payload)
  6973. {
  6974. mtrace();
  6975. int result = FAIL;
  6976. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6977. char message[80]={0};
  6978. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6980. LWS_Send(message);
  6981. result = TRUE;
  6982. return result;
  6983. }
  6984. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6985. {
  6986. mtrace();
  6987. int result = FAIL;
  6988. char message[500]={0};
  6989. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6990. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6991. LWS_Send(message);
  6992. result = TRUE;
  6993. return result;
  6994. }
  6995. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6996. {
  6997. mtrace();
  6998. int result = FAIL;
  6999. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7000. char message[80]={0};
  7001. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7003. LWS_Send(message);
  7004. result = TRUE;
  7005. return result;
  7006. }
  7007. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7008. {
  7009. mtrace();
  7010. int result = FAIL;
  7011. char message[80]={0};
  7012. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7014. LWS_Send(message);
  7015. result = TRUE;
  7016. return result;
  7017. }
  7018. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7019. {
  7020. mtrace();
  7021. int result = FAIL;
  7022. char message[80]={0};
  7023. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7024. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7026. LWS_Send(message);
  7027. result = TRUE;
  7028. return result;
  7029. }
  7030. int sendUpdateFirmwareConfirmation(char *uuid)
  7031. {
  7032. mtrace();
  7033. int result = FAIL;
  7034. char message[60]={0};
  7035. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7036. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7037. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7038. LWS_Send(message);
  7039. result = TRUE;
  7040. return result;
  7041. }
  7042. int sendCertificateSignedConfirmation(char *uuid)
  7043. {
  7044. mtrace();
  7045. int result = PASS;
  7046. char message[4096]={0};
  7047. json_object *CertificateSigned = json_object_new_object();
  7048. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7049. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7050. sprintf(message,"[%d,\"%s\",%s]"
  7051. ,MESSAGE_TYPE_CALLRESULT
  7052. ,uuid
  7053. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7054. json_object_put(CertificateSigned);
  7055. LWS_Send(message);
  7056. return result;
  7057. }
  7058. int sendDeleteCertificateConfirmation(char *uuid)
  7059. {
  7060. mtrace();
  7061. int result = PASS;
  7062. char message[4096]={0};
  7063. json_object *DeleteCertificate = json_object_new_object();
  7064. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7065. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7066. sprintf(message,"[%d,\"%s\",%s]"
  7067. ,MESSAGE_TYPE_CALLRESULT
  7068. ,uuid
  7069. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7070. json_object_put(DeleteCertificate);
  7071. LWS_Send(message);
  7072. return result;
  7073. }
  7074. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7075. {
  7076. mtrace();
  7077. int result = PASS;
  7078. char message[4096]={0};
  7079. json_object *ExtendedTriggerMessage = json_object_new_object();
  7080. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7081. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7082. sprintf(message,"[%d,\"%s\",%s]"
  7083. ,MESSAGE_TYPE_CALLRESULT
  7084. ,uuid
  7085. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7086. json_object_put(ExtendedTriggerMessage);
  7087. LWS_Send(message);
  7088. return result;
  7089. }
  7090. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7091. {
  7092. mtrace();
  7093. int result = PASS;
  7094. char message[4096]={0};
  7095. json_object *GetInstalledCertificateIds = json_object_new_object();
  7096. json_object *certificateHashDataDatas = json_object_new_array();
  7097. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7098. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7099. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7100. {
  7101. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7102. {
  7103. json_object *certificateHashData = json_object_new_object();
  7104. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7105. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7106. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7107. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7108. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7109. }
  7110. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7111. }
  7112. else
  7113. {
  7114. json_object_put(certificateHashDataDatas);
  7115. }
  7116. sprintf(message,"[%d,\"%s\",%s]"
  7117. ,MESSAGE_TYPE_CALLRESULT
  7118. ,uuid
  7119. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7120. json_object_put(GetInstalledCertificateIds);
  7121. LWS_Send(message);
  7122. return result;
  7123. }
  7124. int sendGetLogConfirmation(char *uuid)
  7125. {
  7126. mtrace();
  7127. int result = PASS;
  7128. char message[4096]={0};
  7129. json_object *GetLog = json_object_new_object();
  7130. DEBUG_INFO("sendGetLogConfirmation...\n");
  7131. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7132. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7133. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7134. sprintf(message,"[%d,\"%s\",%s]"
  7135. ,MESSAGE_TYPE_CALLRESULT
  7136. ,uuid
  7137. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7138. json_object_put(GetLog);
  7139. LWS_Send(message);
  7140. return result;
  7141. }
  7142. int sendInstallCertificateConfirmation(char *uuid)
  7143. {
  7144. mtrace();
  7145. int result = PASS;
  7146. char message[4096]={0};
  7147. json_object *InstallCertificate = json_object_new_object();
  7148. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7149. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7150. sprintf(message,"[%d,\"%s\",%s]"
  7151. ,MESSAGE_TYPE_CALLRESULT
  7152. ,uuid
  7153. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7154. json_object_put(InstallCertificate);
  7155. LWS_Send(message);
  7156. return result;
  7157. }
  7158. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7159. {
  7160. mtrace();
  7161. int result = PASS;
  7162. char message[4096]={0};
  7163. json_object *SignedUpdateFirmware = json_object_new_object();
  7164. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7165. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7166. sprintf(message,"[%d,\"%s\",%s]"
  7167. ,MESSAGE_TYPE_CALLRESULT
  7168. ,uuid
  7169. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7170. json_object_put(SignedUpdateFirmware);
  7171. LWS_Send(message);
  7172. return result;
  7173. }
  7174. int sendUnknownConfirmation(char *uuid)
  7175. {
  7176. mtrace();
  7177. int result = PASS;
  7178. char message[256]={0};
  7179. DEBUG_INFO("sendUnknownConfirmation...\n");
  7180. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7181. LWS_Send(message);
  7182. return result;
  7183. }
  7184. //==========================================
  7185. // Handle server request routine Start
  7186. //==========================================
  7187. int handleCancelReservationRequest(char *uuid, char *payload)
  7188. {
  7189. mtrace();
  7190. int result = FAIL;
  7191. int gunNO = 0;
  7192. int reservationIdInt = -1;
  7193. char comfirmstr[20];
  7194. DEBUG_INFO("handleCancelReservationRequest...\n");
  7195. json_object *CancelReservation;
  7196. CancelReservation = json_tokener_parse(payload);
  7197. if(!is_error(CancelReservation))
  7198. {
  7199. // Required data
  7200. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7201. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7202. }
  7203. json_object_put(CancelReservation);
  7204. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7205. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7206. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7207. if(reservationIdInt != -1)
  7208. {
  7209. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7210. //check Transaction active
  7211. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7213. {
  7214. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7215. {
  7216. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7217. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7218. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7219. {
  7220. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7221. }
  7222. else
  7223. {
  7224. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7225. }
  7226. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7227. goto end;
  7228. }
  7229. }
  7230. for (int index = 0; index < CCS_QUANTITY; index++)
  7231. {
  7232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7233. {
  7234. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7235. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7236. if(gunType[2] == GUN_TYPE_CCS)
  7237. {
  7238. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7239. }
  7240. else
  7241. {
  7242. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7243. }
  7244. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7245. goto end;
  7246. }
  7247. }
  7248. for (int index = 0; index < GB_QUANTITY; index++)
  7249. {
  7250. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7251. {
  7252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7254. if(gunType[2] == GUN_TYPE_GBT)
  7255. {
  7256. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7257. }
  7258. else
  7259. {
  7260. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7261. }
  7262. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7263. goto end;
  7264. }
  7265. }
  7266. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7267. {
  7268. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7269. {
  7270. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7271. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7272. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7273. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7274. goto end;
  7275. }
  7276. }
  7277. for (int index = 0; index < AC_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7280. {
  7281. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7282. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7284. {
  7285. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7286. }
  7287. else
  7288. {
  7289. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7290. }
  7291. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7292. goto end;
  7293. }
  7294. }
  7295. }
  7296. //The reservationId does NOT match the reservationId
  7297. sendCancelReservationConfirmation(uuid, comfirmstr);
  7298. end:
  7299. // Fill in ocpp packet uuid
  7300. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7301. return result;
  7302. }
  7303. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7304. {
  7305. mtrace();
  7306. int result = FAIL;
  7307. int gunIndex = 0;
  7308. char typeStr[16]={0};
  7309. char comfirmstr[20];
  7310. int specificId = FALSE;
  7311. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7312. json_object *ChangeAvailability;
  7313. ChangeAvailability = json_tokener_parse(payload);
  7314. if(!is_error(ChangeAvailability))
  7315. {
  7316. // Required data
  7317. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7318. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7319. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7320. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7321. }
  7322. json_object_put(ChangeAvailability);
  7323. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7324. {
  7325. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7326. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7327. }
  7328. else if(gunIndex == 0)
  7329. {
  7330. for(int i=0; i < gunTotalNumber; i++)
  7331. {
  7332. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7333. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7334. }
  7335. }
  7336. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7338. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7339. {
  7340. specificId = TRUE;
  7341. }
  7342. if(specificId == FALSE)
  7343. goto end;
  7344. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7345. {
  7346. //----------------------gunIndex is 0 ------------------------------------------------//
  7347. if(gunIndex == 0)
  7348. {
  7349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7350. {
  7351. for(int i=0; i < gunTotalNumber; i++)
  7352. {
  7353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7354. {
  7355. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7356. {
  7357. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7358. {
  7359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7360. goto end;
  7361. }
  7362. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7363. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7365. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7366. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7367. {
  7368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7369. goto end;
  7370. }
  7371. }
  7372. }//END FOR CHAdeMO_QUANTITY
  7373. for (int index = 0; index < CCS_QUANTITY; index++)
  7374. {
  7375. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7376. {
  7377. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7378. {
  7379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7380. goto end;
  7381. }
  7382. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7383. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7384. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7386. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7387. {
  7388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7389. goto end;
  7390. }
  7391. }
  7392. }//END FOR CCS_QUANTITY
  7393. for (int index = 0; index < GB_QUANTITY; index++)
  7394. {
  7395. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7396. {
  7397. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7398. {
  7399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7400. goto end;
  7401. }
  7402. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7403. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7404. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7405. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7406. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7407. {
  7408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7409. goto end;
  7410. }
  7411. }
  7412. }// END FOR GB_QUANTITY
  7413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7414. {
  7415. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7416. {
  7417. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7418. {
  7419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7420. goto end;
  7421. }
  7422. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7423. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7424. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7425. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7426. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7427. {
  7428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7429. goto end;
  7430. }
  7431. }
  7432. }// END FOR GENERAL_GUN_QUANTITY
  7433. for (int index = 0; index < AC_QUANTITY; index++)
  7434. {
  7435. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7436. {
  7437. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7438. {
  7439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7440. goto end;
  7441. }
  7442. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7443. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7444. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7446. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7447. {
  7448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7449. goto end;
  7450. }
  7451. }
  7452. }//END FOR AC_QUANTITY
  7453. }// END FOR gunTotalNumber
  7454. }
  7455. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7456. {
  7457. for(int i=0; i < gunTotalNumber; i++)
  7458. {
  7459. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7460. {
  7461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7462. goto end;
  7463. }
  7464. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7468. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7469. {
  7470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7471. goto end;
  7472. }
  7473. }
  7474. }
  7475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7476. goto end;
  7477. }
  7478. //----------------------gunIndex is not 0 ------------------------------------------------//
  7479. //check Transaction active
  7480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7481. {
  7482. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7483. {
  7484. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7485. {
  7486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7487. goto end;
  7488. }
  7489. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7490. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7493. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7494. {
  7495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7496. goto end;
  7497. }
  7498. else
  7499. {
  7500. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7502. goto end;
  7503. }
  7504. }
  7505. }//END FOR CHAdeMO_QUANTITY
  7506. for (int index = 0; index < CCS_QUANTITY; index++)
  7507. {
  7508. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7509. {
  7510. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7511. {
  7512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7513. goto end;
  7514. }
  7515. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7516. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7520. {
  7521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7522. goto end;
  7523. }
  7524. else
  7525. {
  7526. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7528. goto end;
  7529. }
  7530. }
  7531. }//END FOR CCS_QUANTITY
  7532. for (int index = 0; index < GB_QUANTITY; index++)
  7533. {
  7534. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7535. {
  7536. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7537. {
  7538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7539. goto end;
  7540. }
  7541. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7542. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7543. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7545. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7546. {
  7547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7548. goto end;
  7549. }
  7550. else
  7551. {
  7552. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7554. goto end;
  7555. }
  7556. }
  7557. }// END FOR GB_QUANTITY
  7558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7559. {
  7560. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7561. {
  7562. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7563. {
  7564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7565. goto end;
  7566. }
  7567. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7572. {
  7573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7574. goto end;
  7575. }
  7576. else
  7577. {
  7578. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7580. goto end;
  7581. }
  7582. }
  7583. }// END FOR GENERAL_GUN_QUANTITY
  7584. for (int index = 0; index < AC_QUANTITY; index++)
  7585. {
  7586. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7587. {
  7588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7589. {
  7590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7591. goto end;
  7592. }
  7593. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7597. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7598. {
  7599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7600. goto end;
  7601. }
  7602. else
  7603. {
  7604. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7606. goto end;
  7607. }
  7608. }
  7609. }//END FOR AC_QUANTITY
  7610. }//END FOR AvailabilityTypeStr[Inoperative]
  7611. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7612. {
  7613. //----------------------gunIndex is 0 ------------------------------------------------//
  7614. if(gunIndex == 0)
  7615. {
  7616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7617. {
  7618. for(int i=0; i < gunTotalNumber; i++)
  7619. {
  7620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7621. {
  7622. 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
  7623. {
  7624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7625. goto end;
  7626. }
  7627. }//END FOR CHAdeMO_QUANTITY
  7628. for (int index = 0; index < CCS_QUANTITY; index++)
  7629. {
  7630. 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
  7631. {
  7632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7633. goto end;
  7634. }
  7635. }//END FOR CCS_QUANTITY
  7636. for (int index = 0; index < GB_QUANTITY; index++)
  7637. {
  7638. 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
  7639. {
  7640. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7642. goto end;
  7643. }
  7644. }// END FOR GB_QUANTITY
  7645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7646. {
  7647. 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
  7648. {
  7649. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7651. goto end;
  7652. }
  7653. }// END FOR GENERAL_GUN_QUANTITY
  7654. for (int index = 0; index < AC_QUANTITY; index++)
  7655. {
  7656. 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
  7657. {
  7658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7659. goto end;
  7660. }
  7661. }//END FOR CHAdeMO_QUANTITY
  7662. }// END FOR gunTotalNumber
  7663. }
  7664. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7665. {
  7666. for(int i=0; i < gunTotalNumber; i++)
  7667. {
  7668. for (int index = 0; index < AC_QUANTITY; index++)
  7669. {
  7670. 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
  7671. {
  7672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7673. goto end;
  7674. }
  7675. }//END FOR CHAdeMO_QUANTITY
  7676. } // END FOR gunTotalNumber
  7677. }
  7678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7679. goto end;
  7680. }
  7681. //----------------------gunIndex is not 0 ------------------------------------------------//
  7682. //check Transaction active
  7683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7684. {
  7685. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7686. {
  7687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7688. goto end;
  7689. }
  7690. }//END FOR CHAdeMO_QUANTITY
  7691. for (int index = 0; index < CCS_QUANTITY; index++)
  7692. {
  7693. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7696. goto end;
  7697. }
  7698. }//END FOR CCS_QUANTITY
  7699. for (int index = 0; index < GB_QUANTITY; index++)
  7700. {
  7701. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7702. {
  7703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7704. goto end;
  7705. }
  7706. }// END FOR GB_QUANTITY
  7707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7708. {
  7709. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }// END FOR GENERAL_GUN_QUANTITY
  7715. for (int index = 0; index < AC_QUANTITY; index++)
  7716. {
  7717. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7718. {
  7719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7720. goto end;
  7721. }
  7722. }//END FOR AC_QUANTITY
  7723. }//END FOR AvailabilityTypeStr[Operative]
  7724. end:
  7725. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7726. {
  7727. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7728. }
  7729. else
  7730. {
  7731. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7732. }
  7733. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7734. {
  7735. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7736. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7737. }
  7738. else if(gunIndex == 0)
  7739. {
  7740. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7741. {
  7742. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7743. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7744. }
  7745. }
  7746. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7747. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7748. return result;
  7749. }
  7750. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7751. {
  7752. mtrace();
  7753. int result = FAIL;
  7754. char keystr[40]={0};
  7755. char valuestr[256]={0};
  7756. char comfirmstr[20]={0};
  7757. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7758. json_object *ChangeConfiguration;
  7759. ChangeConfiguration = json_tokener_parse(payload);
  7760. if(!is_error(ChangeConfiguration))
  7761. {
  7762. // Required data
  7763. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7764. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7765. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7766. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7767. }
  7768. json_object_put(ChangeConfiguration);
  7769. if((uuid==NULL) || (payload ==NULL) )
  7770. {
  7771. DEBUG_ERROR("Payload is null\n");
  7772. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7773. }
  7774. else
  7775. {
  7776. int status = setKeyValue(keystr, valuestr);
  7777. switch(status)
  7778. {
  7779. case ConfigurationStatus_Accepted:
  7780. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7781. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7782. StoreConfigurationTable();
  7783. break;
  7784. case RebootRequired:
  7785. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7786. StoreConfigurationTable();
  7787. break;
  7788. case NotSupported:
  7789. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7790. break;
  7791. case ConfigurationStatus_Rejected:
  7792. default:
  7793. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7794. break;
  7795. }
  7796. }
  7797. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7798. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7799. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7800. {
  7801. ChageWebSocketPingInterval(atoi(valuestr));
  7802. }
  7803. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7804. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7805. {
  7806. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7807. SetOcppConnStatus(FALSE);
  7808. }
  7809. return result;
  7810. }
  7811. int handleClearCacheRequest(char *uuid, char *payload)
  7812. {
  7813. mtrace();
  7814. int result = FAIL;
  7815. char comfirmstr[20];
  7816. char rmFileCmd[100]={0};
  7817. struct stat stats;
  7818. DEBUG_INFO("handleClearCacheRequest...\n");
  7819. stat("/Storage/OCPP", &stats);
  7820. // Check for directory existence
  7821. if (S_ISDIR(stats.st_mode) == 1)
  7822. {}
  7823. else
  7824. {
  7825. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7826. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7827. system(rmFileCmd);
  7828. }
  7829. if(OCPP_cleanLocalCache())
  7830. {
  7831. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7832. }
  7833. else
  7834. {
  7835. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7836. }
  7837. sendClearCacheConfirmation(uuid, comfirmstr);
  7838. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7839. return result;
  7840. }
  7841. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7842. {
  7843. mtrace();
  7844. int result = FAIL;
  7845. int resultRename;
  7846. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7847. char chargingProfilePurposeStr[26]={0};
  7848. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7849. char tempchargingProfilePurposeStr[26]={0};
  7850. char str[100]={0};
  7851. char fname[200]={0};
  7852. char comfirmstr[20]={0};
  7853. char word[1600]={0};
  7854. int clearflag = FALSE;
  7855. int chargingProfileIdIsNULL = FALSE;
  7856. int connectorIsNULL = FALSE;
  7857. int chargingProfilePurposeIsNULL = FALSE;
  7858. int stackLevelIsNULL = FALSE;
  7859. //int GotoEnd = FALSE;
  7860. FILE *fptr1, *fptr2;
  7861. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7862. int n_chargingProfile=0;
  7863. int isEmptyFile = FALSE;
  7864. char sLineWord[1600]={0};
  7865. char chargingProfiles[10][100]={0};
  7866. int ChargeProfileCount = 0;
  7867. int ch;
  7868. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7869. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7870. json_object *ClearChargingProfile;
  7871. ClearChargingProfile = json_tokener_parse(payload);
  7872. if(!is_error(ClearChargingProfile))
  7873. {
  7874. // Optional data
  7875. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7876. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7877. else
  7878. chargingProfileIdIsNULL = TRUE;
  7879. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7880. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7881. else
  7882. connectorIsNULL = TRUE;
  7883. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7884. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7885. else
  7886. chargingProfilePurposeIsNULL = TRUE;
  7887. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7888. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7889. else
  7890. stackLevelIsNULL = TRUE;
  7891. }
  7892. json_object_put(ClearChargingProfile);
  7893. if(connectorIsNULL == FALSE)
  7894. {
  7895. switch(connectorIdInt)
  7896. {
  7897. case 0:
  7898. if(chargingProfilePurposeIsNULL == TRUE)
  7899. {
  7900. int l = 0;
  7901. strcpy(fname, ChargePointMaxProfile_JSON);
  7902. if((access(fname,F_OK))!=-1)
  7903. {
  7904. strcpy(chargingProfiles[l], fname);
  7905. l = l + 1;
  7906. }
  7907. strcpy(fname, TxDefaultProfile_0_JSON);
  7908. if((access(fname,F_OK))!=-1)
  7909. {
  7910. strcpy(chargingProfiles[l], fname);
  7911. l = l + 1;
  7912. }
  7913. ChargeProfileCount = l;
  7914. }
  7915. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7916. {
  7917. strcpy(fname, ChargePointMaxProfile_JSON);
  7918. if((access(fname,F_OK))!=-1)
  7919. {
  7920. strcpy(chargingProfiles[0], fname);
  7921. ChargeProfileCount = 1;
  7922. }
  7923. }
  7924. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7925. {
  7926. strcpy(fname, TxDefaultProfile_0_JSON);
  7927. if((access(fname,F_OK))!=-1)
  7928. {
  7929. strcpy(chargingProfiles[0], fname);
  7930. ChargeProfileCount = 1;
  7931. }
  7932. }
  7933. break;
  7934. default:
  7935. if(chargingProfilePurposeIsNULL == TRUE)
  7936. {
  7937. int m = 0;
  7938. memset(fname, 0, ARRAY_SIZE(fname));
  7939. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7940. if((access(fname,F_OK))!=-1)
  7941. {
  7942. strcpy(chargingProfiles[m], fname);
  7943. m = m + 1;
  7944. }
  7945. memset(fname, 0, ARRAY_SIZE(fname));
  7946. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7947. if((access(fname,F_OK))!=-1)
  7948. {
  7949. strcpy(chargingProfiles[m], fname);
  7950. m = m + 1;
  7951. }
  7952. ChargeProfileCount = m;
  7953. }
  7954. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7955. {
  7956. //strcpy(fname, TxDefaultProfile_1_JSON);
  7957. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7958. if((access(fname,F_OK))!=-1)
  7959. {
  7960. strcpy(chargingProfiles[0], fname);
  7961. ChargeProfileCount = 1;
  7962. }
  7963. }
  7964. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7965. {
  7966. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7967. if((access(fname,F_OK))!=-1)
  7968. {
  7969. strcpy(chargingProfiles[0], fname);
  7970. ChargeProfileCount = 1;
  7971. }
  7972. //strcpy(fname, TxProfile_1_JSON);
  7973. }
  7974. //strcpy(fname, ChargePointMaxProfile_JSON );
  7975. break;
  7976. }
  7977. }
  7978. else // Check all Charging Profiles
  7979. {
  7980. int i = 0;
  7981. char fnametemp[200]={0};
  7982. ChargeProfileCount = 0;
  7983. //Check ChargePointMaxProfile.json exit
  7984. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7985. {
  7986. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7987. i = i + 1;
  7988. }
  7989. //Check TxDefaultProfile_0.json exit
  7990. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7991. {
  7992. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7993. i = i + 1;
  7994. }
  7995. //Check TxDefaultProfile_%d.json
  7996. for(int j=1; j <= gunTotalNumber; j++)
  7997. {
  7998. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7999. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8000. if((access(fnametemp,F_OK))!=-1)
  8001. {
  8002. strcpy(chargingProfiles[i], fnametemp);
  8003. i = i + 1;
  8004. }
  8005. }
  8006. //Check TxProfile_%d.json
  8007. for(int j=1; j <= gunTotalNumber; j++)
  8008. {
  8009. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8010. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8011. if((access(fnametemp,F_OK))!=-1)
  8012. {
  8013. strcpy(chargingProfiles[i], fnametemp);
  8014. i = i + 1;
  8015. }
  8016. }
  8017. ChargeProfileCount = i;
  8018. }// End connectorIsNULL is TRUE
  8019. if(ChargeProfileCount == 0)
  8020. {
  8021. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8022. goto end;
  8023. }
  8024. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8025. {
  8026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8027. goto end;
  8028. }
  8029. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8030. {
  8031. memset(str, 0, ARRAY_SIZE(str));
  8032. // clear temp file
  8033. sprintf(str,"rm -f %s",temp);
  8034. system(str);
  8035. for(int k=0; k < ChargeProfileCount; k++)
  8036. {
  8037. memset(str, 0, ARRAY_SIZE(str));
  8038. //clear file in C
  8039. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8040. system(str);
  8041. }
  8042. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8043. goto end;
  8044. }
  8045. else if(connectorIsNULL == TRUE)
  8046. {
  8047. for(int k=0; k < ChargeProfileCount; k++)
  8048. {
  8049. fptr1 = fopen(chargingProfiles[k], "r");
  8050. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8051. //Check Charging Profile Count
  8052. while(fscanf(fptr1, "%s", word) != EOF)
  8053. {
  8054. //DEBUG_INFO("word=%s\n",word);
  8055. if(strstr(word, "chargingProfileId")!= NULL)
  8056. {
  8057. //DEBUG_INFO("test chargingProfileId \n");
  8058. n_chargingProfile = n_chargingProfile + 1;
  8059. //DEBUG_INFO("chargingProfileId Found\n");
  8060. }
  8061. }
  8062. rewind(fptr1);
  8063. //search Charging Profile Element
  8064. //int i= 0;
  8065. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8066. {
  8067. json_object *tmpProfilee;
  8068. tmpProfilee = json_tokener_parse(sLineWord);
  8069. if(!is_error(tmpProfilee))
  8070. {
  8071. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8072. {
  8073. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8074. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8075. }
  8076. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8077. {
  8078. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8079. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8080. }
  8081. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8082. {
  8083. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8084. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8085. }
  8086. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8087. {
  8088. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8089. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8090. }
  8091. }
  8092. json_object_put(tmpProfilee);
  8093. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8094. {
  8095. //------- not write to fptr2-------//
  8096. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8097. //clearflag = TRUE;
  8098. }
  8099. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8100. {
  8101. //------- not write to fptr2-------//
  8102. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8103. }
  8104. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8105. {
  8106. //------- not write to fptr2-------//
  8107. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8108. }
  8109. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8110. {
  8111. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8112. }
  8113. else
  8114. {
  8115. fprintf(fptr2, sLineWord);//writing data into file
  8116. }
  8117. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8118. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8119. if(clearflag == TRUE)
  8120. {
  8121. fclose(fptr1);
  8122. fclose(fptr2);
  8123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8124. system(str);
  8125. // clear temp file
  8126. sprintf(str,"rm -f %s",temp);
  8127. system(str);
  8128. }
  8129. else
  8130. {
  8131. fclose(fptr1);
  8132. fclose(fptr2);
  8133. memset(str, 0, ARRAY_SIZE(str));
  8134. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8135. system(str);
  8136. resultRename = rename(temp, chargingProfiles[k]);
  8137. if(resultRename == 0)
  8138. {
  8139. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8140. }
  8141. else
  8142. {
  8143. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8144. }
  8145. if(comfirmstr[0]== 0)
  8146. {
  8147. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8148. }
  8149. //Check chargingProfile is empty file
  8150. /*------ Read the file ----------------*/
  8151. fptr1=fopen(chargingProfiles[k],"r");
  8152. ch=fgetc(fptr1);
  8153. rewind(fptr1);
  8154. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8155. if(ch!=EOF)
  8156. {
  8157. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8158. {
  8159. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8160. if(sLineWord[0]=='\0')
  8161. {
  8162. isEmptyFile = TRUE;
  8163. break;
  8164. }
  8165. else
  8166. {
  8167. isEmptyFile = FALSE;
  8168. break;
  8169. }
  8170. }
  8171. }
  8172. else
  8173. isEmptyFile = TRUE;
  8174. fclose(fptr1);
  8175. if(isEmptyFile == TRUE)
  8176. {
  8177. memset(str, 0, ARRAY_SIZE(str));
  8178. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8179. system(str);
  8180. }
  8181. }
  8182. }// End of while(int k=0; k < ChargePointCount; k++)
  8183. }
  8184. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8185. {
  8186. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8187. for(int k=0; k < ChargeProfileCount; k++)
  8188. {
  8189. fptr1 = fopen(chargingProfiles[k], "r");
  8190. fptr2 = fopen(temp, "w+");
  8191. //Check Charging Profile Count
  8192. while(fscanf(fptr1, "%s", word) != EOF)
  8193. {
  8194. //DEBUG_INFO("word=%s\n",word);
  8195. if(strstr(word, "chargingProfileId")!= NULL)
  8196. {
  8197. n_chargingProfile = n_chargingProfile + 1;
  8198. }
  8199. }
  8200. rewind(fptr1);
  8201. //search Charging Profile Element
  8202. //int i= 0;
  8203. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8204. {
  8205. json_object *tmpProfilee;
  8206. tmpProfilee = json_tokener_parse(sLineWord);
  8207. if(!is_error(tmpProfilee))
  8208. {
  8209. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8210. {
  8211. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8212. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8213. }
  8214. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8215. {
  8216. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8217. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8218. }
  8219. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8220. {
  8221. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8222. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8223. }
  8224. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8225. {
  8226. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8227. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8228. }
  8229. }
  8230. json_object_put(tmpProfilee);
  8231. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8232. {
  8233. //------- not write to fptr2-------//
  8234. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8235. //clearflag = TRUE;
  8236. }
  8237. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8238. {
  8239. //------- not write to fptr2-------//
  8240. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8241. }
  8242. else if(stackLevelIsNULL == TRUE)
  8243. {
  8244. //Clear Whole File
  8245. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8246. clearflag = TRUE;
  8247. break;
  8248. }
  8249. else
  8250. {
  8251. fprintf(fptr2, sLineWord);//writing data into file
  8252. }
  8253. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8254. }
  8255. if(clearflag == TRUE)
  8256. {
  8257. fclose(fptr1);
  8258. fclose(fptr2);
  8259. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8260. system(str);
  8261. // clear temp file
  8262. sprintf(str,"rm -f %s",temp);
  8263. system(str);
  8264. }
  8265. else
  8266. {
  8267. fclose(fptr1);
  8268. fclose(fptr2);
  8269. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8270. system(str);
  8271. resultRename = rename(temp, chargingProfiles[k]);
  8272. if(resultRename == 0)
  8273. {
  8274. DEBUG_INFO("File ChargingProfile renamed successfully");
  8275. }
  8276. else
  8277. {
  8278. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8279. }
  8280. if(comfirmstr[0]== 0)
  8281. {
  8282. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8283. }
  8284. //Check chargingProfile is empty file
  8285. /*------ Read the file ----------------*/
  8286. fptr1=fopen(chargingProfiles[k],"r");
  8287. ch=fgetc(fptr1);
  8288. rewind(fptr1);
  8289. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8290. if(ch!=EOF)
  8291. {
  8292. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8293. {
  8294. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8295. if(sLineWord[0]=='\0')
  8296. {
  8297. isEmptyFile = TRUE;
  8298. break;
  8299. }
  8300. else
  8301. {
  8302. isEmptyFile = FALSE;
  8303. break;
  8304. }
  8305. }
  8306. }
  8307. else
  8308. isEmptyFile = TRUE;
  8309. fclose(fptr1);
  8310. if(isEmptyFile == TRUE)
  8311. {
  8312. memset(str, 0, ARRAY_SIZE(str));
  8313. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8314. system(str);
  8315. }
  8316. /*------- End of reading ---------------*/
  8317. }
  8318. } // while(int k=0; k < ChargeProfileCount; k++)
  8319. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8320. end:
  8321. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8322. {
  8323. if(connectorIdInt == 0)
  8324. {
  8325. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8326. {
  8327. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8328. }
  8329. }
  8330. else
  8331. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8332. }
  8333. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8334. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8335. return result;
  8336. }
  8337. void createFirmwareVersionByDataTransfer(void)
  8338. {
  8339. json_object *FirmwareDataTransfer = json_object_new_object();
  8340. // AC & DC model
  8341. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8342. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8343. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8344. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8345. // DC model
  8346. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8347. {
  8348. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8349. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8350. (gunType[3] != GUN_TYPE_UNKNOWN))
  8351. {
  8352. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8353. }
  8354. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8355. {
  8356. // DS DM DW
  8357. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8358. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8359. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8360. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8361. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8362. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8363. }
  8364. else
  8365. {
  8366. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8367. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8368. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8369. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8370. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8371. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8372. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8373. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8374. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8375. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8376. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8377. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8378. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8379. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8380. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8381. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8382. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8383. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8384. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8385. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8386. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8388. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8389. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8390. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8391. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8392. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8393. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8394. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8395. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8396. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8397. }
  8398. }
  8399. // 4G model
  8400. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8401. {
  8402. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8403. }
  8404. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8405. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8406. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8407. json_object_put(FirmwareDataTransfer);
  8408. }
  8409. int handleDataTransferRequest(char *uuid, char *payload)
  8410. {
  8411. mtrace();
  8412. json_object *response = json_object_new_object();
  8413. int result = FAIL;
  8414. char tempvendorId[255]={0};
  8415. char tempmessageId[50]={0};
  8416. char tempdata[512]={0};
  8417. char message[2048]={0};
  8418. DEBUG_INFO("handleDataTransferRequest...\n");
  8419. if((uuid != NULL) && (payload != NULL))
  8420. {
  8421. json_object *DataTransfer;
  8422. DataTransfer = json_tokener_parse(payload);
  8423. if(!is_error(DataTransfer))
  8424. {
  8425. // Required data
  8426. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8427. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8428. // Optional data
  8429. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8430. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8431. if(json_object_object_get(DataTransfer, "data") != NULL)
  8432. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8433. result = PASS;
  8434. }
  8435. json_object_put(DataTransfer);
  8436. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8437. {
  8438. // Send all moudle firmware version on EVSE
  8439. createFirmwareVersionByDataTransfer();
  8440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8441. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8442. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8443. json_object_put(response);
  8444. }
  8445. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8446. {
  8447. system("/usr/bin/run_tmate_restart.sh &");
  8448. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8449. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(response);
  8451. }
  8452. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8453. {
  8454. json_object *data;
  8455. data = json_tokener_parse(tempdata);
  8456. if(!is_error(data))
  8457. {
  8458. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8459. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8460. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8461. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8462. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8463. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8464. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8465. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8466. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8467. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8468. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8469. }
  8470. else
  8471. {
  8472. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8473. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8474. }
  8475. json_object_put(data);
  8476. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8477. json_object_put(response);
  8478. }
  8479. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8480. {
  8481. json_object *data;
  8482. data = json_tokener_parse(tempdata);
  8483. if(!is_error(data))
  8484. {
  8485. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8486. if(json_object_object_get(data, "idToken") != NULL)
  8487. {
  8488. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8489. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8490. }
  8491. if(json_object_object_get(data, "price") != NULL)
  8492. {
  8493. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8494. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8495. }
  8496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8497. }
  8498. else
  8499. {
  8500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8502. }
  8503. json_object_put(data);
  8504. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8505. json_object_put(response);
  8506. }
  8507. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8508. {
  8509. json_object *data;
  8510. data = json_tokener_parse(tempdata);
  8511. if(!is_error(data))
  8512. {
  8513. if(json_object_object_get(data, "txId") != NULL)
  8514. {
  8515. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8516. for(int idx = 0;idx<gunTotalNumber;idx++)
  8517. {
  8518. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8519. {
  8520. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8521. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8522. if(json_object_object_get(data, "description") != NULL)
  8523. {
  8524. // California pricing V1.0
  8525. DEBUG_INFO("California pricing V1.0\n");
  8526. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8527. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8528. }
  8529. else
  8530. {
  8531. // California pricing V1.1
  8532. DEBUG_INFO("California pricing V1.1\n");
  8533. if(json_object_object_get(data, "timestamp") != NULL)
  8534. {
  8535. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8536. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8537. }
  8538. if(json_object_object_get(data, "meterValue") != NULL)
  8539. {
  8540. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8541. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8542. }
  8543. if(json_object_object_get(data, "cost") != NULL)
  8544. {
  8545. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8546. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8547. }
  8548. if(json_object_object_get(data, "state") != NULL)
  8549. {
  8550. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8551. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8552. }
  8553. if(json_object_object_get(data, "chargingPrice") != NULL)
  8554. {
  8555. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8556. {
  8557. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8558. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8559. }
  8560. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8561. {
  8562. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8563. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8564. }
  8565. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8566. {
  8567. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8568. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8569. }
  8570. }
  8571. if(json_object_object_get(data, "idlePrice") != NULL)
  8572. {
  8573. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8574. {
  8575. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8576. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8577. }
  8578. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8579. {
  8580. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8581. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8582. }
  8583. }
  8584. if(json_object_object_get(data, "nextPeriod") != NULL)
  8585. {
  8586. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8587. {
  8588. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8589. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8590. }
  8591. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8592. {
  8593. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8594. {
  8595. 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")));
  8596. 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"));
  8597. }
  8598. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8599. {
  8600. 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")));
  8601. 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"));
  8602. }
  8603. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8604. {
  8605. 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")));
  8606. 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"));
  8607. }
  8608. }
  8609. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8610. {
  8611. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8612. {
  8613. 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")));
  8614. 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"));
  8615. }
  8616. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8617. {
  8618. 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")));
  8619. 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"));
  8620. }
  8621. }
  8622. }
  8623. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8624. {
  8625. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8626. {
  8627. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8628. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8629. }
  8630. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8631. {
  8632. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8633. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8634. }
  8635. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8636. {
  8637. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8638. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8639. }
  8640. }
  8641. }
  8642. }
  8643. }
  8644. }
  8645. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8646. }
  8647. else
  8648. {
  8649. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8650. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8651. }
  8652. json_object_put(data);
  8653. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8654. json_object_put(response);
  8655. }
  8656. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8657. {
  8658. json_object *data;
  8659. data = json_tokener_parse(tempdata);
  8660. if(!is_error(data))
  8661. {
  8662. if(json_object_object_get(data, "txId") != NULL)
  8663. {
  8664. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8665. for(int idx = 0;idx<gunTotalNumber;idx++)
  8666. {
  8667. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8668. {
  8669. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8670. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8671. if(json_object_object_get(data, "description") != NULL)
  8672. {
  8673. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8674. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8675. }
  8676. }
  8677. }
  8678. }
  8679. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8680. }
  8681. else
  8682. {
  8683. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8684. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8685. }
  8686. json_object_put(data);
  8687. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8688. json_object_put(response);
  8689. }
  8690. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8691. {
  8692. json_object *data;
  8693. data = json_tokener_parse(tempdata);
  8694. if(!is_error(data))
  8695. {
  8696. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8697. if(json_object_object_get(data, "Content_Type") != NULL)
  8698. {
  8699. 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))
  8700. {
  8701. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8702. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8703. {
  8704. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8705. }
  8706. }
  8707. else
  8708. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8709. }
  8710. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8711. }
  8712. else
  8713. {
  8714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8716. }
  8717. json_object_put(data);
  8718. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8719. json_object_put(response);
  8720. }
  8721. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8722. {
  8723. json_object *data;
  8724. data = json_tokener_parse(tempdata);
  8725. if(!is_error(data))
  8726. {
  8727. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8728. if(json_object_object_get(data, "Page_Index") != NULL)
  8729. {
  8730. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8731. }
  8732. if(json_object_object_get(data, "Duration") != NULL)
  8733. {
  8734. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8735. }
  8736. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8737. }
  8738. else
  8739. {
  8740. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8741. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8742. }
  8743. json_object_put(data);
  8744. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8745. json_object_put(response);
  8746. }
  8747. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8748. {
  8749. json_object *data;
  8750. data = json_tokener_parse(tempdata);
  8751. if(!is_error(data))
  8752. {
  8753. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8754. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8755. {
  8756. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8757. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8758. else
  8759. {
  8760. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8761. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8762. }
  8763. }
  8764. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8765. {
  8766. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8767. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8768. else
  8769. {
  8770. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8771. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8772. }
  8773. }
  8774. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8775. {
  8776. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8777. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8778. else
  8779. {
  8780. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8781. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8782. }
  8783. }
  8784. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8785. {
  8786. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8787. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8788. else
  8789. {
  8790. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8791. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8792. }
  8793. }
  8794. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8795. {
  8796. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8797. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8798. else
  8799. {
  8800. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8801. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8802. }
  8803. }
  8804. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8805. {
  8806. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8807. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8808. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8809. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8810. else
  8811. {
  8812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8813. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8814. }
  8815. }
  8816. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8817. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8818. }
  8819. else
  8820. {
  8821. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8822. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8823. }
  8824. json_object_put(data);
  8825. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8826. json_object_put(response);
  8827. }
  8828. else
  8829. {
  8830. // Can not find valid message id
  8831. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8832. }
  8833. }
  8834. else
  8835. {
  8836. // Payload is null
  8837. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8838. }
  8839. LWS_Send(message);
  8840. return result;
  8841. }
  8842. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8843. {
  8844. mtrace();
  8845. int result = FAIL;
  8846. int connectorIdInt, durationInt;
  8847. char chargingRateUnitStr[4]={0};
  8848. char comfirmstr[20];
  8849. int confirmPeriods = 0;
  8850. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8851. json_object *GetCompositeSchedule;
  8852. GetCompositeSchedule = json_tokener_parse(payload);
  8853. if(!is_error(GetCompositeSchedule))
  8854. {
  8855. // Required data
  8856. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8857. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8858. else
  8859. connectorIdInt = -1;
  8860. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8861. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8862. else
  8863. durationInt = 86400;
  8864. // Optional data
  8865. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8866. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8867. }
  8868. json_object_put(GetCompositeSchedule);
  8869. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8870. if((connectorIdInt == 0) ||
  8871. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8872. {
  8873. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8874. struct StructChargingProfile tmpProfile[1];
  8875. if(strstr(chargingRateUnitStr, "W") != NULL)
  8876. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8877. else
  8878. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8879. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8880. {
  8881. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8882. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8883. }
  8884. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8885. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8886. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8887. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8888. {
  8889. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8890. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8891. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8892. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8893. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8894. {
  8895. confirmPeriods = idx;
  8896. break;
  8897. }
  8898. }
  8899. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8900. {
  8901. confirmPeriods += 1;
  8902. }
  8903. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8904. }
  8905. else
  8906. {
  8907. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8908. }
  8909. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8910. return result;
  8911. }
  8912. int handleGetConfigurationRequest(char *uuid, char *payload)
  8913. {
  8914. mtrace();
  8915. int result = FAIL;
  8916. int MaxKeySupported = 0;
  8917. int n_keys = 0;
  8918. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8919. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8920. json_object *GetConfiguration;
  8921. GetConfiguration = json_tokener_parse(payload);
  8922. if(!is_error(GetConfiguration))
  8923. {
  8924. // Optional data
  8925. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8926. {
  8927. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8928. {
  8929. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8930. n_keys = idx + 1;
  8931. }
  8932. }
  8933. }
  8934. json_object_put(GetConfiguration);
  8935. UnknownKeynum = 0;
  8936. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8937. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8938. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8939. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8940. if(n_keys != 0)
  8941. {
  8942. for(int i=0;i<n_keys;i++)
  8943. {
  8944. getKeyValue(requestKey[i]);
  8945. }
  8946. }
  8947. else
  8948. {
  8949. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8950. getKeyValue("");
  8951. }
  8952. processUnkownKey();
  8953. sendGetConfigurationConfirmation(uuid);
  8954. return result;
  8955. }
  8956. static char fnamePlusPath[100]={0};
  8957. static char fnamePWithNoPath[60]={0};
  8958. void checkUploadLog(void)
  8959. {
  8960. FILE *fp;
  8961. /* Open the command for reading. */
  8962. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8963. if (fp == NULL) {
  8964. DEBUG_WARN("Failed to run command\n" );
  8965. exit(1);
  8966. }
  8967. int ftppathlen = 0;
  8968. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8969. int i = 0;
  8970. /* Read the output a line at a time - output it. */
  8971. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8972. if(i==0)
  8973. {
  8974. ftppathlen = strlen(fnamePlusPath);
  8975. DEBUG_INFO("%s\n", fnamePlusPath);
  8976. fnamePlusPath[ftppathlen]='\0';
  8977. break;
  8978. }
  8979. i= i+1;
  8980. }
  8981. /* close */
  8982. pclose(fp);
  8983. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8984. {
  8985. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8986. {
  8987. fnamePlusPath[k]='\0';
  8988. }
  8989. }
  8990. i=1;
  8991. //char fname[60]={0};
  8992. while(i < ftppathlen)
  8993. {
  8994. int len=ftppathlen-i;
  8995. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8996. {
  8997. DEBUG_INFO("compare '/' all right\n");
  8998. break;
  8999. }
  9000. i=i+1;
  9001. }
  9002. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9003. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9004. fnamePWithNoPath[i+1] = '\0';
  9005. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9006. {
  9007. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9008. {
  9009. fnamePWithNoPath[j]='\0';
  9010. }
  9011. }
  9012. FILE* fp1 = fopen(fnamePlusPath, "r");
  9013. if (fp1)
  9014. {
  9015. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9016. // file exists
  9017. fclose(fp1);
  9018. }
  9019. else
  9020. {
  9021. // file doesn't exist
  9022. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9023. }
  9024. }
  9025. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9026. {
  9027. mtrace();
  9028. int result = FAIL;
  9029. time_t CurrentTime;
  9030. struct tm *tm;
  9031. pthread_t th_Status;
  9032. CurrentTime = time(NULL);
  9033. tm = localtime(&CurrentTime);
  9034. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9035. 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);
  9036. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9037. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9038. return result;
  9039. }
  9040. void* GetDiagnosticsProcess(void* data)
  9041. {
  9042. pthread_detach(pthread_self());
  9043. mtrace();
  9044. int retriesInt=0, retryIntervalInt=0;
  9045. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9046. 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};
  9047. int port=0;
  9048. int isSuccess = FALSE;
  9049. char cmdBuf[2048];
  9050. struct tm *tmNow;
  9051. time_t CurrentTime;
  9052. struct tm tmStart;
  9053. struct tm tmStop;
  9054. CurrentTime = time(NULL);
  9055. tmNow=localtime(&CurrentTime);
  9056. uint16_t targetYear, targetMonth;
  9057. json_object *GetDiagnostics;
  9058. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9059. GetDiagnostics = json_tokener_parse(data);
  9060. if(!is_error(GetDiagnostics))
  9061. {
  9062. // Required data
  9063. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9064. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9065. // Optional data
  9066. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9067. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9068. else
  9069. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9070. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9071. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9072. else
  9073. retryIntervalInt = 30;
  9074. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9075. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9076. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9077. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9078. }
  9079. json_object_put(GetDiagnostics);
  9080. // Pack log to compress file
  9081. 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) &&
  9082. (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))
  9083. {
  9084. // Pack system log
  9085. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9086. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9087. targetYear = tmStart.tm_year;
  9088. targetMonth = tmStart.tm_mon;
  9089. do
  9090. {
  9091. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9092. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9093. if(targetMonth+1>=13)
  9094. {
  9095. targetYear += 1;
  9096. targetMonth = 1;
  9097. }
  9098. else
  9099. {
  9100. targetMonth += 1;
  9101. }
  9102. }while((targetYear < (tmNow->tm_year+1900)) ||
  9103. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9104. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9105. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9106. system(cmdBuf);
  9107. // Pack charging & event log
  9108. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9109. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9110. targetYear = tmStart.tm_year;
  9111. targetMonth = tmStart.tm_mon;
  9112. do
  9113. {
  9114. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9115. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9116. if(targetMonth+1>=13)
  9117. {
  9118. targetYear += 1;
  9119. targetMonth = 1;
  9120. }
  9121. else
  9122. {
  9123. targetMonth += 1;
  9124. }
  9125. }while((targetYear < (tmNow->tm_year+1900)) ||
  9126. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9127. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9128. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9129. system(cmdBuf);
  9130. // Combine log file
  9131. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9132. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9133. }
  9134. else
  9135. {
  9136. system("exec /root/logPackTools 'log' 6");
  9137. }
  9138. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9139. system(cmdBuf);
  9140. checkUploadLog();
  9141. //****************location*******************/
  9142. if(strcmp(locationstr,"")==0)
  9143. {
  9144. DEBUG_INFO("location is <Empty>!\n");
  9145. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9146. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9147. goto end;
  9148. }
  9149. memset(protocol, 0, ARRAY_SIZE(protocol));
  9150. memset(user, 0, ARRAY_SIZE(user) );
  9151. memset(password, 0, ARRAY_SIZE(password));
  9152. memset(host, 0, ARRAY_SIZE(host));
  9153. memset(path, 0, ARRAY_SIZE(path));
  9154. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9155. memset(host1, 0, ARRAY_SIZE(host1));
  9156. memset(path1, 0, ARRAY_SIZE(path1));
  9157. /*location: ftp://user:password@host:port/path*/
  9158. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9159. if((access(fnamePlusPath,F_OK))!=-1)
  9160. {
  9161. DEBUG_INFO("fnamePlusPath exist.\n");
  9162. }
  9163. else
  9164. {
  9165. DEBUG_INFO("fnamePlusPath not exist!\n");
  9166. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9167. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9168. goto end;
  9169. }
  9170. if(strchr(locationstr,'@')==NULL)
  9171. {
  9172. sscanf(locationstr,
  9173. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9174. protocol, host, &port, path);
  9175. strcpy(user,"anonymous");
  9176. strcpy(password,"");
  9177. }
  9178. else
  9179. {
  9180. //DEBUG_INFO("pch=%s\n", pch);
  9181. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9182. protocol, user, password, host, &port, path);
  9183. }
  9184. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9185. {
  9186. DEBUG_INFO("protocol is not ftp/http ! \n");
  9187. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9188. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9189. goto end;
  9190. }
  9191. if(strncmp(locationstr,"http", 4) == 0)
  9192. {
  9193. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9194. sprintf(ftppath,"/%s", path);
  9195. do
  9196. {
  9197. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9198. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9199. sleep(3);
  9200. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9201. if(!isSuccess)
  9202. {
  9203. DEBUG_INFO("Diagnostics fail.\n");
  9204. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9205. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9206. sleep(retryIntervalInt);
  9207. }
  9208. else
  9209. {
  9210. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9211. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9212. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9213. }
  9214. retriesInt--;
  9215. }while((isSuccess == 0)&&(retriesInt >= 0));
  9216. }
  9217. else
  9218. {
  9219. sscanf(host,"%[^/]%s",host1, path1);
  9220. if(strlen(path) > 0)
  9221. sprintf(ftppath,"/%s", path);
  9222. else
  9223. sprintf(ftppath,"/%s", path1);
  9224. int ftppathlen=strlen(ftppath);
  9225. int i=1;
  9226. char filenametemp[50];
  9227. while(i < ftppathlen)
  9228. {
  9229. int len=ftppathlen-i;
  9230. if(ftppath[len]== 47) // '/' ascll code: 47
  9231. {
  9232. DEBUG_INFO("find '/' all right\n");
  9233. break;
  9234. }
  9235. i=i+1;
  9236. }
  9237. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9238. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9239. filenametemp[i+1] = 0;
  9240. if(port == 0)
  9241. port = 21;
  9242. do
  9243. {
  9244. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9245. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9246. sleep(3);
  9247. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9248. if(!isSuccess)
  9249. {
  9250. DEBUG_INFO("Diagnostics fail.\n");
  9251. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9253. sleep(retryIntervalInt);
  9254. }
  9255. else
  9256. {
  9257. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9258. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9259. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9260. }
  9261. retriesInt--;
  9262. }while((!isSuccess)&&(retriesInt >= 0));
  9263. }
  9264. end:
  9265. system("rm -f /mnt/*");
  9266. sleep(5);
  9267. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9268. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9269. pthread_exit(NULL);
  9270. }
  9271. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9272. {
  9273. mtrace();
  9274. int result = FAIL;
  9275. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9276. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9277. {
  9278. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9279. locallistVersion = -1;
  9280. }
  9281. else
  9282. {
  9283. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9284. OCPP_getListVerion();
  9285. }
  9286. //from db.OCPP_getListVerion
  9287. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9288. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9289. sendGetLocalListVersionConfirmation(uuid,"");
  9290. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9291. return result;
  9292. }
  9293. int handleRemoteStartRequest(char *uuid, char *payload)
  9294. {
  9295. mtrace();
  9296. int result = FAIL;
  9297. int connectorIdInt=-1;
  9298. int tempIndex = 0;
  9299. int connectorIdIsNULL, chargingProfileIsNULL;
  9300. char comfirmstr[20]={0};
  9301. char cmdBuf[512];
  9302. json_object *RemoteStartTransaction;
  9303. FILE *fp;
  9304. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9305. if(server_pending == TRUE)
  9306. {
  9307. return 0;
  9308. }
  9309. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9310. RemoteStartTransaction = json_tokener_parse(payload);
  9311. if(!is_error(RemoteStartTransaction))
  9312. {
  9313. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9314. {
  9315. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9316. }
  9317. else
  9318. {
  9319. connectorIdIsNULL = TRUE;
  9320. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9321. {
  9322. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9323. {
  9324. connectorIdIsNULL = FALSE;
  9325. connectorIdInt = (gun_index+1);
  9326. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9327. break;
  9328. }
  9329. }
  9330. }
  9331. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9332. {
  9333. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9334. // Required data
  9335. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9336. // Optional data
  9337. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9338. {
  9339. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9340. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9341. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9342. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9343. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9344. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9345. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9346. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9347. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9348. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9349. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9350. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9351. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9352. {
  9353. 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")));
  9354. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9355. 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"));
  9356. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9357. 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"));
  9358. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9359. 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")));
  9360. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9361. {
  9362. 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++)
  9363. {
  9364. 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"));
  9365. 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"));
  9366. 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)
  9367. 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"));
  9368. }
  9369. }
  9370. }
  9371. }
  9372. else
  9373. {
  9374. chargingProfileIsNULL = TRUE;
  9375. }
  9376. }
  9377. }
  9378. else
  9379. {
  9380. connectorIdIsNULL = TRUE;
  9381. }
  9382. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9383. {
  9384. DEBUG_WARN("Connector id is NULL\n.");
  9385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9386. goto end;
  9387. }
  9388. /*
  9389. enum _SYSTEM_STATUS
  9390. {
  9391. S_BOOTING = 0,
  9392. S_IDLE, = 1
  9393. S_AUTHORIZING, = 2
  9394. S_REASSIGN_CHECK, = 3
  9395. S_REASSIGN, = 4
  9396. S_PRECHARGE, = 5
  9397. S_PREPARING_FOR_EV, = 6
  9398. S_PREPARING_FOR_EVSE, = 7
  9399. S_CHARGING, = 8
  9400. S_TERMINATING, = 9
  9401. S_COMPLETE, = 10
  9402. S_ALARM, = 11
  9403. S_FAULT = 12
  9404. }
  9405. */
  9406. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9407. {
  9408. //check Transaction active
  9409. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9410. {
  9411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9412. {
  9413. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9414. }
  9415. else
  9416. {
  9417. tempIndex = connectorIdInt -1;
  9418. }
  9419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9420. {
  9421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9422. {
  9423. 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))
  9424. {
  9425. //Reserved
  9426. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9427. }
  9428. 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))
  9429. {
  9430. //Reserved
  9431. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9433. goto end;
  9434. }
  9435. else
  9436. {
  9437. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9438. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9439. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9440. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9441. {
  9442. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9443. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9444. goto end;
  9445. }
  9446. }//END FOR ELSE
  9447. }
  9448. }// END FOR CHAdeMO_QUANTITY
  9449. }
  9450. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9451. {
  9452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9453. {
  9454. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9455. }
  9456. else
  9457. {
  9458. tempIndex = connectorIdInt -1;
  9459. }
  9460. for (int index = 0; index < CCS_QUANTITY; index++)
  9461. {
  9462. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9463. {
  9464. 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))
  9465. {
  9466. //Reserved
  9467. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9468. }
  9469. 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))
  9470. {
  9471. //Reserved
  9472. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9473. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9474. goto end;
  9475. }
  9476. else
  9477. {
  9478. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9479. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9480. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9481. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9482. {
  9483. DEBUG_WARN("CCS connector not allow start\n.");
  9484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9485. goto end;
  9486. }
  9487. }// END FOR ELSE
  9488. }
  9489. }// END FOR CCS_QUANTITY
  9490. }
  9491. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9492. {
  9493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9494. {
  9495. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9496. }
  9497. else
  9498. {
  9499. tempIndex = connectorIdInt -1;
  9500. }
  9501. for (int index = 0; index < GB_QUANTITY; index++)
  9502. {
  9503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9504. {
  9505. 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))
  9506. {
  9507. //Reserved
  9508. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9509. }
  9510. 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))
  9511. {
  9512. //Reserved
  9513. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9515. goto end;
  9516. }
  9517. else
  9518. {
  9519. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9520. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9521. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9522. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9523. {
  9524. DEBUG_WARN("GB connector not allow start\n.");
  9525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9526. goto end;
  9527. }
  9528. }// END FOR ELSE
  9529. }
  9530. } // END FOR GB_QUANTITY
  9531. }
  9532. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9533. {
  9534. tempIndex = connectorIdInt -1;
  9535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9536. {
  9537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9538. {
  9539. 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))
  9540. {
  9541. //Reserved
  9542. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9543. }
  9544. 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))
  9545. {
  9546. //Reserved
  9547. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9548. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9549. goto end;
  9550. }
  9551. else
  9552. {
  9553. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9554. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9555. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9556. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9557. {
  9558. DEBUG_WARN("GB connector not allow start\n.");
  9559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9560. goto end;
  9561. }
  9562. }// END FOR ELSE
  9563. }
  9564. } // END FOR GB_QUANTITY
  9565. }
  9566. else
  9567. {
  9568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9569. {
  9570. tempIndex = 2;
  9571. }
  9572. else
  9573. {
  9574. tempIndex = connectorIdInt -1;
  9575. }
  9576. for (int index = 0; index < AC_QUANTITY; index++)
  9577. {
  9578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9579. {
  9580. 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))
  9581. {
  9582. //Reserved
  9583. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9584. }
  9585. 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))
  9586. {
  9587. //Reserved
  9588. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9590. goto end;
  9591. }
  9592. else
  9593. {
  9594. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9595. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9596. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9597. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9598. {
  9599. DEBUG_WARN("AC connector not allow start\n.");
  9600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9601. goto end;
  9602. }
  9603. }//END FOR ELSE
  9604. }
  9605. }// END FOR AC_QUANTITY
  9606. }
  9607. if(chargingProfileIsNULL == FALSE)
  9608. {
  9609. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9610. {
  9611. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9613. //memset idTag
  9614. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9615. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9616. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9617. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9618. // Save profile to file
  9619. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9620. system(cmdBuf);
  9621. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9622. fp = fopen(cmdBuf, "w");
  9623. 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));
  9624. fclose(fp);
  9625. }
  9626. else
  9627. {
  9628. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9630. }
  9631. }
  9632. else
  9633. {
  9634. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9635. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9636. //memset idTag
  9637. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9638. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9639. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9640. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9641. }
  9642. }
  9643. else
  9644. {
  9645. DEBUG_WARN("Connector id over\n.");
  9646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9647. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9648. }
  9649. end:
  9650. json_object_put(RemoteStartTransaction);
  9651. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9652. {
  9653. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9654. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9655. }
  9656. //OCPP send RemoteStartConfirmation by first.
  9657. sendRemoteStartConfirmation(uuid, comfirmstr);
  9658. return result;
  9659. }
  9660. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9661. {
  9662. mtrace();
  9663. int result = FAIL;
  9664. int match = FALSE;
  9665. int GunNO = 0;
  9666. int tempIndex = 0;
  9667. int transactionIdInt=0;
  9668. int transactionIdIsNULL= TRUE;
  9669. char comfirmstr[20];
  9670. json_object *RemoteStopTransaction;
  9671. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9672. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9673. if(server_pending == TRUE)
  9674. {
  9675. return 0;
  9676. }
  9677. RemoteStopTransaction = json_tokener_parse(payload);
  9678. if(!is_error(RemoteStopTransaction))
  9679. {
  9680. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9681. {
  9682. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9683. transactionIdIsNULL = FALSE;
  9684. }
  9685. }
  9686. json_object_put(RemoteStopTransaction);
  9687. if(transactionIdIsNULL == FALSE)
  9688. {
  9689. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9690. {
  9691. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9692. {
  9693. //check Transaction active
  9694. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9695. {
  9696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9697. {
  9698. tempIndex = ((gun_index==2) ? 1: 0);
  9699. }
  9700. else
  9701. {
  9702. tempIndex = gun_index;
  9703. }
  9704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9705. {
  9706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9707. {
  9708. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9709. {
  9710. match = TRUE;
  9711. GunNO = gun_index;
  9712. }
  9713. }
  9714. }// END FOR CHAdeMO_QUANTITY
  9715. }
  9716. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9717. {
  9718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9719. {
  9720. tempIndex = ((gun_index==2) ? 1: 0);
  9721. }
  9722. else
  9723. {
  9724. tempIndex = gun_index;
  9725. }
  9726. for (int index = 0; index < CCS_QUANTITY; index++)
  9727. {
  9728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9729. {
  9730. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9731. {
  9732. match = TRUE;
  9733. GunNO = gun_index;
  9734. }
  9735. }
  9736. }// END FOR CCS_QUANTITY
  9737. }
  9738. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9739. {
  9740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9741. {
  9742. tempIndex = ((gun_index==2) ? 1: 0);
  9743. }
  9744. else
  9745. {
  9746. tempIndex = gun_index;
  9747. }
  9748. for (int index = 0; index < GB_QUANTITY; index++)
  9749. {
  9750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9751. {
  9752. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9753. {
  9754. match = TRUE;
  9755. GunNO = gun_index;
  9756. }
  9757. }
  9758. }// END FOR GB_QUANTITY
  9759. }
  9760. else if(gunType[gun_index] == GUN_TYPE_DO)
  9761. {
  9762. tempIndex = gun_index;
  9763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9764. {
  9765. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9766. {
  9767. 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
  9768. {
  9769. match = TRUE;
  9770. GunNO = gun_index;
  9771. }
  9772. }
  9773. }// END FOR GB_QUANTITY
  9774. }
  9775. else
  9776. {
  9777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9778. {
  9779. tempIndex = 2;
  9780. }
  9781. else
  9782. {
  9783. tempIndex = gun_index;
  9784. }
  9785. for (int index = 0; index < AC_QUANTITY; index++)
  9786. {
  9787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9788. {
  9789. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9790. {
  9791. match = TRUE;
  9792. GunNO = gun_index;
  9793. }
  9794. }
  9795. }// END FOR CHAdeMO_QUANTITY
  9796. } // END FOR AC ELSE
  9797. }// CHECK IF ResponseTransactionId == transactionIdInt
  9798. }//END FOR
  9799. if( match == TRUE)
  9800. {
  9801. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9802. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9803. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9804. }
  9805. else
  9806. {
  9807. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9808. }
  9809. }
  9810. else
  9811. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9812. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9813. return result;
  9814. }
  9815. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9816. {
  9817. mtrace();
  9818. int result = FAIL;
  9819. int connectorIdInt=0, reservationIdInt=0;
  9820. int tempIndex = 0;
  9821. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9822. char comfirmstr[20]={0};
  9823. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9824. int c = 0;
  9825. char *loc;
  9826. //char *ptr;
  9827. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9828. strcpy(sstrtemp, stringtrimspace(payload));
  9829. //***(1)connectorId ****/
  9830. c=0;
  9831. loc = strstr(sstrtemp, "connectorId");
  9832. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9833. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9834. {
  9835. sstr[c] = loc[strlen("connectorId")+2+c];
  9836. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9837. c++;
  9838. }
  9839. sstr[c] = '\0';
  9840. connectorIdInt = atoi(sstr);
  9841. //***(2)expiryDate ****/
  9842. loc = strstr(sstrtemp, "expiryDate");
  9843. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9844. c = 0;
  9845. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9846. {
  9847. sstr[c] = loc[3+strlen("expiryDate")+c];
  9848. c++;
  9849. }
  9850. sstr[c] = '\0';
  9851. strcpy(expiryDatestr, sstr);
  9852. //***(3)idTag ****/
  9853. loc = strstr(sstrtemp, "idTag");
  9854. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9855. c = 0;
  9856. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9857. {
  9858. sstr[c] = loc[3+strlen("idTag")+c];
  9859. c++;
  9860. }
  9861. sstr[c] = '\0';
  9862. strcpy(idTagstr, sstr);
  9863. //***(4)parentIdTag ****/
  9864. loc = strstr(sstrtemp, "parentIdTag");
  9865. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9866. c = 0;
  9867. if(loc == NULL)
  9868. {
  9869. strcpy(parentIdTagstr, "");
  9870. }
  9871. else
  9872. {
  9873. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9874. {
  9875. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9876. c++;
  9877. }
  9878. sstr[c] = '\0';
  9879. strcpy(parentIdTagstr, sstr);
  9880. }
  9881. //***(5)reservationId ****/
  9882. c=0;
  9883. loc = strstr(sstrtemp, "reservationId");
  9884. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9885. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9886. {
  9887. sstr[c] = loc[strlen("reservationId")+2+c];
  9888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9889. c++;
  9890. }
  9891. sstr[c] = '\0';
  9892. reservationIdInt = atoi(sstr);
  9893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9894. /*
  9895. enum SYSTEM_STATUS
  9896. {
  9897. SYS_MODE_BOOTING = 0,
  9898. SYS_MODE_IDLE = 1,
  9899. SYS_MODE_AUTHORIZING = 2,
  9900. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9901. SYS_MODE_REASSIGN = 4,
  9902. SYS_MODE_PREPARING = 5,
  9903. SYS_MODE_PREPARE_FOR_EV = 6,
  9904. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9905. SYS_MODE_CHARGING = 8,
  9906. SYS_MODE_TERMINATING = 9,
  9907. SYS_MODE_COMPLETE = 10,
  9908. SYS_MODE_ALARM = 11,
  9909. SYS_MODE_FAULT = 12,
  9910. SYS_MODE_RESERVATION = 13,
  9911. SYS_MODE_BOOKING = 14,
  9912. SYS_MODE_MAINTAIN = 15,
  9913. SYS_MODE_DEBUG = 16,
  9914. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9915. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9916. SYS_MODE_UPDATE = 19
  9917. };
  9918. */
  9919. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9920. {
  9921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9922. goto end;
  9923. }
  9924. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9925. {
  9926. //check Transaction active
  9927. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9928. {
  9929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9930. {
  9931. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9932. }
  9933. else
  9934. {
  9935. tempIndex = connectorIdInt -1;
  9936. }
  9937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9938. {
  9939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9940. {
  9941. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9942. {
  9943. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9944. {
  9945. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9946. {
  9947. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9949. }
  9950. 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'))
  9951. {
  9952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9953. }
  9954. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9955. {
  9956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9957. }
  9958. else
  9959. {
  9960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9961. }
  9962. }
  9963. 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
  9964. {
  9965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9966. }
  9967. }
  9968. else
  9969. {
  9970. //replace reservation
  9971. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9973. }
  9974. }
  9975. } // END FOR CHAdeMO_QUANTITY
  9976. }
  9977. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9978. {
  9979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9980. {
  9981. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9982. }
  9983. else
  9984. {
  9985. tempIndex = connectorIdInt -1;
  9986. }
  9987. for (int index = 0; index < CCS_QUANTITY; index++)
  9988. {
  9989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9990. {
  9991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9992. {
  9993. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9994. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9995. {
  9996. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9997. {
  9998. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10000. }
  10001. 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'))
  10002. {
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10004. }
  10005. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10006. {
  10007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10008. }
  10009. else
  10010. {
  10011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10012. }
  10013. }
  10014. 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
  10015. {
  10016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10017. }
  10018. }
  10019. else
  10020. {
  10021. //replace reservation
  10022. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10024. }
  10025. }
  10026. } // END FOR CCS_QUANTITY
  10027. }
  10028. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10029. {
  10030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10031. {
  10032. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10033. }
  10034. else
  10035. {
  10036. tempIndex = connectorIdInt -1;
  10037. }
  10038. for (int index = 0; index < GB_QUANTITY; index++)
  10039. {
  10040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10041. {
  10042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10043. {
  10044. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10045. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10046. {
  10047. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10048. {
  10049. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10051. }
  10052. 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'))
  10053. {
  10054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10055. }
  10056. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10057. {
  10058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10059. }
  10060. else
  10061. {
  10062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10063. }
  10064. }
  10065. 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
  10066. {
  10067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10068. }
  10069. }
  10070. else
  10071. {
  10072. //replace reservation
  10073. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10075. }
  10076. }
  10077. }// END FOR GB_QUANTITY
  10078. }
  10079. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10080. {
  10081. tempIndex = connectorIdInt -1;
  10082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10083. {
  10084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10085. {
  10086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10087. {
  10088. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10089. 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
  10090. {
  10091. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10092. {
  10093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10095. }
  10096. 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'))
  10097. {
  10098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10099. }
  10100. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10101. {
  10102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10103. }
  10104. else
  10105. {
  10106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10107. }
  10108. }
  10109. 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
  10110. {
  10111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10112. }
  10113. }
  10114. else
  10115. {
  10116. //replace reservation
  10117. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10119. }
  10120. }
  10121. }// END FOR GB_QUANTITY
  10122. }
  10123. else
  10124. {
  10125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10126. {
  10127. tempIndex = 2;
  10128. }
  10129. else
  10130. {
  10131. tempIndex = (connectorIdInt -1);
  10132. }
  10133. for (int index = 0; index < AC_QUANTITY; index++)
  10134. {
  10135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10136. {
  10137. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10138. {
  10139. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10140. {
  10141. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10142. {
  10143. 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))
  10144. {
  10145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10146. }
  10147. else
  10148. {
  10149. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10151. }
  10152. }
  10153. 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'))
  10154. {
  10155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10156. }
  10157. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10158. {
  10159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10160. }
  10161. else
  10162. {
  10163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10164. }
  10165. }
  10166. 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
  10167. {
  10168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10169. }
  10170. }
  10171. else
  10172. {
  10173. //replace reservation
  10174. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10176. }
  10177. }
  10178. } // END FOR AC_QUANTITY
  10179. }
  10180. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10181. }
  10182. else if(connectorIdInt == 0)
  10183. {
  10184. //check Transaction active
  10185. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10186. {
  10187. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10188. {
  10189. 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'))
  10190. {
  10191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10192. goto end;
  10193. }
  10194. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10195. {
  10196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10197. goto end;
  10198. }
  10199. 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
  10200. {
  10201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10202. goto end;
  10203. }
  10204. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10205. {
  10206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10207. goto end;
  10208. }
  10209. }
  10210. }// END FOR CHAdeMO_QUANTITY
  10211. for (int index = 0; index < CCS_QUANTITY; index++)
  10212. {
  10213. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10214. {
  10215. 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'))
  10216. {
  10217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10218. goto end;
  10219. }
  10220. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10221. {
  10222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10223. goto end;
  10224. }
  10225. 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
  10226. {
  10227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10228. goto end;
  10229. }
  10230. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10231. {
  10232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10233. goto end;
  10234. }
  10235. }
  10236. } // END FOR CCS_QUANTITY
  10237. for (int index = 0; index < GB_QUANTITY; index++)
  10238. {
  10239. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10240. {
  10241. 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'))
  10242. {
  10243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10244. goto end;
  10245. }
  10246. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10247. {
  10248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10249. goto end;
  10250. }
  10251. 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
  10252. {
  10253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10254. goto end;
  10255. }
  10256. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10257. {
  10258. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10259. goto end;
  10260. }
  10261. }
  10262. } // END FOR GB_QUANTITY
  10263. for (int index = 0; index < AC_QUANTITY; index++)
  10264. {
  10265. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10266. {
  10267. 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'))
  10268. {
  10269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10270. goto end;
  10271. }
  10272. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10273. {
  10274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10275. goto end;
  10276. }
  10277. 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
  10278. {
  10279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10280. goto end;
  10281. }
  10282. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10283. {
  10284. 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))
  10285. {
  10286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10287. goto end;
  10288. }
  10289. }
  10290. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10291. {
  10292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10293. goto end;
  10294. }
  10295. }
  10296. }// END FOR AC_QUANTITY
  10297. //The connectorId is 0
  10298. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10299. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10300. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10301. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10302. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10303. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10304. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10305. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10306. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10307. result = TRUE;
  10308. return result;
  10309. }
  10310. else
  10311. {
  10312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10313. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10314. }
  10315. if(strcmp(comfirmstr,"Accepted") == 0)
  10316. {
  10317. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10318. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10319. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10320. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10321. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10322. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10323. result = TRUE;
  10324. return result;
  10325. }
  10326. end:
  10327. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10328. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10329. return result;
  10330. }
  10331. int handleResetRequest(char *uuid, char *payload)
  10332. {
  10333. mtrace();
  10334. int result = FAIL;
  10335. char sstr[10]={0},sstrtemp[30]={ 0 };
  10336. char typestr[10]={0};
  10337. char comfirmstr[20]={0};
  10338. int c = 0;
  10339. char *loc;
  10340. DEBUG_INFO("handleResetRequest...\n");
  10341. strcpy(sstrtemp, stringtrimspace(payload));
  10342. loc = strstr(sstrtemp, "type");
  10343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10344. c = 0;
  10345. while (loc[3+strlen("type")+c] != '\"')
  10346. {
  10347. sstr[c] = loc[3+strlen("type")+c];
  10348. c++;
  10349. }
  10350. sstr[c] = '\0';
  10351. strcpy(typestr,sstr);
  10352. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10353. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10354. {
  10355. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10356. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10357. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10358. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10359. }
  10360. else
  10361. {
  10362. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10363. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10364. result = PASS;
  10365. }
  10366. sendResetConfirmation(uuid, comfirmstr);
  10367. return result;
  10368. }
  10369. int handleSendLocalListRequest(char *uuid, char *payload)
  10370. {
  10371. mtrace();
  10372. int result = FAIL;
  10373. char comfirmstr[20];
  10374. int checkState_Faulted = FALSE;
  10375. json_object *SendLocalList;
  10376. DEBUG_INFO("handleSendLocalListRequest...\n");
  10377. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10378. {
  10379. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10380. goto end;
  10381. }
  10382. //check Charge Point state
  10383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10384. {
  10385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10386. {
  10387. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10388. }
  10389. }
  10390. for (int index = 0; index < CCS_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10393. {
  10394. checkState_Faulted = TRUE; //OCPP Status
  10395. }
  10396. }
  10397. for (int index = 0; index < GB_QUANTITY; index++)
  10398. {
  10399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10400. {
  10401. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10402. }
  10403. }
  10404. //check Charge Point state
  10405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10406. {
  10407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10408. {
  10409. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10410. }
  10411. }
  10412. //check Charge Point state
  10413. for (int index = 0; index < AC_QUANTITY; index++)
  10414. {
  10415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10416. {
  10417. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10418. }
  10419. }
  10420. if(checkState_Faulted == TRUE)
  10421. {
  10422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10423. goto end;
  10424. }
  10425. // Parsing payload
  10426. SendLocalList = json_tokener_parse(payload);
  10427. if(!is_error(SendLocalList))
  10428. {
  10429. // Required data
  10430. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10431. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10432. // Optional data
  10433. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10434. {
  10435. //Check UpdateType
  10436. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10437. {
  10438. //Local list full update
  10439. DEBUG_INFO("Local list full update.\n");
  10440. OCPP_getListVerion();
  10441. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10442. {
  10443. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10444. goto end;
  10445. }
  10446. OCPP_cleanLocalList();
  10447. }
  10448. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10449. {
  10450. //Local list different update
  10451. DEBUG_INFO("Local list different update.\n");
  10452. OCPP_getListVerion();
  10453. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10454. {
  10455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10456. goto end;
  10457. }
  10458. }
  10459. else
  10460. {
  10461. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10462. goto end;
  10463. }
  10464. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10465. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10466. {
  10467. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10468. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10469. {
  10470. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10471. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10472. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10473. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10474. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10475. }
  10476. // Add to db
  10477. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10478. {
  10479. //Local list full update
  10480. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10481. idx,
  10482. ShmOCPP16Data->SendLocalList.ListVersion,
  10483. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10484. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10485. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10486. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10487. // update list
  10488. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10489. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10490. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10491. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10492. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10493. }
  10494. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10495. {
  10496. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10497. idx,
  10498. ShmOCPP16Data->SendLocalList.ListVersion,
  10499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10500. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10501. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10502. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10503. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10504. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10505. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10506. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10507. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10508. }
  10509. }
  10510. }
  10511. else
  10512. {
  10513. //Check UpdateType
  10514. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10515. {
  10516. //Local list full update
  10517. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10518. OCPP_cleanLocalList();
  10519. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10520. goto end;
  10521. }
  10522. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10523. {
  10524. //Local list different update
  10525. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10526. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10527. goto end;
  10528. }
  10529. }
  10530. result = PASS;
  10531. }
  10532. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10533. end:
  10534. json_object_put(SendLocalList);
  10535. sendSendLocalListConfirmation(uuid, comfirmstr);
  10536. return result;
  10537. }
  10538. #define MAX 200
  10539. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10540. {
  10541. mtrace();
  10542. int result = FAIL;
  10543. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10544. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10545. char chargingProfilePurposeStr[30]={0};
  10546. char chargingProfileKindStr[16]={0};
  10547. char recurrencyKindStr[10]={0};
  10548. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10549. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10550. int chargingSchedulePeriodCount = 0;
  10551. char comfirmstr[20]={0};
  10552. int meet= FALSE;
  10553. FILE *fptr1;
  10554. char filename[MAX]={0};
  10555. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10556. char rmFileCmd[50]={0};
  10557. char tempchargingProfilePurposeStr[30]={0};
  10558. char word[1600]={0};
  10559. int n_chargingProfile = 0;
  10560. json_object *SetChargingProfile;
  10561. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10562. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10563. SetChargingProfile = json_tokener_parse(payload);
  10564. if(!is_error(SetChargingProfile))
  10565. {
  10566. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10567. {
  10568. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10569. if(connectorIdInt == 0)
  10570. {
  10571. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10572. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10573. }
  10574. else
  10575. {
  10576. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10577. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10578. }
  10579. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10580. }
  10581. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10582. {
  10583. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10584. {
  10585. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10586. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10587. {
  10588. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10589. }
  10590. else
  10591. {
  10592. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10593. }
  10594. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10595. }
  10596. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10597. {
  10598. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10600. {
  10601. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10602. }
  10603. else
  10604. {
  10605. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10606. }
  10607. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10608. }
  10609. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10610. {
  10611. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10612. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10613. {
  10614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10615. }
  10616. else
  10617. {
  10618. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10619. }
  10620. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10621. }
  10622. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10623. {
  10624. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10625. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10626. {
  10627. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10628. }
  10629. else
  10630. {
  10631. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10632. }
  10633. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10634. }
  10635. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10636. {
  10637. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10638. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10639. {
  10640. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10641. }
  10642. else
  10643. {
  10644. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10645. }
  10646. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10647. }
  10648. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10649. {
  10650. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10651. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10654. }
  10655. else
  10656. {
  10657. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10658. }
  10659. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10660. }
  10661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10662. {
  10663. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10665. {
  10666. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10667. }
  10668. else
  10669. {
  10670. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10671. }
  10672. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10673. }
  10674. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10675. {
  10676. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10684. }
  10685. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10686. }
  10687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10688. {
  10689. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10690. {
  10691. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10695. }
  10696. else
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10699. }
  10700. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10701. }
  10702. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10703. {
  10704. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10705. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10706. {
  10707. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10708. }
  10709. else
  10710. {
  10711. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10712. }
  10713. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10714. }
  10715. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10716. {
  10717. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10718. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10719. {
  10720. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10721. }
  10722. else
  10723. {
  10724. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10725. }
  10726. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10727. }
  10728. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10729. {
  10730. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10731. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10732. {
  10733. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10734. }
  10735. else
  10736. {
  10737. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10738. }
  10739. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10740. }
  10741. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10742. {
  10743. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10744. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10745. if(chargingSchedulePeriodCount <= 10)
  10746. {
  10747. 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++)
  10748. {
  10749. 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)
  10750. {
  10751. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10752. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10753. {
  10754. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10755. }
  10756. else
  10757. {
  10758. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10759. }
  10760. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10761. }
  10762. 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)
  10763. {
  10764. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10765. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10766. {
  10767. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10768. }
  10769. else
  10770. {
  10771. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10772. }
  10773. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10774. }
  10775. 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)
  10776. {
  10777. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10778. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10779. {
  10780. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10781. }
  10782. else
  10783. {
  10784. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10785. }
  10786. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10787. }
  10788. }
  10789. }
  10790. }
  10791. }
  10792. }
  10793. }
  10794. json_object_put(SetChargingProfile);
  10795. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10796. {
  10797. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10798. goto end;
  10799. }
  10800. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10801. {
  10802. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10803. if(connectorIdInt != 0)
  10804. {
  10805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10806. goto end;
  10807. }
  10808. strcpy(filename, ChargePointMaxProfile_JSON );
  10809. fptr1 = fopen(filename, "r");
  10810. if (!fptr1)
  10811. {
  10812. //file not exist
  10813. DEBUG_INFO("Unable to open the input file!!\n");
  10814. fptr1 = fopen(filename, "w+");
  10815. }
  10816. else
  10817. {
  10818. //Check Charging Profile Count
  10819. while(fscanf(fptr1, "%s", word) != EOF)
  10820. {
  10821. //DEBUG_INFO("word=%s\n",word);
  10822. if(strstr(word, "chargingProfileId")!= NULL)
  10823. {
  10824. //DEBUG_INFO("test chargingProfileId \n");
  10825. n_chargingProfile = n_chargingProfile + 1;
  10826. //DEBUG_INFO("chargingProfileId Found\n");
  10827. }
  10828. }
  10829. }
  10830. fclose(fptr1);
  10831. }
  10832. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10833. {
  10834. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10835. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10836. {
  10837. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10838. goto end;
  10839. }
  10840. memset(filename, 0, ARRAY_SIZE(filename));
  10841. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10842. fptr1 = fopen(filename, "r");
  10843. if (!fptr1)
  10844. {
  10845. //file not exist
  10846. //DEBUG_INFO("Unable to open the input file!!\n");
  10847. fptr1 = fopen(filename, "w+");
  10848. }
  10849. else
  10850. {
  10851. //Check Charging Profile Count
  10852. while(fscanf(fptr1, "%s", word) != EOF)
  10853. {
  10854. //DEBUG_INFO("word=%s\n",word);
  10855. if(strstr(word, "chargingProfileId")!= NULL)
  10856. {
  10857. //DEBUG_INFO("test chargingProfileId \n");
  10858. n_chargingProfile = n_chargingProfile + 1;
  10859. //DEBUG_INFO("chargingProfileId Found\n");
  10860. }
  10861. }
  10862. }
  10863. fclose(fptr1);
  10864. }
  10865. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10866. {
  10867. //printf("set chargingProfile 1-4\n");
  10868. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10869. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10870. if(connectorIdInt == 0)
  10871. {
  10872. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10873. goto end;
  10874. }
  10875. int tempIndex = 0;
  10876. //check Transaction active
  10877. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10878. {
  10879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10880. {
  10881. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10882. }
  10883. else
  10884. {
  10885. tempIndex = connectorIdInt -1;
  10886. }
  10887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10888. {
  10889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10890. {
  10891. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10892. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10893. {
  10894. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10895. {
  10896. meet = TRUE;
  10897. break;
  10898. }
  10899. }
  10900. }
  10901. }
  10902. }
  10903. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10904. {
  10905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10906. {
  10907. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10908. }
  10909. else
  10910. {
  10911. tempIndex = connectorIdInt -1;
  10912. }
  10913. for (int index = 0; index < CCS_QUANTITY; index++)
  10914. {
  10915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10916. {
  10917. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10918. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10919. {
  10920. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10921. {
  10922. meet = TRUE;
  10923. break;
  10924. }
  10925. }
  10926. }
  10927. }
  10928. }
  10929. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10930. {
  10931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10932. {
  10933. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10934. }
  10935. else
  10936. {
  10937. tempIndex = connectorIdInt -1;
  10938. }
  10939. for (int index = 0; index < GB_QUANTITY; index++)
  10940. {
  10941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10942. {
  10943. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10944. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10945. {
  10946. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10947. {
  10948. meet = TRUE;
  10949. break;
  10950. }
  10951. }
  10952. }
  10953. }
  10954. }
  10955. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10956. {
  10957. tempIndex = connectorIdInt -1;
  10958. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10959. {
  10960. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10961. {
  10962. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10963. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10964. {
  10965. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10966. {
  10967. meet = TRUE;
  10968. break;
  10969. }
  10970. }
  10971. }
  10972. }
  10973. }
  10974. else
  10975. {
  10976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10977. {
  10978. tempIndex = 2;
  10979. }
  10980. else
  10981. {
  10982. tempIndex = (connectorIdInt -1);
  10983. }
  10984. for (int index = 0; index < AC_QUANTITY; index++)
  10985. {
  10986. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10987. {
  10988. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10989. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10990. {
  10991. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10992. {
  10993. meet = TRUE;
  10994. break;
  10995. }
  10996. }
  10997. }
  10998. }
  10999. }
  11000. //check Transaction active
  11001. if(meet == FALSE)
  11002. {
  11003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11004. goto end;
  11005. }
  11006. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  11007. {
  11008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11009. goto end;
  11010. }
  11011. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11012. fptr1 = fopen(filename, "r");
  11013. if (!fptr1)
  11014. {
  11015. //file not exist
  11016. DEBUG_INFO("Unable to open the input file!!\n");
  11017. fptr1 = fopen(filename, "w+");
  11018. }
  11019. else
  11020. {
  11021. //Check Charging Profile Count
  11022. while(fscanf(fptr1, "%s", word) != EOF)
  11023. {
  11024. //DEBUG_INFO("word=%s\n",word);
  11025. if(strstr(word, "chargingProfileId")!= NULL)
  11026. {
  11027. //DEBUG_INFO("test chargingProfileId \n");
  11028. n_chargingProfile = n_chargingProfile + 1;
  11029. //DEBUG_INFO("chargingProfileId Found\n");
  11030. }
  11031. }
  11032. }
  11033. fclose(fptr1);
  11034. }
  11035. // Check ChargeProfileMaxStackLevel
  11036. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11037. {
  11038. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11039. goto end;
  11040. }
  11041. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11042. {
  11043. int i = 0;
  11044. char fnametemp[200]={0};
  11045. n_chargingProfile = 0;
  11046. //Check ChargePointMaxProfile.json exit
  11047. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11048. {
  11049. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11050. //Check Charging Profile Count
  11051. while(fscanf(fptr1, "%s", word) != EOF)
  11052. {
  11053. //DEBUG_INFO("word=%s\n",word);
  11054. if(strstr(word, "chargingProfileId")!= NULL)
  11055. {
  11056. //DEBUG_INFO("test chargingProfileId \n");
  11057. n_chargingProfile = n_chargingProfile + 1;
  11058. i = i + 1;
  11059. //DEBUG_INFO("chargingProfileId Found\n");
  11060. }
  11061. memset(word, 0, ARRAY_SIZE(word));
  11062. }
  11063. fclose(fptr1);
  11064. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11065. }
  11066. //Check TxDefaultProfile_0.json exit
  11067. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11068. {
  11069. i = 0;
  11070. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11071. //Check Charging Profile Count
  11072. while(fscanf(fptr1, "%s", word) != EOF)
  11073. {
  11074. //DEBUG_INFO("word=%s\n",word);
  11075. if(strstr(word, "chargingProfileId")!= NULL)
  11076. {
  11077. //DEBUG_INFO("test chargingProfileId \n");
  11078. n_chargingProfile = n_chargingProfile + 1;
  11079. i = i + 1;
  11080. //DEBUG_INFO("chargingProfileId Found\n");
  11081. }
  11082. memset(word, 0, ARRAY_SIZE(word));
  11083. }
  11084. fclose(fptr1);
  11085. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11086. }
  11087. //Check TxDefaultProfile_%d.json
  11088. for(int j=1; j <= gunTotalNumber; j++)
  11089. {
  11090. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11091. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11092. if((access(fnametemp,F_OK))!=-1)
  11093. {
  11094. i = 0;
  11095. fptr1 = fopen(fnametemp, "r");
  11096. //Check Charging Profile Count
  11097. while(fscanf(fptr1, "%s", word) != EOF)
  11098. {
  11099. //DEBUG_INFO("word=%s\n",word);
  11100. if(strstr(word, "chargingProfileId")!= NULL)
  11101. {
  11102. //DEBUG_INFO("test chargingProfileId \n");
  11103. n_chargingProfile = n_chargingProfile + 1;
  11104. i = i + 1;
  11105. //DEBUG_INFO("chargingProfileId Found\n");
  11106. }
  11107. memset(word, 0, ARRAY_SIZE(word));
  11108. }
  11109. fclose(fptr1);
  11110. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11111. }
  11112. }
  11113. //Check TxProfile_%d.json
  11114. for(int j=1; j <= gunTotalNumber; j++)
  11115. {
  11116. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11117. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11118. if((access(fnametemp,F_OK))!=-1)
  11119. {
  11120. i = 0;
  11121. fptr1 = fopen(fnametemp, "r");
  11122. //Check Charging Profile Count
  11123. while(fscanf(fptr1, "%s", word) != EOF)
  11124. {
  11125. //DEBUG_INFO("word=%s\n",word);
  11126. if(strstr(word, "chargingProfileId")!= NULL)
  11127. {
  11128. //DEBUG_INFO("test chargingProfileId \n");
  11129. n_chargingProfile = n_chargingProfile + 1;
  11130. i = i + 1;
  11131. //DEBUG_INFO("chargingProfileId Found\n");
  11132. }
  11133. memset(word, 0, ARRAY_SIZE(word));
  11134. }
  11135. fclose(fptr1);
  11136. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11137. }
  11138. }
  11139. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11140. {
  11141. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11142. goto end;
  11143. }
  11144. }
  11145. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11146. //**********************************Write to File********************************************************/
  11147. FILE *infile;
  11148. FILE *outfile;
  11149. infile = fopen (filename, "r");
  11150. outfile = fopen (tempfile, "w");
  11151. int d =0;
  11152. d = fgetc(infile);
  11153. rewind(infile);
  11154. if(d == EOF)
  11155. {
  11156. // Profile is empty
  11157. fprintf(outfile,"%s\n",payload);
  11158. fclose(infile);
  11159. fclose(outfile);
  11160. sprintf(rmFileCmd,"rm -f %s",filename);
  11161. system(rmFileCmd);
  11162. rename(tempfile, filename);
  11163. }
  11164. else
  11165. {
  11166. // Profile is not empty
  11167. char buf[2048]={0};
  11168. int ChargingProfileAdded = FALSE;
  11169. while (fgets(buf, sizeof(buf), infile) != NULL)
  11170. {
  11171. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11172. json_object *tmpChargingProfile;
  11173. tmpChargingProfile = json_tokener_parse(buf);
  11174. if(!is_error(SetChargingProfile))
  11175. {
  11176. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11177. {
  11178. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11179. }
  11180. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11181. {
  11182. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11183. {
  11184. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11185. }
  11186. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11187. {
  11188. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11189. }
  11190. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11191. {
  11192. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11193. }
  11194. }
  11195. }
  11196. json_object_put(tmpChargingProfile);
  11197. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11198. {
  11199. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11200. {
  11201. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11202. if(ChargingProfileAdded == FALSE)
  11203. {
  11204. fprintf(outfile,"%s\n",payload);
  11205. ChargingProfileAdded = TRUE;
  11206. }
  11207. }
  11208. else
  11209. {
  11210. if(tempstackLevelInt < stackLevelInt)
  11211. {
  11212. if(ChargingProfileAdded == FALSE)
  11213. {
  11214. fprintf(outfile,"%s\n",buf);
  11215. fprintf(outfile,"%s\n",payload);
  11216. ChargingProfileAdded = TRUE;
  11217. }
  11218. else
  11219. {
  11220. fprintf(outfile,"%s\n",buf);
  11221. }
  11222. }
  11223. else
  11224. {
  11225. if(ChargingProfileAdded == FALSE)
  11226. {
  11227. fprintf(outfile,"%s\n",buf);
  11228. fprintf(outfile,"%s\n",payload);
  11229. ChargingProfileAdded = TRUE;
  11230. }
  11231. else
  11232. {
  11233. fprintf(outfile,"%s\n",buf);
  11234. }
  11235. }
  11236. }
  11237. }
  11238. else
  11239. {
  11240. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11241. {
  11242. if(ChargingProfileAdded == FALSE)
  11243. {
  11244. fprintf(outfile,"%s\n",buf);
  11245. fprintf(outfile,"%s\n",payload);
  11246. ChargingProfileAdded = TRUE;
  11247. }
  11248. else
  11249. {
  11250. fprintf(outfile,"%s\n",buf);
  11251. }
  11252. }
  11253. else if(tempstackLevelInt < stackLevelInt)
  11254. {
  11255. if(ChargingProfileAdded == FALSE)
  11256. {
  11257. fprintf(outfile,"%s\n",buf);
  11258. fprintf(outfile,"%s\n",payload);
  11259. ChargingProfileAdded = TRUE;
  11260. }
  11261. else
  11262. {
  11263. fprintf(outfile,"%s\n",buf);
  11264. }
  11265. }
  11266. else
  11267. {
  11268. if(ChargingProfileAdded == FALSE)
  11269. {
  11270. fprintf(outfile,"%s\n",buf);
  11271. fprintf(outfile,"%s\n",payload);
  11272. ChargingProfileAdded = TRUE;
  11273. }
  11274. else
  11275. {
  11276. fprintf(outfile,"%s\n",buf);
  11277. }
  11278. }
  11279. }
  11280. } // end of while loop
  11281. fclose(infile);
  11282. fclose(outfile);
  11283. sprintf(rmFileCmd,"rm -f %s",filename);
  11284. system(rmFileCmd);
  11285. rename(tempfile, filename);
  11286. }
  11287. sleep(1);
  11288. result = TRUE;
  11289. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11290. end:
  11291. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11292. {
  11293. if(connectorIdInt == 0)
  11294. {
  11295. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11296. {
  11297. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11298. }
  11299. }
  11300. else
  11301. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11302. }
  11303. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11304. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11305. return result;
  11306. }
  11307. int handleTriggerMessageRequest(char *uuid, char *payload)
  11308. {
  11309. mtrace();
  11310. int result = FAIL;
  11311. int connectorIdIsNULL = FALSE;
  11312. int connectorIdInt =0;
  11313. char sstr[40]={0},sstrtemp[100]={ 0 };
  11314. char requestedMessagestr[40]={0};
  11315. char comfirmstr[20]={0};
  11316. int c = 0;
  11317. char *loc;
  11318. DEBUG_INFO("handleTriggerMessageRequest\n");
  11319. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11320. strcpy(sstrtemp, stringtrimspace(payload));
  11321. c = 0;
  11322. loc = strstr(sstrtemp, "requestedMessage");
  11323. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11324. {
  11325. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11326. c++;
  11327. }
  11328. sstr[c] = '\0';
  11329. strcpy(requestedMessagestr, sstr);
  11330. c = 0;
  11331. loc = strstr(sstrtemp, "connectorId");
  11332. if(loc == NULL)
  11333. {
  11334. connectorIdIsNULL = TRUE;
  11335. }
  11336. else
  11337. {
  11338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11339. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11340. {
  11341. sstr[c] = loc[strlen("connectorId")+2+c];
  11342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11343. c++;
  11344. }
  11345. sstr[c] = '\0';
  11346. connectorIdInt = atoi(sstr);
  11347. }
  11348. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11349. {
  11350. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11351. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11352. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11353. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11354. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11355. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11356. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11357. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11358. {
  11359. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11360. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11361. return TRUE;
  11362. }
  11363. else
  11364. {
  11365. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11366. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11367. }
  11368. }
  11369. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11370. {
  11371. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11372. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11373. return TRUE;
  11374. }
  11375. //==========================
  11376. // Trigger message
  11377. //==========================
  11378. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11379. {
  11380. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11381. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11382. {
  11383. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11384. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11385. }
  11386. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11387. }
  11388. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11389. {
  11390. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11391. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11392. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11393. }
  11394. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11395. {
  11396. //sendBootNotificationRequest();
  11397. server_sign = FALSE;
  11398. }
  11399. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11400. {
  11401. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11402. }
  11403. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11404. {
  11405. if(connectorIdIsNULL == FALSE)
  11406. {
  11407. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11408. {
  11409. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11410. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11411. }
  11412. }
  11413. else
  11414. {
  11415. for(int idx=0;idx< gunTotalNumber;idx++)
  11416. {
  11417. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11418. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11419. }
  11420. }
  11421. }
  11422. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11423. {
  11424. if(connectorIdIsNULL == FALSE)
  11425. {
  11426. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11427. {
  11428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11429. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11430. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11431. }
  11432. }
  11433. else
  11434. {
  11435. for(int idx=0;idx< gunTotalNumber;idx++)
  11436. {
  11437. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11438. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11439. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11440. }
  11441. }
  11442. }
  11443. return result;
  11444. }
  11445. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11446. {
  11447. mtrace();
  11448. int result = FAIL;
  11449. int connectorIdInt =0;
  11450. char comfirmstr[20]={0};
  11451. int tempIndex = 0;
  11452. json_object *UnlockConnector;
  11453. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11454. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11455. UnlockConnector = json_tokener_parse(payload);
  11456. if(!is_error(UnlockConnector))
  11457. {
  11458. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11459. {
  11460. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11461. }
  11462. }
  11463. json_object_put(UnlockConnector);
  11464. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11465. if(gunTotalNumber == 0)
  11466. {
  11467. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11468. goto end;
  11469. }
  11470. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11471. {
  11472. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11473. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11474. goto end;
  11475. }
  11476. else
  11477. {
  11478. //check Transaction active
  11479. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11480. {
  11481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11482. {
  11483. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11484. }
  11485. else
  11486. {
  11487. tempIndex = connectorIdInt -1;
  11488. }
  11489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11490. {
  11491. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11492. {
  11493. //stop Transaction
  11494. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11495. }
  11496. }
  11497. }
  11498. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11499. {
  11500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11501. {
  11502. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11503. }
  11504. else
  11505. {
  11506. tempIndex = connectorIdInt -1;
  11507. }
  11508. for (int index = 0; index < CCS_QUANTITY; index++)
  11509. {
  11510. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11511. {
  11512. //stop Transaction
  11513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11514. }
  11515. }
  11516. }
  11517. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11518. {
  11519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11520. {
  11521. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11522. }
  11523. else
  11524. {
  11525. tempIndex = connectorIdInt -1;
  11526. }
  11527. for (int index = 0; index < GB_QUANTITY; index++)
  11528. {
  11529. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11530. {
  11531. //stop Transaction
  11532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11533. }
  11534. }
  11535. }
  11536. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11537. {
  11538. tempIndex = connectorIdInt -1;
  11539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11540. {
  11541. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11542. {
  11543. //stop Transaction
  11544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11545. }
  11546. }
  11547. }
  11548. else
  11549. {
  11550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11551. {
  11552. tempIndex = 2;
  11553. }
  11554. else
  11555. {
  11556. tempIndex = connectorIdInt-1;
  11557. }
  11558. for (int index = 0; index < AC_QUANTITY; index++)
  11559. {
  11560. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11561. {
  11562. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11563. }
  11564. }
  11565. }
  11566. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11567. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11568. result = TRUE;
  11569. return result;
  11570. }
  11571. end:
  11572. //json_object_put(obj); --- remove temporally
  11573. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11574. return result;
  11575. }
  11576. static char UpdateFirmwarepayloadData[300]={0};
  11577. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11578. {
  11579. mtrace();
  11580. int result = FAIL;
  11581. pthread_t t;
  11582. sendUpdateFirmwareConfirmation(uuid);
  11583. memset(UpdateFirmwarepayloadData, 0, 300);
  11584. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11585. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11586. ////pthread_join(t, NULL); //
  11587. //pthread_detach(t);
  11588. //sendUpdateFirmwareConfirmation(uuid);
  11589. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11590. return result;
  11591. }
  11592. void *UpdateFirmwareProcess(void *data)
  11593. {
  11594. pthread_detach(pthread_self());
  11595. mtrace();
  11596. int retriesInt =0, retryIntervalInt=0;
  11597. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11598. int port=0;
  11599. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11600. int isSuccess = 0;
  11601. char ftpbuf[1024];
  11602. char temp[1024];
  11603. char * pch;
  11604. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11605. json_object *UpdateFirmware;
  11606. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11607. if(!is_error(UpdateFirmware))
  11608. {
  11609. // Required data
  11610. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11611. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11612. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11613. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11614. // Optional data
  11615. if(json_object_object_get(UpdateFirmware, "retries"))
  11616. {
  11617. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11618. }
  11619. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11620. {
  11621. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11622. }
  11623. }
  11624. json_object_put(UpdateFirmware);
  11625. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11626. memset(path, 0, ARRAY_SIZE(path));
  11627. // Wait retrieveData
  11628. if(strlen(retrieveDatestr) > 10)
  11629. {
  11630. do
  11631. {
  11632. sleep(1);
  11633. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11634. }
  11635. // Ready to download
  11636. system("rm -f /mnt/*");
  11637. if(strncmp(locationstr,"http", 4) == 0)
  11638. {
  11639. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11640. sprintf(ftppath,"/%s", path);
  11641. DEBUG_INFO("locationstr: %s\n", locationstr);
  11642. DEBUG_INFO("protocol: %s\n",protocol);
  11643. DEBUG_INFO("host: %s\n",host);
  11644. DEBUG_INFO("path: %s\n",path);
  11645. DEBUG_INFO("ftppath: %s\n",ftppath);
  11646. int ftppathlen=strlen(ftppath);
  11647. int i=1;
  11648. char filenametemp[50];
  11649. while(i < ftppathlen)
  11650. {
  11651. int len=ftppathlen-i;
  11652. if(ftppath[len]== 47) // '/' ascll code: 47
  11653. {
  11654. DEBUG_INFO("compare '/' all right\n");
  11655. break;
  11656. }
  11657. i=i+1;
  11658. }
  11659. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11660. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11661. filenametemp[i+1] = 0;
  11662. do
  11663. {
  11664. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11665. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11666. sleep(1);
  11667. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11668. if(!isSuccess)
  11669. {
  11670. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11671. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11672. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11673. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11674. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11675. }
  11676. else
  11677. {
  11678. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11679. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11680. }
  11681. retriesInt--;
  11682. }while((isSuccess == 0)&&(retriesInt >= 0));
  11683. }
  11684. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11685. {
  11686. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11687. memset(temp, 0, ARRAY_SIZE(temp));
  11688. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11689. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11690. int ftppathlen=strlen(ftpbuf);
  11691. int i=1;
  11692. char filenametemp[50];
  11693. while(i < ftppathlen)
  11694. {
  11695. int len=ftppathlen-i;
  11696. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11697. {
  11698. DEBUG_INFO(" compare '/' all right\n");
  11699. break;
  11700. }
  11701. i=i+1;
  11702. }
  11703. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11704. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11705. filenametemp[i+1] = 0;
  11706. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11707. pch=strchr(temp,'@');
  11708. if(pch==NULL)
  11709. {
  11710. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11711. protocol, host, &port, path);
  11712. strcpy(user,"anonymous");
  11713. strcpy(password,"");
  11714. }
  11715. else
  11716. {
  11717. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11718. protocol, user, password, host, &port, path);
  11719. }
  11720. sscanf(host,"%[^/]%s",host1, path1);
  11721. sprintf(ftppath,"%s", path1);
  11722. //DEBUG_INFO("protocol =%s\n",protocol);
  11723. //DEBUG_INFO("user =%s\n",user);
  11724. //DEBUG_INFO("password =%s\n",password);
  11725. //DEBUG_INFO("host1 =%s\n",host1);
  11726. //DEBUG_INFO("port =%d\n",port);
  11727. //DEBUG_INFO("path1 =%s\n",path1);
  11728. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11729. //ftpFile(host, user, password, port, ftppath, fname);
  11730. //download firmware pthred
  11731. if(port == 0)
  11732. {
  11733. port = 21;
  11734. }
  11735. do
  11736. {
  11737. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11738. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11739. sleep(1);
  11740. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11741. if(!isSuccess)
  11742. {
  11743. //BulldogUtil.sleepMs(interval*1000);
  11744. DEBUG_INFO("Update firmware request and download file fail.\n");
  11745. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11746. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11747. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11748. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11749. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11750. }
  11751. else
  11752. {
  11753. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11754. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11755. }
  11756. retriesInt--;
  11757. }while((!isSuccess)&&(retriesInt >= 0));
  11758. }
  11759. else
  11760. {
  11761. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11762. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11763. sleep(1);
  11764. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11765. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11766. }
  11767. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11768. pthread_exit(NULL);
  11769. }
  11770. int handleCertificateSignedRequest(char *uuid, char *payload)
  11771. {
  11772. mtrace();
  11773. int result = PASS;
  11774. json_object *CertificateSigned;
  11775. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11776. CertificateSigned = json_tokener_parse(payload);
  11777. if(!is_error(CertificateSigned))
  11778. {
  11779. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11780. }
  11781. json_object_put(CertificateSigned);
  11782. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11783. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11784. fclose(fp);
  11785. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11786. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11787. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11788. sendCertificateSignedConfirmation(uuid);
  11789. return result;
  11790. }
  11791. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11792. {
  11793. mtrace();
  11794. int result = PASS;
  11795. json_object *DeleteCertificate;
  11796. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11797. DeleteCertificate = json_tokener_parse(payload);
  11798. if(!is_error(DeleteCertificate))
  11799. {
  11800. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11801. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11802. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11803. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11804. }
  11805. json_object_put(DeleteCertificate);
  11806. /*
  11807. * TODO: Delete certificateSigned process
  11808. */
  11809. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11810. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11811. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11812. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11813. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11814. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11815. sendDeleteCertificateConfirmation(uuid);
  11816. return result;
  11817. }
  11818. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11819. {
  11820. mtrace();
  11821. int result = PASS;
  11822. json_object *ExtendedTriggerMessage;
  11823. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11824. ExtendedTriggerMessage = json_tokener_parse(payload);
  11825. if(!is_error(ExtendedTriggerMessage))
  11826. {
  11827. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11828. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11829. {
  11830. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11831. }
  11832. else
  11833. {
  11834. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11835. }
  11836. }
  11837. json_object_put(ExtendedTriggerMessage);
  11838. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11839. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11840. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11841. {
  11842. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11843. }
  11844. else
  11845. {
  11846. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11847. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11848. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11849. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11850. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11851. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11852. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11853. {
  11854. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11855. }
  11856. else
  11857. {
  11858. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11859. }
  11860. }
  11861. sendExtendedTriggerMessageConfirmation(uuid);
  11862. //==========================
  11863. // Trigger message
  11864. //==========================
  11865. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11866. {
  11867. //sendBootNotificationRequest();
  11868. server_sign = FALSE;
  11869. }
  11870. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11871. {
  11872. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11873. }
  11874. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11875. {
  11876. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11877. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11878. {
  11879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11880. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11881. }
  11882. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11883. }
  11884. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11885. {
  11886. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11887. }
  11888. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11889. {
  11890. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11891. {
  11892. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11893. }
  11894. else
  11895. {
  11896. for(int idx=0;idx< gunTotalNumber;idx++)
  11897. {
  11898. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11899. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11900. }
  11901. }
  11902. }
  11903. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11904. {
  11905. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11906. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11907. {
  11908. 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\" &");
  11909. }
  11910. }
  11911. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11912. {
  11913. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11914. {
  11915. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11916. }
  11917. else
  11918. {
  11919. for(int idx=0;idx< gunTotalNumber;idx++)
  11920. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11921. }
  11922. }
  11923. return result;
  11924. }
  11925. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11926. {
  11927. mtrace();
  11928. int result = PASS;
  11929. json_object *GetInstalledCertificateIds;
  11930. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11931. GetInstalledCertificateIds = json_tokener_parse(payload);
  11932. if(!is_error(GetInstalledCertificateIds))
  11933. {
  11934. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11935. }
  11936. json_object_put(GetInstalledCertificateIds);
  11937. /*
  11938. * TODO: Return installed certificate process
  11939. */
  11940. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11941. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11942. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11943. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11944. sendGetInstalledCertificateIdsConfirmation(uuid);
  11945. return result;
  11946. }
  11947. int handleGetLogRequest(char *uuid, char *payload)
  11948. {
  11949. mtrace();
  11950. int result = PASS;
  11951. json_object *GetLog;
  11952. DEBUG_INFO("handleGetLogRequest...\n");
  11953. GetLog = json_tokener_parse(payload);
  11954. if(!is_error(GetLog))
  11955. {
  11956. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11957. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11958. if(json_object_object_get(GetLog, "retries") != NULL)
  11959. {
  11960. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11961. }
  11962. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11963. {
  11964. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11965. }
  11966. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11967. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11968. {
  11969. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11970. }
  11971. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11972. {
  11973. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11974. }
  11975. }
  11976. json_object_put(GetLog);
  11977. /*
  11978. * TODO: Upload log process
  11979. */
  11980. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11981. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11982. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11983. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11984. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11985. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11986. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11987. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11988. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11989. sendGetLogConfirmation(uuid);
  11990. return result;
  11991. }
  11992. int handleInstallCertificateRequest(char *uuid, char *payload)
  11993. {
  11994. mtrace();
  11995. int result = PASS;
  11996. json_object *InstallCertificate;
  11997. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11998. InstallCertificate = json_tokener_parse(payload);
  11999. if(!is_error(InstallCertificate))
  12000. {
  12001. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12002. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12003. /*
  12004. * TODO: Install certificate process
  12005. */
  12006. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12007. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12008. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12009. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12010. sendInstallCertificateConfirmation(uuid);
  12011. }
  12012. json_object_put(InstallCertificate);
  12013. return result;
  12014. }
  12015. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12016. {
  12017. mtrace();
  12018. int result = PASS;
  12019. json_object *SignedUpdateFirmware;
  12020. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12021. SignedUpdateFirmware = json_tokener_parse(payload);
  12022. if(!is_error(SignedUpdateFirmware))
  12023. {
  12024. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12025. {
  12026. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12027. }
  12028. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12029. {
  12030. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12031. }
  12032. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12033. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12034. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12035. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12036. {
  12037. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12038. }
  12039. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12040. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12041. }
  12042. json_object_put(SignedUpdateFirmware);
  12043. /*
  12044. * TODO: Upgrade firmware process
  12045. */
  12046. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12047. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12048. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12049. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12050. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12051. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12052. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12053. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12054. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12055. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12056. sendInstallCertificateConfirmation(uuid);
  12057. return result;
  12058. }
  12059. int handleUnknownRequest(char *uuid, char *payload)
  12060. {
  12061. mtrace();
  12062. int result = PASS;
  12063. DEBUG_INFO("handleUnknownRequest...\n");
  12064. sendUnknownConfirmation(uuid);
  12065. result = PASS;
  12066. return result;
  12067. }
  12068. //==========================================
  12069. // Handle server response routine
  12070. //==========================================
  12071. void handleAuthorizeResponse(char *payload, int gun_index)
  12072. {
  12073. mtrace();
  12074. char expiryDatestr[30]={0};
  12075. char parentIdTagstr[20]={0};
  12076. char statusstr[20]={0};
  12077. int expiryDateISNULL=FALSE;
  12078. int parentIdTagISNULL=FALSE;
  12079. DEBUG_INFO("handleAuthorizeResponse...\n");
  12080. json_object *Authorize;
  12081. Authorize = json_tokener_parse(payload);
  12082. if(!is_error(Authorize))
  12083. {
  12084. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12085. {
  12086. // Required data
  12087. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12088. // Optional data
  12089. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12090. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12091. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12092. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12093. }
  12094. }
  12095. json_object_put(Authorize);
  12096. if(expiryDateISNULL == FALSE)
  12097. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12098. if(parentIdTagISNULL == FALSE)
  12099. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12100. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12101. //Update idTag information to authorization cache if supproted
  12102. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12103. {
  12104. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12105. }
  12106. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12107. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12108. authorizeRetryTimes = 0;
  12109. }
  12110. void handleBootNotificationResponse(char *payload, int gun_index)
  12111. {
  12112. mtrace();
  12113. char statusStr[12]={0};
  12114. char currentTimeStr[30]={0};
  12115. int intervalInt = 0;
  12116. DEBUG_INFO("handleBootNotificationResponse...\n");
  12117. json_object *BootNotification;
  12118. BootNotification = json_tokener_parse(payload);
  12119. if(!is_error(BootNotification))
  12120. {
  12121. // Required data
  12122. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12123. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12124. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12125. }
  12126. json_object_put(BootNotification);
  12127. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12128. BootNotificationInterval = intervalInt;
  12129. HeartBeatWaitTime = intervalInt;
  12130. //write back to ShmOCPP16Data->BootNotification
  12131. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12132. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12133. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12134. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12135. {
  12136. server_sign = TRUE;
  12137. server_pending =FALSE;
  12138. }
  12139. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12140. {
  12141. server_pending = TRUE;
  12142. }
  12143. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12144. srand(time(NULL));
  12145. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12146. SetOcppConnStatus(TRUE);
  12147. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12148. }
  12149. void handleDataTransferResponse(char *payload, int gun_index)
  12150. {
  12151. char sstr[160]={0};//sstr[200]={ 0 };
  12152. int c = 0;
  12153. char *loc;
  12154. DEBUG_INFO("handleDataTransferResponse ...\n");
  12155. loc = strstr(payload, "status");
  12156. c = 0;
  12157. while (loc[3+strlen("status")+c] != '\"')
  12158. {
  12159. sstr[c] = loc[3+strlen("status")+c];
  12160. c++;
  12161. }
  12162. sstr[c] = '\0';
  12163. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12164. }
  12165. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12166. {
  12167. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12168. //struct json_object *obj;
  12169. // obj = json_tokener_parse(payload);
  12170. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12171. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12172. //No fields are defined.
  12173. }
  12174. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12175. {
  12176. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12177. //struct json_object *obj;
  12178. // obj = json_tokener_parse(payload);
  12179. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12180. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12181. //No fields are defined.
  12182. }
  12183. void handleHeartbeatResponse(char *payload, int gun_index)
  12184. {
  12185. mtrace();
  12186. DEBUG_INFO("handleHeartbeatResponse...\n");
  12187. json_object *Heartbeat;
  12188. Heartbeat = json_tokener_parse(payload);
  12189. if(!is_error(Heartbeat))
  12190. {
  12191. // Required data
  12192. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12193. }
  12194. json_object_put(Heartbeat);
  12195. if(FirstHeartBeat == 0)
  12196. {
  12197. FirstHeartBeat = 1;
  12198. DEBUG_INFO("FirstHeartBeat \n");
  12199. }
  12200. HeartBeatWithNOResponse = 0;
  12201. clientTime.Heartbeat=time((time_t*)NULL);
  12202. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12203. }
  12204. void handleMeterValuesResponse(char *payload, int gun_index)
  12205. {
  12206. mtrace();
  12207. DEBUG_INFO("handleMeterValuesResponse...\n");
  12208. }
  12209. void handleStartTransactionResponse(char *payload, int gun_index)
  12210. {
  12211. mtrace();
  12212. //int transactionIdInt = 0;
  12213. FILE *outfile;
  12214. char data[100]={0};
  12215. DEBUG_INFO("handleStartTransactionResponse...\n");
  12216. json_object *StartTransaction;
  12217. StartTransaction = json_tokener_parse(payload);
  12218. if(!is_error(StartTransaction))
  12219. {
  12220. // Required data
  12221. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12222. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12223. // Optional data
  12224. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12225. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12226. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12227. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12228. }
  12229. json_object_put(StartTransaction);
  12230. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12231. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12232. //-----------Start : write to the Queue TransactionId file -----------------//
  12233. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12234. {}
  12235. else
  12236. {
  12237. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12238. if(log == NULL)
  12239. {
  12240. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12241. return ;
  12242. }
  12243. else
  12244. {
  12245. fclose(log);
  12246. }
  12247. }
  12248. // open file for writing
  12249. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12250. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12251. {
  12252. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12253. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12254. fputs(data, outfile);
  12255. fclose (outfile);
  12256. }
  12257. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12258. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12259. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12260. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12261. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12262. }
  12263. void handleStatusNotificationResponse(char *payload, int gun_index)
  12264. {
  12265. mtrace();
  12266. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12267. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12268. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12269. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12270. }
  12271. void handleStopTransactionnResponse(char *payload, int gun_index)
  12272. {
  12273. mtrace();
  12274. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12275. json_object *StopTransaction;
  12276. StopTransaction = json_tokener_parse(payload);
  12277. if(!is_error(StopTransaction))
  12278. {
  12279. // Optional data
  12280. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12281. {
  12282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12283. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12285. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12287. }
  12288. }
  12289. json_object_put(StopTransaction);
  12290. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12291. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12292. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12293. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12294. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12295. }
  12296. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12297. {
  12298. mtrace();
  12299. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12300. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12301. }
  12302. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12303. {
  12304. mtrace();
  12305. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12306. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12307. }
  12308. void handleSignCertificateResponse(char *payload, int gun_index)
  12309. {
  12310. mtrace();
  12311. DEBUG_INFO("handleSignCertificateResponse...\n");
  12312. json_object *SignCertificate;
  12313. SignCertificate = json_tokener_parse(payload);
  12314. if(!is_error(SignCertificate))
  12315. {
  12316. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12317. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12318. }
  12319. json_object_put(SignCertificate);
  12320. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12321. }
  12322. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12323. {
  12324. mtrace();
  12325. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12326. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12327. }
  12328. //==========================================
  12329. // Handle Error routine
  12330. //==========================================
  12331. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12332. {
  12333. mtrace();
  12334. #ifdef SystemLogMessage
  12335. DEBUG_INFO("errorCode: %s\n", errorCode);
  12336. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12337. DEBUG_INFO("errorDetails: %s\n", payload);
  12338. #endif
  12339. }
  12340. //===============================================
  12341. // Common routine
  12342. //===============================================
  12343. int initialConfigurationTable(void)
  12344. {
  12345. //clock_t start_t, end_t, total_t;
  12346. FILE *fp;
  12347. FILE *outfile;
  12348. char str[512]={0};
  12349. char sstr[256]={0};
  12350. int c = 0;
  12351. char *loc;
  12352. int confVersion = 7;
  12353. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12354. //start_t = clock();
  12355. //printf("Starting of the program, start_t = %ld\n", start_t);
  12356. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12357. // Check configuration file size is correct
  12358. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12359. {
  12360. struct stat st;
  12361. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12362. if(st.st_size < 3100)
  12363. {
  12364. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12365. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12366. }
  12367. }
  12368. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12369. {
  12370. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12371. if(outfile == NULL)
  12372. {
  12373. DEBUG_INFO("Error opening file\n");
  12374. return FALSE;
  12375. }
  12376. /*Core Profile*/
  12377. //AllowOfflineTxForUnknownId
  12378. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12382. //AuthorizationCacheEnabled
  12383. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12387. //AuthorizeRemoteTxRequests
  12388. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12392. //BlinkRepeat
  12393. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12397. //ClockAlignedDataInterval
  12398. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12402. //ConnectionTimeOut
  12403. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12407. //GetConfigurationMaxKeys
  12408. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12412. // HeartbeatInterval
  12413. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12417. // LightIntensity
  12418. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12422. // LocalAuthorizeOffline
  12423. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12427. // LocalPreAuthorize
  12428. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12432. // MaxEnergyOnInvalidId
  12433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12437. // MeterValuesAlignedData
  12438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12441. 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" );
  12442. else
  12443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12445. // MeterValuesAlignedDataMaxLength
  12446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12450. else
  12451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12453. // MeterValuesSampledData
  12454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12457. 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" );
  12458. else
  12459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12461. // MeterValuesSampledDataMaxLength
  12462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12466. else
  12467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12469. // MeterValueSampleInterval
  12470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12474. // MinimumStatusDuration
  12475. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12478. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12480. // NumberOfConnectors
  12481. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12484. {
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12486. }
  12487. else
  12488. {
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12490. }
  12491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12492. // ResetRetries
  12493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12497. // ConnectorPhaseRotation
  12498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12502. // ConnectorPhaseRotationMaxLength
  12503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12507. // StopTransactionOnEVSideDisconnect
  12508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12512. // StopTransactionOnInvalidId
  12513. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12517. // StopTxnAlignedData
  12518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12522. // StopTxnAlignedDataMaxLength
  12523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12527. // StopTxnSampledData
  12528. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12532. else
  12533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12535. // StopTxnSampledDataMaxLength
  12536. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12539. {
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12541. }
  12542. else
  12543. {
  12544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12545. }
  12546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12547. // SupportedFeatureProfiles
  12548. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12552. // SupportedFeatureProfilesMaxLength
  12553. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12557. // TransactionMessageAttempts
  12558. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12561. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12563. // TransactionMessageRetryInterval
  12564. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12567. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12569. // UnlockConnectorOnEVSideDisconnect
  12570. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12574. // WebSocketPingInterval
  12575. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12579. // QueueOffLineStartTransactionMessage
  12580. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12584. // AuthorizationKey
  12585. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12589. // SecurityProfile
  12590. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12594. // DefaultPrice
  12595. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12599. // CustomDisplayCostAndPrice
  12600. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12604. // CustomIdleFeeAfterStop
  12605. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12609. // TimeOffset
  12610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12614. // NextTimeOffsetTransitionDateTime
  12615. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12619. // TimeOffsetNextTransition
  12620. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12624. // Configuration Version
  12625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12629. //* Local Auth List Management Profile*/
  12630. #if 0
  12631. //For OCTT Test Case
  12632. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12635. #endif
  12636. #if 1
  12637. //LocalAuthListEnabled
  12638. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12642. #endif
  12643. //LocalAuthListMaxLength
  12644. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12648. //SendLocalListMaxLength
  12649. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12653. //ReserveConnectorZeroSupported
  12654. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12658. //* Smart Charging Profile */
  12659. //ChargeProfileMaxStackLevel
  12660. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12664. // ChargingScheduleAllowedChargingRateUnit
  12665. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12669. // ChargingScheduleMaxPeriods
  12670. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12674. // ConnectorSwitch3to1PhaseSupported
  12675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12679. // MaxChargingProfilesInstalled
  12680. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12684. fclose(outfile);
  12685. }
  12686. else
  12687. {
  12688. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12689. char keystr[60]={0};
  12690. char readonlystr[10]={0};
  12691. char valuestr[256]={0};
  12692. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12693. if(fp == NULL) {
  12694. DEBUG_INFO("Error opening file");
  12695. return FALSE;
  12696. }
  12697. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12698. {
  12699. //DEBUG_INFO("Get Configuration \n");
  12700. if(strlen(str) > 0)
  12701. {
  12702. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12703. //*************************key*********************************/
  12704. if(strstr(str, "key") != NULL)
  12705. {
  12706. loc = strstr(str, "key");
  12707. c = 0;
  12708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12709. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12710. {
  12711. sstr[c] = loc[strlen("key")+3+c];
  12712. c++;
  12713. }
  12714. sstr[c] = '\0';
  12715. strcpy(keystr,sstr);
  12716. }
  12717. //*************************readonly*********************************/
  12718. if(strstr(str, "readonly") != NULL)
  12719. {
  12720. loc = strstr(str, "readonly");
  12721. c = 0;
  12722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12723. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12724. {
  12725. sstr[c] = loc[strlen("readonly")+2+c];
  12726. c++;
  12727. }
  12728. sstr[c] = '\0';
  12729. strcpy(readonlystr,sstr);
  12730. }
  12731. //*************************value*********************************/
  12732. if(strstr(str, "value") != NULL)
  12733. {
  12734. loc = strstr(str, "value");
  12735. c = 0;
  12736. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12737. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12738. {
  12739. sstr[c] = loc[strlen("value")+3+c];
  12740. c++;
  12741. }
  12742. sstr[c] = '\0';
  12743. strcpy(valuestr,sstr);
  12744. }
  12745. // DEBUG_INFO("keystr=%s\n",keystr);
  12746. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12747. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12748. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12749. {
  12750. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12751. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12753. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12754. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12755. }
  12756. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12757. {
  12758. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12759. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12761. }
  12762. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12763. {
  12764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12766. }
  12767. if(strcmp(keystr, "BlinkRepeat") == 0)
  12768. {
  12769. //Charger.BlinkRepeat = Integer.parseInt(value);
  12770. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12772. }
  12773. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12774. {
  12775. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12777. }
  12778. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12779. {
  12780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12782. }
  12783. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12784. {
  12785. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12787. }
  12788. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12789. {
  12790. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12792. HeartBeatWaitTime = atoi(valuestr);
  12793. }
  12794. if(strcmp(keystr, "LightIntensity") == 0)
  12795. {
  12796. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12798. }
  12799. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12800. {
  12801. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12803. }
  12804. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12805. {
  12806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12808. }
  12809. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12810. {
  12811. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12813. }
  12814. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12815. {
  12816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12818. }
  12819. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12820. {
  12821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12823. }
  12824. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12825. {
  12826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12828. }
  12829. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12830. {
  12831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12833. }
  12834. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12835. {
  12836. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12838. }
  12839. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12840. {
  12841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12843. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12844. }
  12845. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12846. {
  12847. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12849. }
  12850. if(strcmp(keystr, "ResetRetries") == 0)
  12851. {
  12852. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12854. }
  12855. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12856. {
  12857. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12859. }
  12860. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12861. {
  12862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12864. }
  12865. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12866. {
  12867. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12869. }
  12870. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12871. {
  12872. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12874. }
  12875. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12876. {
  12877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12879. }
  12880. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12881. {
  12882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12884. }
  12885. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12886. {
  12887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12889. }
  12890. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12891. {
  12892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12894. }
  12895. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12896. {
  12897. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12899. }
  12900. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12901. {
  12902. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12904. }
  12905. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12906. {
  12907. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12909. TransactionMessageAttemptsValue = atoi(valuestr);
  12910. }
  12911. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12912. {
  12913. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12915. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12916. }
  12917. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12918. {
  12919. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12921. }
  12922. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12923. {
  12924. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12926. }
  12927. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12928. {
  12929. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12931. }
  12932. if(strcmp(keystr, "AuthorizationKey") == 0)
  12933. {
  12934. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12935. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12937. }
  12938. if(strcmp(keystr, "SecurityProfile") == 0)
  12939. {
  12940. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12942. }
  12943. if(strcmp(keystr, "DefaultPrice") == 0)
  12944. {
  12945. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12947. }
  12948. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12949. {
  12950. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12952. }
  12953. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12954. {
  12955. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12957. }
  12958. if(strcmp(keystr, "TimeOffset") == 0)
  12959. {
  12960. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12962. }
  12963. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12964. {
  12965. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12967. }
  12968. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12969. {
  12970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12972. }
  12973. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12974. {
  12975. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12977. }
  12978. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12979. {
  12980. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12982. }
  12983. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12984. {
  12985. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12987. }
  12988. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12989. {
  12990. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12992. }
  12993. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12994. {
  12995. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12997. }
  12998. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12999. {
  13000. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13002. }
  13003. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13004. {
  13005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13007. }
  13008. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13009. {
  13010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13012. }
  13013. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13014. {
  13015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13017. }
  13018. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13019. {
  13020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13022. }
  13023. }
  13024. }
  13025. fclose(fp);
  13026. }
  13027. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13028. {
  13029. return PASS;
  13030. }
  13031. else
  13032. {
  13033. return FAIL;
  13034. }
  13035. }
  13036. void StoreConfigurationTable(void)
  13037. {
  13038. FILE *outfile;
  13039. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13040. if(outfile == NULL)
  13041. {
  13042. DEBUG_INFO("Error opening file");
  13043. return ;
  13044. }
  13045. /*Core Profile*/
  13046. //AllowOfflineTxForUnknownId
  13047. /*
  13048. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13049. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13052. */
  13053. //DEBUG_INFO("data=%s\n",data);
  13054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13055. //AuthorizationCacheEnabled
  13056. /*
  13057. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13060. */
  13061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13062. //AuthorizeRemoteTxRequests
  13063. /*
  13064. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13067. */
  13068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13069. //BlinkRepeat
  13070. /*
  13071. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13074. */
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13076. //ClockAlignedDataInterval
  13077. /*
  13078. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13081. */
  13082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13083. //ConnectionTimeOut
  13084. /*
  13085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13088. */
  13089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13090. //GetConfigurationMaxKeys
  13091. /*
  13092. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13095. */
  13096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13097. // HeartbeatInterval
  13098. /*
  13099. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13102. */
  13103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13104. // LightIntensity
  13105. /*
  13106. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13109. */
  13110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13111. // LocalAuthorizeOffline
  13112. /*
  13113. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13116. */
  13117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13118. // LocalPreAuthorize
  13119. /*
  13120. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13123. */
  13124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13125. // MaxEnergyOnInvalidId
  13126. /*
  13127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13130. */
  13131. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13133. // MeterValuesAlignedData
  13134. /*
  13135. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13138. */
  13139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13140. // MeterValuesAlignedDataMaxLength
  13141. /*
  13142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13145. */
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13147. // MeterValuesSampledData
  13148. /*
  13149. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13152. */
  13153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13154. // MeterValuesSampledDataMaxLength
  13155. /*
  13156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13159. */
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13161. // MeterValueSampleInterval
  13162. /*
  13163. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13166. */
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13168. // MinimumStatusDuration
  13169. /*
  13170. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13173. */
  13174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13175. // NumberOfConnectors
  13176. /*
  13177. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13180. {
  13181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13182. }
  13183. else
  13184. {
  13185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13186. }
  13187. */
  13188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13189. // ResetRetries
  13190. /*
  13191. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13194. */
  13195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13196. // ConnectorPhaseRotation
  13197. /*
  13198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13201. */
  13202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13203. // ConnectorPhaseRotationMaxLength
  13204. /*
  13205. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13208. */
  13209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13210. // StopTransactionOnEVSideDisconnect
  13211. /*
  13212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13215. */
  13216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13217. // StopTransactionOnInvalidId
  13218. /*
  13219. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13222. */
  13223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13224. // StopTxnAlignedData
  13225. /*
  13226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13229. */
  13230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13231. // StopTxnAlignedDataMaxLength
  13232. /*
  13233. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13236. */
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13238. // StopTxnSampledData
  13239. /*
  13240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13243. */
  13244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13245. // StopTxnSampledDataMaxLength
  13246. /*
  13247. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13250. */
  13251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13252. // SupportedFeatureProfiles
  13253. /*
  13254. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13257. */
  13258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13259. // SupportedFeatureProfilesMaxLength
  13260. /*
  13261. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13264. */
  13265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13266. // TransactionMessageAttempts
  13267. /*
  13268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13271. */
  13272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13273. // TransactionMessageRetryInterval
  13274. /*
  13275. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13278. */
  13279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13280. // UnlockConnectorOnEVSideDisconnect
  13281. /*
  13282. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13285. */
  13286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13287. // WebSocketPingInterval
  13288. /*
  13289. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13292. */
  13293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13294. // QueueOffLineStartTransactionMessage
  13295. /*
  13296. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13299. */
  13300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13301. // AuthorizationKey
  13302. /*
  13303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13306. */
  13307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13308. // SecurityProfile
  13309. /*
  13310. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13313. */
  13314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13315. // DefaultPrice
  13316. /*
  13317. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13320. */
  13321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13322. // CustomDisplayCostAndPrice
  13323. /*
  13324. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13327. */
  13328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13329. // CustomIdleFeeAfterStop
  13330. /*
  13331. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13334. */
  13335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13336. // TimeOffset
  13337. /*
  13338. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13341. */
  13342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13343. // NextTimeOffsetTransitionDateTime
  13344. /*
  13345. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13348. */
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13350. // TimeOffsetNextTransition
  13351. /*
  13352. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13355. */
  13356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13357. // ConfigurationVersion
  13358. /*
  13359. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13362. */
  13363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13364. //* Local Auth List Management Profile*/
  13365. //LocalAuthListEnabled
  13366. /*
  13367. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13370. */
  13371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13372. //LocalAuthListMaxLength
  13373. /*
  13374. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13377. */
  13378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13379. //SendLocalListMaxLength
  13380. /*
  13381. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13384. */
  13385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13386. //ReserveConnectorZeroSupported
  13387. /*
  13388. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13391. */
  13392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13393. //* Smart Charging Profile */
  13394. //ChargeProfileMaxStackLevel
  13395. /*
  13396. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13399. */
  13400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13401. // ChargingScheduleAllowedChargingRateUnit
  13402. /*
  13403. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13406. */
  13407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13408. // ChargingScheduleMaxPeriods
  13409. /*
  13410. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13413. */
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13415. // ConnectorSwitch3to1PhaseSupported
  13416. /*
  13417. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13420. */
  13421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13422. // MaxChargingProfilesInstalled
  13423. /*
  13424. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13427. */
  13428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13429. fclose(outfile);
  13430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13431. }
  13432. void getKeyValue(char *keyReq)
  13433. {
  13434. int isEmpty = FALSE;
  13435. int isKnowKey = FALSE;
  13436. DEBUG_INFO("keyReq = %s\n", keyReq);
  13437. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13438. isEmpty = TRUE;
  13439. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13440. {
  13441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13444. {
  13445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13446. }
  13447. else
  13448. {
  13449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13450. }
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13452. isKnowKey = TRUE;
  13453. }
  13454. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13455. {
  13456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13459. {
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13461. }
  13462. else
  13463. {
  13464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13465. }
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13467. isKnowKey = TRUE;
  13468. }
  13469. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13470. {
  13471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13474. {
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13476. }
  13477. else
  13478. {
  13479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13480. }
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13482. isKnowKey = TRUE;
  13483. }
  13484. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13485. {
  13486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13489. {
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13491. }
  13492. else
  13493. {
  13494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13495. }
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13497. isKnowKey = TRUE;
  13498. }
  13499. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13500. {
  13501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13504. {
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13506. }
  13507. else
  13508. {
  13509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13510. }
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13512. isKnowKey = TRUE;
  13513. }
  13514. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13515. {
  13516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13519. {
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13521. }
  13522. else
  13523. {
  13524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13525. }
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13527. isKnowKey = TRUE;
  13528. }
  13529. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13530. {
  13531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13534. {
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13536. }
  13537. else
  13538. {
  13539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13540. }
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13542. isKnowKey = TRUE;
  13543. }
  13544. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13545. {
  13546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13549. {
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13551. }
  13552. else
  13553. {
  13554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13555. }
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13557. isKnowKey = TRUE;
  13558. }
  13559. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13560. {
  13561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13564. {
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13566. }
  13567. else
  13568. {
  13569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13570. }
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13572. isKnowKey = TRUE;
  13573. }
  13574. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13575. {
  13576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13579. {
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13581. }
  13582. else
  13583. {
  13584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13585. }
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13587. isKnowKey = TRUE;
  13588. }
  13589. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13590. {
  13591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13594. {
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13596. }
  13597. else
  13598. {
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13600. }
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13602. isKnowKey = TRUE;
  13603. }
  13604. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13605. {
  13606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13609. {
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13611. }
  13612. else
  13613. {
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13615. }
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13617. isKnowKey = TRUE;
  13618. }
  13619. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13620. {
  13621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13624. {
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13626. }
  13627. else
  13628. {
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13630. }
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13632. isKnowKey = TRUE;
  13633. }
  13634. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13635. {
  13636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13639. {
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13641. }
  13642. else
  13643. {
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13645. }
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13647. isKnowKey = TRUE;
  13648. }
  13649. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13650. {
  13651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13654. {
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13656. }
  13657. else
  13658. {
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13660. }
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13662. isKnowKey = TRUE;
  13663. }
  13664. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13665. {
  13666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13669. {
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13671. }
  13672. else
  13673. {
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13675. }
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13677. isKnowKey = TRUE;
  13678. }
  13679. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13680. {
  13681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13684. {
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13686. }
  13687. else
  13688. {
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13690. }
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13692. isKnowKey = TRUE;
  13693. }
  13694. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13695. {
  13696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13699. {
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13701. }
  13702. else
  13703. {
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13705. }
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13707. isKnowKey = TRUE;
  13708. }
  13709. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13710. {
  13711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13714. {
  13715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13716. }
  13717. else
  13718. {
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13720. }
  13721. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13723. isKnowKey = TRUE;
  13724. }
  13725. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13726. {
  13727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13730. {
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13732. }
  13733. else
  13734. {
  13735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13736. }
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13738. isKnowKey = TRUE;
  13739. }
  13740. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13741. {
  13742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13745. {
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13747. }
  13748. else
  13749. {
  13750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13751. }
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13753. isKnowKey = TRUE;
  13754. }
  13755. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13756. {
  13757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13760. {
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13762. }
  13763. else
  13764. {
  13765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13766. }
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13768. isKnowKey = TRUE;
  13769. }
  13770. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13771. {
  13772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13775. {
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13777. }
  13778. else
  13779. {
  13780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13781. }
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13783. isKnowKey = TRUE;
  13784. }
  13785. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13786. {
  13787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13790. {
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13792. }
  13793. else
  13794. {
  13795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13796. }
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13798. isKnowKey = TRUE;
  13799. }
  13800. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13801. {
  13802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13805. {
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13807. }
  13808. else
  13809. {
  13810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13811. }
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13813. isKnowKey = TRUE;
  13814. }
  13815. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13816. {
  13817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13820. {
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13822. }
  13823. else
  13824. {
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13826. }
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13828. isKnowKey = TRUE;
  13829. }
  13830. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13831. {
  13832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13835. {
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13837. }
  13838. else
  13839. {
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13841. }
  13842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13843. isKnowKey = TRUE;
  13844. }
  13845. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13850. {
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13852. }
  13853. else
  13854. {
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13856. }
  13857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13858. isKnowKey = TRUE;
  13859. }
  13860. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13865. {
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13867. }
  13868. else
  13869. {
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13871. }
  13872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13873. isKnowKey = TRUE;
  13874. }
  13875. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13876. {
  13877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13880. {
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13882. }
  13883. else
  13884. {
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13886. }
  13887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13888. isKnowKey = TRUE;
  13889. }
  13890. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13891. {
  13892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13895. {
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13897. }
  13898. else
  13899. {
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13901. }
  13902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13903. isKnowKey = TRUE;
  13904. }
  13905. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13906. {
  13907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13910. {
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13912. }
  13913. else
  13914. {
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13916. }
  13917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13918. isKnowKey = TRUE;
  13919. }
  13920. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13921. {
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13925. {
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13927. }
  13928. else
  13929. {
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13931. }
  13932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13933. isKnowKey = TRUE;
  13934. }
  13935. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13936. {
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13940. {
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13942. }
  13943. else
  13944. {
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13946. }
  13947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13948. isKnowKey = TRUE;
  13949. }
  13950. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13951. {
  13952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13955. {
  13956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13957. }
  13958. else
  13959. {
  13960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13961. }
  13962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13963. isKnowKey = TRUE;
  13964. }
  13965. /*
  13966. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13967. {
  13968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13971. {
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13973. }
  13974. else
  13975. {
  13976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13977. }
  13978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13979. isKnowKey = TRUE;
  13980. }*/
  13981. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13982. {
  13983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13986. {
  13987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13988. }
  13989. else
  13990. {
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13992. }
  13993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13994. isKnowKey = TRUE;
  13995. }
  13996. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13997. {
  13998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14001. {
  14002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14003. }
  14004. else
  14005. {
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14007. }
  14008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14009. isKnowKey = TRUE;
  14010. }
  14011. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14012. {
  14013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14016. {
  14017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14018. }
  14019. else
  14020. {
  14021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14022. }
  14023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14024. isKnowKey = TRUE;
  14025. }
  14026. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14027. {
  14028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14031. {
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14033. }
  14034. else
  14035. {
  14036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14037. }
  14038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14039. isKnowKey = TRUE;
  14040. }
  14041. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14042. {
  14043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14046. {
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14048. }
  14049. else
  14050. {
  14051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14052. }
  14053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14054. isKnowKey = TRUE;
  14055. }
  14056. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14057. {
  14058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14061. {
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14063. }
  14064. else
  14065. {
  14066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14067. }
  14068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14069. isKnowKey = TRUE;
  14070. }
  14071. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14072. {
  14073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14076. {
  14077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14078. }
  14079. else
  14080. {
  14081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14082. }
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14084. isKnowKey = TRUE;
  14085. }
  14086. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14087. {
  14088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14091. {
  14092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14093. }
  14094. else
  14095. {
  14096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14097. }
  14098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14099. isKnowKey = TRUE;
  14100. }
  14101. #if 1
  14102. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14103. {
  14104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14106. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14107. {
  14108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14109. }
  14110. else
  14111. {
  14112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14113. }
  14114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14115. isKnowKey = TRUE;
  14116. }
  14117. #endif
  14118. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14119. {
  14120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14123. {
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14125. }
  14126. else
  14127. {
  14128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14129. }
  14130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14131. isKnowKey = TRUE;
  14132. }
  14133. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14134. {
  14135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14138. {
  14139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14140. }
  14141. else
  14142. {
  14143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14144. }
  14145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14146. isKnowKey = TRUE;
  14147. }
  14148. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14149. {
  14150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14152. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14153. {
  14154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14155. }
  14156. else
  14157. {
  14158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14159. }
  14160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14161. isKnowKey = TRUE;
  14162. }
  14163. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14164. {
  14165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14167. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14168. {
  14169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14170. }
  14171. else
  14172. {
  14173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14174. }
  14175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14176. isKnowKey = TRUE;
  14177. }
  14178. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14179. {
  14180. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14182. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14183. {
  14184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14185. }
  14186. else
  14187. {
  14188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14189. }
  14190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14191. isKnowKey = TRUE;
  14192. }
  14193. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14194. {
  14195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14197. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14198. {
  14199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14200. }
  14201. else
  14202. {
  14203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14204. }
  14205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14206. isKnowKey = TRUE;
  14207. }
  14208. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14209. {
  14210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14212. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14213. {
  14214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14215. }
  14216. else
  14217. {
  14218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14219. }
  14220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14221. isKnowKey = TRUE;
  14222. }
  14223. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14224. {
  14225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14228. {
  14229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14230. }
  14231. else
  14232. {
  14233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14234. }
  14235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14236. isKnowKey = TRUE;
  14237. }
  14238. //=========================================================
  14239. if(!isEmpty && !isKnowKey)
  14240. {
  14241. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14242. strcpy(unknownkey[UnknownKeynum], keyReq);
  14243. UnknownKeynum = UnknownKeynum + 1;
  14244. }
  14245. }
  14246. void processUnkownKey(void)
  14247. {
  14248. DEBUG_INFO("processUnkownKey...\n");
  14249. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14250. for(int index=0; index < UnknownKeynum; index++)
  14251. {
  14252. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14253. {
  14254. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14255. }
  14256. }
  14257. }
  14258. int setKeyValue(char *key, char *value)
  14259. {
  14260. int isSuccess = NotSupported;
  14261. int check_ascii=0;
  14262. char str[256]={0};
  14263. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14264. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14265. {
  14266. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14268. {
  14269. strcpy(str, (const char*)value);
  14270. for(int i = 0; str[i]; i++){
  14271. str[i] = tolower(str[i]);
  14272. }
  14273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14274. isSuccess = ConfigurationStatus_Accepted;
  14275. }
  14276. else
  14277. {
  14278. isSuccess = ConfigurationStatus_Rejected;
  14279. }
  14280. }
  14281. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14282. {
  14283. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14285. {
  14286. strcpy(str, (const char*)value);
  14287. for(int i = 0; str[i]; i++){
  14288. str[i] = tolower(str[i]);
  14289. }
  14290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14291. isSuccess = ConfigurationStatus_Accepted;
  14292. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14293. }
  14294. else
  14295. {
  14296. isSuccess = ConfigurationStatus_Rejected;
  14297. }
  14298. }
  14299. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14300. {
  14301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14302. {
  14303. strcpy(str, (const char*)value);
  14304. for(int i = 0; str[i]; i++)
  14305. {
  14306. str[i] = tolower(str[i]);
  14307. }
  14308. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14310. isSuccess = ConfigurationStatus_Accepted;
  14311. }
  14312. else
  14313. {
  14314. isSuccess = ConfigurationStatus_Rejected;
  14315. }
  14316. }
  14317. if(strcmp(key, "BlinkRepeat") == 0)
  14318. {
  14319. //Charger.BlinkRepeat = Integer.parseInt(value);
  14320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14321. {
  14322. check_ascii = value[0];
  14323. if( (check_ascii < 48) || (check_ascii > 57) )
  14324. {
  14325. isSuccess = ConfigurationStatus_Rejected;
  14326. }
  14327. else
  14328. {
  14329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14330. isSuccess = ConfigurationStatus_Accepted;
  14331. }
  14332. }
  14333. else
  14334. {
  14335. isSuccess = ConfigurationStatus_Rejected;
  14336. }
  14337. }
  14338. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14339. {
  14340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14341. {
  14342. check_ascii = value[0];
  14343. if( (check_ascii < 48) || (check_ascii > 57) )
  14344. {
  14345. isSuccess = ConfigurationStatus_Rejected;
  14346. }
  14347. else
  14348. {
  14349. if((atoi(value) == 0) || (atoi(value) >= 10))
  14350. {
  14351. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14353. isSuccess = ConfigurationStatus_Accepted;
  14354. }
  14355. else
  14356. isSuccess = ConfigurationStatus_Rejected;
  14357. }
  14358. }
  14359. else
  14360. {
  14361. isSuccess = ConfigurationStatus_Rejected;
  14362. }
  14363. }
  14364. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14365. {
  14366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14367. {
  14368. check_ascii = value[0];
  14369. if( (check_ascii < 48) || (check_ascii > 57) )
  14370. {
  14371. isSuccess = ConfigurationStatus_Rejected;
  14372. }
  14373. else
  14374. {
  14375. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14377. isSuccess = ConfigurationStatus_Accepted;
  14378. }
  14379. }
  14380. else
  14381. {
  14382. isSuccess = ConfigurationStatus_Rejected;
  14383. }
  14384. }
  14385. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14386. {
  14387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14388. {
  14389. check_ascii = value[0];
  14390. if( (check_ascii < 48) || (check_ascii > 57) )
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. else
  14395. {
  14396. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14398. isSuccess = ConfigurationStatus_Accepted;
  14399. }
  14400. }
  14401. else
  14402. {
  14403. isSuccess = ConfigurationStatus_Rejected;
  14404. }
  14405. }
  14406. if(strcmp(key, "HeartbeatInterval") == 0)
  14407. {
  14408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14409. {
  14410. check_ascii = value[0];
  14411. if( (check_ascii < 48) || (check_ascii > 57) )
  14412. {
  14413. isSuccess = ConfigurationStatus_Rejected;
  14414. }
  14415. else
  14416. {
  14417. if((atoi(value) == 0) || (atoi(value) >= 10))
  14418. {
  14419. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14421. HeartBeatWaitTime = atoi(value);
  14422. isSuccess = ConfigurationStatus_Accepted;
  14423. }
  14424. else
  14425. {
  14426. isSuccess = ConfigurationStatus_Rejected;
  14427. }
  14428. }
  14429. }
  14430. else
  14431. {
  14432. isSuccess = ConfigurationStatus_Rejected;
  14433. }
  14434. }
  14435. if(strcmp(key, "LightIntensity") == 0)
  14436. {
  14437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14438. {
  14439. check_ascii = value[0];
  14440. if( (check_ascii < 48) || (check_ascii > 57) )
  14441. {
  14442. isSuccess = ConfigurationStatus_Rejected;
  14443. }
  14444. else
  14445. {
  14446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14447. isSuccess = ConfigurationStatus_Accepted;
  14448. }
  14449. }
  14450. else
  14451. {
  14452. isSuccess = ConfigurationStatus_Rejected;
  14453. }
  14454. }
  14455. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14456. {
  14457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14458. {
  14459. strcpy(str, (const char*)value);
  14460. for(int i = 0; str[i]; i++)
  14461. {
  14462. str[i] = tolower(str[i]);
  14463. }
  14464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14465. isSuccess = ConfigurationStatus_Accepted;
  14466. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14467. }
  14468. else
  14469. {
  14470. isSuccess = ConfigurationStatus_Rejected;
  14471. }
  14472. }
  14473. if(strcmp(key, "LocalPreAuthorize") == 0)
  14474. {
  14475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14476. {
  14477. strcpy(str, (const char*)value);
  14478. for(int i = 0; str[i]; i++)
  14479. {
  14480. str[i] = tolower(str[i]);
  14481. }
  14482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14483. isSuccess = ConfigurationStatus_Accepted;
  14484. }
  14485. else
  14486. {
  14487. isSuccess = ConfigurationStatus_Rejected;
  14488. }
  14489. }
  14490. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14491. {
  14492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14493. {
  14494. check_ascii = value[0];
  14495. if( (check_ascii < 48) || (check_ascii > 57) )
  14496. {
  14497. isSuccess = ConfigurationStatus_Rejected;
  14498. }
  14499. else
  14500. {
  14501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14502. isSuccess = ConfigurationStatus_Accepted;
  14503. }
  14504. }
  14505. else
  14506. {
  14507. isSuccess = ConfigurationStatus_Rejected;
  14508. }
  14509. }
  14510. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14511. {
  14512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14513. {
  14514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14515. isSuccess = ConfigurationStatus_Accepted;
  14516. }
  14517. else
  14518. {
  14519. isSuccess = ConfigurationStatus_Rejected;
  14520. }
  14521. }
  14522. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14523. {
  14524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14525. {
  14526. check_ascii = value[0];
  14527. if( (check_ascii < 48) || (check_ascii > 57) )
  14528. {
  14529. isSuccess = ConfigurationStatus_Rejected;
  14530. }
  14531. else
  14532. {
  14533. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14535. isSuccess = ConfigurationStatus_Accepted;
  14536. }
  14537. }
  14538. else
  14539. {
  14540. isSuccess = ConfigurationStatus_Rejected;
  14541. }
  14542. }
  14543. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14544. {
  14545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14546. {
  14547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14548. isSuccess = ConfigurationStatus_Accepted;
  14549. }
  14550. else
  14551. {
  14552. isSuccess = ConfigurationStatus_Rejected;
  14553. }
  14554. }
  14555. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14556. {
  14557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14558. {
  14559. check_ascii = value[0];
  14560. if( (check_ascii < 48) || (check_ascii > 57) )
  14561. {
  14562. isSuccess = ConfigurationStatus_Rejected;
  14563. }
  14564. else
  14565. {
  14566. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14568. isSuccess = ConfigurationStatus_Accepted;
  14569. }
  14570. }
  14571. else
  14572. {
  14573. isSuccess = ConfigurationStatus_Rejected;
  14574. }
  14575. }
  14576. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14577. {
  14578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14579. {
  14580. check_ascii = value[0];
  14581. if( (check_ascii < 48) || (check_ascii > 57) )
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. else
  14586. {
  14587. if((atoi(value) == 0) || (atoi(value) >= 10))
  14588. {
  14589. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14591. isSuccess = ConfigurationStatus_Accepted;
  14592. }
  14593. else
  14594. {
  14595. isSuccess = ConfigurationStatus_Rejected;
  14596. }
  14597. }
  14598. }
  14599. else
  14600. {
  14601. isSuccess = ConfigurationStatus_Rejected;
  14602. }
  14603. }
  14604. if(strcmp(key, "MinimumStatusDuration") == 0)
  14605. {
  14606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14607. {
  14608. check_ascii = value[0];
  14609. if( (check_ascii < 48) || (check_ascii > 57) )
  14610. {
  14611. isSuccess = ConfigurationStatus_Rejected;
  14612. }
  14613. else
  14614. {
  14615. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14616. {
  14617. isSuccess = ConfigurationStatus_Rejected;
  14618. }
  14619. else
  14620. {
  14621. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14623. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14624. isSuccess = ConfigurationStatus_Accepted;
  14625. }
  14626. }
  14627. }
  14628. else
  14629. {
  14630. isSuccess = ConfigurationStatus_Rejected;
  14631. }
  14632. }
  14633. if(strcmp(key, "NumberOfConnectors") == 0)
  14634. {
  14635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14636. {
  14637. check_ascii = value[0];
  14638. if( (check_ascii < 48) || (check_ascii > 57) )
  14639. {
  14640. isSuccess = ConfigurationStatus_Rejected;
  14641. }
  14642. else
  14643. {
  14644. //Charger.ResetRetries = Integer.parseInt(value);
  14645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14646. isSuccess = ConfigurationStatus_Accepted;
  14647. }
  14648. }
  14649. else
  14650. {
  14651. isSuccess = ConfigurationStatus_Rejected;
  14652. }
  14653. }
  14654. if(strcmp(key, "ResetRetries") == 0)
  14655. {
  14656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14657. {
  14658. check_ascii = value[0];
  14659. if( (check_ascii < 48) || (check_ascii > 57) )
  14660. {
  14661. isSuccess = ConfigurationStatus_Rejected;
  14662. }
  14663. else
  14664. {
  14665. //Charger.ResetRetries = Integer.parseInt(value);
  14666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14667. isSuccess = ConfigurationStatus_Accepted;
  14668. }
  14669. }
  14670. else
  14671. {
  14672. isSuccess = ConfigurationStatus_Rejected;
  14673. }
  14674. }
  14675. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14676. {
  14677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14678. {
  14679. strcpy(str, (const char*)value);
  14680. for(int i = 0; str[i]; i++)
  14681. {
  14682. str[i] = tolower(str[i]);
  14683. }
  14684. if(strcmp(str, "notapplicable")== 0)
  14685. {
  14686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14687. isSuccess = ConfigurationStatus_Accepted;
  14688. }
  14689. else if(strcmp(str, "unknown")== 0)
  14690. {
  14691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14692. isSuccess = ConfigurationStatus_Accepted;
  14693. }
  14694. else if(strcmp(str, "rst")== 0)
  14695. {
  14696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14697. isSuccess = ConfigurationStatus_Accepted;
  14698. }
  14699. else if(strcmp(str, "rts")== 0)
  14700. {
  14701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14702. isSuccess = ConfigurationStatus_Accepted;
  14703. }
  14704. else if(strcmp(str, "srt")== 0)
  14705. {
  14706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14707. isSuccess = ConfigurationStatus_Accepted;
  14708. }
  14709. else if(strcmp(str, "str")== 0)
  14710. {
  14711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14712. isSuccess = ConfigurationStatus_Accepted;
  14713. }
  14714. else if(strcmp(str, "trs")== 0)
  14715. {
  14716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14717. isSuccess = ConfigurationStatus_Accepted;
  14718. }
  14719. else if(strcmp(str, "tsr")== 0)
  14720. {
  14721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14722. isSuccess = ConfigurationStatus_Accepted;
  14723. }
  14724. else
  14725. {
  14726. isSuccess = ConfigurationStatus_Rejected;
  14727. }
  14728. }
  14729. else
  14730. {
  14731. isSuccess = ConfigurationStatus_Rejected;
  14732. }
  14733. }
  14734. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14735. {
  14736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14737. {
  14738. check_ascii = value[0];
  14739. if( (check_ascii < 48) || (check_ascii > 57) )
  14740. {
  14741. isSuccess = ConfigurationStatus_Rejected;
  14742. }
  14743. else
  14744. {
  14745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14746. isSuccess = ConfigurationStatus_Accepted;
  14747. }
  14748. }
  14749. else
  14750. {
  14751. isSuccess = ConfigurationStatus_Rejected;
  14752. }
  14753. }
  14754. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14755. {
  14756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14757. {
  14758. strcpy(str, (const char*)value);
  14759. for(int i = 0; str[i]; i++)
  14760. {
  14761. str[i] = tolower(str[i]);
  14762. }
  14763. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14765. isSuccess = ConfigurationStatus_Accepted;
  14766. }
  14767. else
  14768. {
  14769. isSuccess = ConfigurationStatus_Rejected;
  14770. }
  14771. }
  14772. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14773. {
  14774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14775. {
  14776. strcpy(str, (const char*)value);
  14777. for(int i = 0; str[i]; i++)
  14778. {
  14779. str[i] = tolower(str[i]);
  14780. }
  14781. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14783. isSuccess = ConfigurationStatus_Accepted;
  14784. }
  14785. else
  14786. {
  14787. isSuccess = ConfigurationStatus_Rejected;
  14788. }
  14789. }
  14790. if(strcmp(key, "StopTxnAlignedData") == 0)
  14791. {
  14792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14793. {
  14794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14795. isSuccess = ConfigurationStatus_Accepted;
  14796. }
  14797. else
  14798. {
  14799. isSuccess = ConfigurationStatus_Rejected;
  14800. }
  14801. }
  14802. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14803. {
  14804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14805. {
  14806. check_ascii = value[0];
  14807. if( (check_ascii < 48) || (check_ascii > 57) )
  14808. {
  14809. isSuccess = ConfigurationStatus_Rejected;
  14810. }
  14811. else
  14812. {
  14813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14814. isSuccess = ConfigurationStatus_Accepted;
  14815. }
  14816. }
  14817. else
  14818. {
  14819. isSuccess = ConfigurationStatus_Rejected;
  14820. }
  14821. }
  14822. if(strcmp(key, "StopTxnSampledData") == 0)
  14823. {
  14824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14825. {
  14826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14827. isSuccess = ConfigurationStatus_Accepted;
  14828. }
  14829. else
  14830. {
  14831. isSuccess = ConfigurationStatus_Rejected;
  14832. }
  14833. }
  14834. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14835. {
  14836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14837. {
  14838. check_ascii = value[0];
  14839. if( (check_ascii < 48) || (check_ascii > 57) )
  14840. {
  14841. isSuccess = ConfigurationStatus_Rejected;
  14842. }
  14843. else
  14844. {
  14845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14846. isSuccess = ConfigurationStatus_Accepted;
  14847. }
  14848. }
  14849. else
  14850. {
  14851. isSuccess = ConfigurationStatus_Rejected;
  14852. }
  14853. }
  14854. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14855. {
  14856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14857. {
  14858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14859. isSuccess = ConfigurationStatus_Accepted;
  14860. }
  14861. else
  14862. {
  14863. isSuccess = ConfigurationStatus_Rejected;
  14864. }
  14865. }
  14866. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14867. {
  14868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14869. {
  14870. check_ascii = value[0];
  14871. if( (check_ascii < 48) || (check_ascii > 57) )
  14872. {
  14873. isSuccess = ConfigurationStatus_Rejected;
  14874. }
  14875. else
  14876. {
  14877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14878. isSuccess = ConfigurationStatus_Accepted;
  14879. }
  14880. }
  14881. else
  14882. {
  14883. isSuccess = ConfigurationStatus_Rejected;
  14884. }
  14885. }
  14886. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14887. {
  14888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14889. {
  14890. check_ascii = value[0];
  14891. if( (check_ascii < 48) || (check_ascii > 57) )
  14892. {
  14893. isSuccess = ConfigurationStatus_Rejected;
  14894. }
  14895. else
  14896. {
  14897. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14899. TransactionMessageAttemptsValue = atoi(value);
  14900. isSuccess = ConfigurationStatus_Accepted;
  14901. }
  14902. }
  14903. else
  14904. {
  14905. isSuccess = ConfigurationStatus_Rejected;
  14906. }
  14907. }
  14908. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14909. {
  14910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14911. {
  14912. check_ascii = value[0];
  14913. if( (check_ascii < 48) || (check_ascii > 57) )
  14914. {
  14915. isSuccess = ConfigurationStatus_Rejected;
  14916. }
  14917. else
  14918. {
  14919. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14921. TransactionMessageRetryIntervalValue = atoi(value);
  14922. isSuccess = ConfigurationStatus_Accepted;
  14923. }
  14924. }
  14925. else
  14926. {
  14927. isSuccess = ConfigurationStatus_Rejected;
  14928. }
  14929. }
  14930. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14931. {
  14932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14933. {
  14934. strcpy(str, (const char*)value);
  14935. for(int i = 0; str[i]; i++)
  14936. {
  14937. str[i] = tolower(str[i]);
  14938. }
  14939. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14941. isSuccess = ConfigurationStatus_Accepted;
  14942. }
  14943. else
  14944. {
  14945. isSuccess = ConfigurationStatus_Rejected;
  14946. }
  14947. }
  14948. if(strcmp(key, "WebSocketPingInterval") == 0)
  14949. {
  14950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14951. {
  14952. check_ascii = value[0];
  14953. if( (check_ascii < 48) || (check_ascii > 57) )
  14954. {
  14955. isSuccess = ConfigurationStatus_Rejected;
  14956. }
  14957. else
  14958. {
  14959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14960. isSuccess = ConfigurationStatus_Accepted;
  14961. }
  14962. }
  14963. else
  14964. {
  14965. isSuccess = ConfigurationStatus_Rejected;
  14966. }
  14967. }
  14968. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14969. {
  14970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14971. {
  14972. strcpy(str, (const char*)value);
  14973. for(int i = 0; str[i]; i++)
  14974. {
  14975. str[i] = tolower(str[i]);
  14976. }
  14977. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14979. isSuccess = ConfigurationStatus_Accepted;
  14980. }
  14981. else
  14982. {
  14983. isSuccess = ConfigurationStatus_Rejected;
  14984. }
  14985. }
  14986. if(strcmp(key, "AuthorizationKey") == 0)
  14987. {
  14988. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14989. {
  14990. strcpy(str, (const char*)value);
  14991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14992. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14993. isSuccess = ConfigurationStatus_Accepted;
  14994. }
  14995. else
  14996. {
  14997. isSuccess = ConfigurationStatus_Rejected;
  14998. }
  14999. }
  15000. if(strcmp(key, "SecurityProfile") == 0)
  15001. {
  15002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15003. {
  15004. check_ascii = value[0];
  15005. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15006. {
  15007. isSuccess = ConfigurationStatus_Rejected;
  15008. }
  15009. else if(check_ascii == 0x33)
  15010. {
  15011. isSuccess = NotSupported;
  15012. }
  15013. else
  15014. {
  15015. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15016. {
  15017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15018. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15019. isSuccess = ConfigurationStatus_Accepted;
  15020. }
  15021. else
  15022. isSuccess = ConfigurationStatus_Rejected;
  15023. }
  15024. }
  15025. else
  15026. {
  15027. isSuccess = ConfigurationStatus_Rejected;
  15028. }
  15029. }
  15030. if(strcmp(key, "DefaultPrice") == 0)
  15031. {
  15032. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15033. {
  15034. strcpy(str, (const char*)value);
  15035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15036. isSuccess = ConfigurationStatus_Accepted;
  15037. }
  15038. else
  15039. {
  15040. isSuccess = ConfigurationStatus_Rejected;
  15041. }
  15042. }
  15043. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15044. {
  15045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15046. {
  15047. strcpy(str, (const char*)value);
  15048. for(int i = 0; str[i]; i++)
  15049. {
  15050. str[i] = tolower(str[i]);
  15051. }
  15052. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  15053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15054. isSuccess = ConfigurationStatus_Accepted;
  15055. }
  15056. else
  15057. {
  15058. isSuccess = ConfigurationStatus_Rejected;
  15059. }
  15060. }
  15061. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15062. {
  15063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15064. {
  15065. strcpy(str, (const char*)value);
  15066. for(int i = 0; str[i]; i++)
  15067. {
  15068. str[i] = tolower(str[i]);
  15069. }
  15070. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  15071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15072. isSuccess = ConfigurationStatus_Accepted;
  15073. }
  15074. else
  15075. {
  15076. isSuccess = ConfigurationStatus_Rejected;
  15077. }
  15078. }
  15079. if(strcmp(key, "TimeOffset") == 0)
  15080. {
  15081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15082. {
  15083. strcpy(str, (const char*)value);
  15084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15085. isSuccess = ConfigurationStatus_Accepted;
  15086. }
  15087. else
  15088. {
  15089. isSuccess = ConfigurationStatus_Rejected;
  15090. }
  15091. }
  15092. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15093. {
  15094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15095. {
  15096. strcpy(str, (const char*)value);
  15097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15098. isSuccess = ConfigurationStatus_Accepted;
  15099. }
  15100. else
  15101. {
  15102. isSuccess = ConfigurationStatus_Rejected;
  15103. }
  15104. }
  15105. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15106. {
  15107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15108. {
  15109. strcpy(str, (const char*)value);
  15110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15111. isSuccess = ConfigurationStatus_Accepted;
  15112. }
  15113. else
  15114. {
  15115. isSuccess = ConfigurationStatus_Rejected;
  15116. }
  15117. }
  15118. #if 0
  15119. //For OCPP Test Case
  15120. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15121. {
  15122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15123. {
  15124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15125. isSuccess = ConfigurationStatus_Accepted;
  15126. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15127. }
  15128. else
  15129. {
  15130. isSuccess = ConfigurationStatus_Rejected;
  15131. }
  15132. }
  15133. #endif
  15134. #if 1
  15135. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15136. {
  15137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15138. {
  15139. strcpy(str, (const char*)value);
  15140. for(int i = 0; str[i]; i++)
  15141. {
  15142. str[i] = tolower(str[i]);
  15143. }
  15144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15145. isSuccess = ConfigurationStatus_Accepted;
  15146. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15147. }
  15148. else
  15149. {
  15150. isSuccess = ConfigurationStatus_Rejected;
  15151. }
  15152. }
  15153. #endif
  15154. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15155. {
  15156. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15157. {
  15158. check_ascii = value[0];
  15159. if( (check_ascii < 48) || (check_ascii > 57) )
  15160. {
  15161. isSuccess = ConfigurationStatus_Rejected;
  15162. }
  15163. else
  15164. {
  15165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15166. isSuccess = ConfigurationStatus_Accepted;
  15167. }
  15168. }
  15169. else
  15170. {
  15171. isSuccess = ConfigurationStatus_Rejected;
  15172. }
  15173. }
  15174. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15175. {
  15176. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15177. {
  15178. check_ascii = value[0];
  15179. if( (check_ascii < 48) || (check_ascii > 57) )
  15180. {
  15181. isSuccess = ConfigurationStatus_Rejected;
  15182. }
  15183. else
  15184. {
  15185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15186. isSuccess = ConfigurationStatus_Accepted;
  15187. }
  15188. }
  15189. else
  15190. {
  15191. isSuccess = ConfigurationStatus_Rejected;
  15192. }
  15193. }
  15194. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15195. {
  15196. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15197. {
  15198. strcpy(str, (const char*)value);
  15199. for(int i = 0; str[i]; i++)
  15200. {
  15201. str[i] = tolower(str[i]);
  15202. }
  15203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15204. isSuccess = ConfigurationStatus_Accepted;
  15205. }
  15206. else
  15207. {
  15208. isSuccess = ConfigurationStatus_Rejected;
  15209. }
  15210. }
  15211. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15212. {
  15213. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15214. {
  15215. check_ascii = value[0];
  15216. if( (check_ascii < 48) || (check_ascii > 57) )
  15217. {
  15218. isSuccess = ConfigurationStatus_Rejected;
  15219. }
  15220. else
  15221. {
  15222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15223. isSuccess = ConfigurationStatus_Accepted;
  15224. }
  15225. }
  15226. else
  15227. {
  15228. isSuccess = ConfigurationStatus_Rejected;
  15229. }
  15230. }
  15231. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15232. {
  15233. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15234. {
  15235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15236. isSuccess = ConfigurationStatus_Accepted;
  15237. }
  15238. else
  15239. {
  15240. isSuccess = ConfigurationStatus_Rejected;
  15241. }
  15242. }
  15243. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15244. {
  15245. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15246. {
  15247. check_ascii = value[0];
  15248. if( (check_ascii < 48) || (check_ascii > 57) )
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. else
  15253. {
  15254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15255. isSuccess = ConfigurationStatus_Accepted;
  15256. }
  15257. }
  15258. else
  15259. {
  15260. isSuccess = ConfigurationStatus_Rejected;
  15261. }
  15262. }
  15263. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15264. {
  15265. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15266. {
  15267. strcpy(str, (const char*)value);
  15268. for(int i = 0; str[i]; i++)
  15269. {
  15270. str[i] = tolower(str[i]);
  15271. }
  15272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15273. isSuccess = ConfigurationStatus_Accepted;
  15274. }
  15275. else
  15276. {
  15277. isSuccess = ConfigurationStatus_Rejected;
  15278. }
  15279. }
  15280. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15281. {
  15282. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15283. {
  15284. check_ascii = value[0];
  15285. if( (check_ascii < 48) || (check_ascii > 57) )
  15286. {
  15287. isSuccess = ConfigurationStatus_Rejected;
  15288. }
  15289. else
  15290. {
  15291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15292. isSuccess = ConfigurationStatus_Accepted;
  15293. }
  15294. }
  15295. else
  15296. {
  15297. isSuccess = ConfigurationStatus_Rejected;
  15298. }
  15299. }
  15300. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15301. return isSuccess;
  15302. }
  15303. int TransactionMessageAttemptsGet(void)
  15304. {
  15305. return TransactionMessageAttemptsValue;
  15306. }
  15307. int FirstHeartBeatResponse(void)
  15308. {
  15309. return FirstHeartBeat;
  15310. }
  15311. int TransactionMessageRetryIntervalGet(void)
  15312. {
  15313. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15314. }
  15315. int ReadHttpStatus(int sock)
  15316. {
  15317. //char c;
  15318. char buff[1024]="",*ptr=buff+1;
  15319. int bytes_received, status;
  15320. DEBUG_INFO("Begin Response ..\n");
  15321. while((bytes_received = recv(sock, ptr, 1, 0))){
  15322. if(bytes_received==-1){
  15323. perror("ReadHttpStatus");
  15324. exit(1);
  15325. }
  15326. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15327. ptr++;
  15328. }
  15329. *ptr=0;
  15330. ptr=buff+1;
  15331. sscanf(ptr,"%*s %d ", &status);
  15332. DEBUG_INFO("%s\n",ptr);
  15333. DEBUG_INFO("status=%d\n",status);
  15334. DEBUG_INFO("End Response ..\n");
  15335. return (bytes_received>0)?status:0;
  15336. }
  15337. //the only filed that it parsed is 'Content-Length'
  15338. int ParseHeader(int sock)
  15339. {
  15340. //char c;
  15341. char buff[1024]="",*ptr=buff+4;
  15342. int bytes_received;
  15343. DEBUG_INFO("Begin HEADER ..\n");
  15344. while((bytes_received = recv(sock, ptr, 1, 0))){
  15345. if(bytes_received==-1){
  15346. perror("Parse Header");
  15347. exit(1);
  15348. }
  15349. if(
  15350. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15351. (ptr[-1]=='\r') && (*ptr=='\n' )
  15352. ) break;
  15353. ptr++;
  15354. }
  15355. *ptr=0;
  15356. ptr=buff+4;
  15357. //printf("%s",ptr);
  15358. if(bytes_received){
  15359. ptr=strstr(ptr,"Content-Length:");
  15360. if(ptr){
  15361. sscanf(ptr,"%*s %d",&bytes_received);
  15362. }else
  15363. bytes_received=-1; //unknown size
  15364. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15365. }
  15366. DEBUG_INFO("End HEADER ..\n");
  15367. return bytes_received ;
  15368. }
  15369. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15370. {
  15371. int result = TRUE;
  15372. char rmFileCmd[100]={0};
  15373. char FilePath[100]={0};
  15374. char ftpbuf[200];
  15375. int systemresult;
  15376. //DEBUG_INFO("filename=%s\n",filename);
  15377. //DEBUG_INFO("url=%s\n",url);
  15378. sprintf(FilePath,"/mnt/%s",filename);
  15379. system("ping 8.8.8.8 &");
  15380. if((access(FilePath,F_OK))!=-1)
  15381. {
  15382. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15383. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15384. system(rmFileCmd);
  15385. }
  15386. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15387. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15388. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15389. systemresult = system(ftpbuf);
  15390. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15391. if(systemresult != 0)
  15392. {
  15393. DEBUG_INFO("http DownLoad error!\n");
  15394. result = FALSE;
  15395. }
  15396. system("pkill ping");
  15397. return result;
  15398. }
  15399. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15400. {
  15401. int result = TRUE;
  15402. char rmFileCmd[100]={0};
  15403. char FilePath[100]={0};
  15404. char ftpbuf[200];
  15405. int systemresult;
  15406. //char temp[100];
  15407. sprintf(FilePath,"/mnt/%s",filename);
  15408. system("ping 8.8.8.8 &");
  15409. if((access(FilePath,F_OK))!=-1)
  15410. {
  15411. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15412. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15413. system(rmFileCmd);
  15414. }
  15415. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15416. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15417. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15418. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15419. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15420. systemresult = system(ftpbuf);
  15421. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15422. if(systemresult != 0)
  15423. {
  15424. DEBUG_WARN("wget error!\n");
  15425. result = FALSE;
  15426. }
  15427. system("pkill ping");
  15428. return result;
  15429. }
  15430. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15431. {
  15432. char rmFileCmd[100]={0};
  15433. char FilePath[100]={0};
  15434. char buf[512];
  15435. int systemresult = 0;
  15436. //DEBUG_INFO("filename=%s\n",filename);
  15437. //DEBUG_INFO("url=%s\n",url);
  15438. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15439. if((access(FilePath,F_OK))!=-1)
  15440. {
  15441. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15442. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15443. system(rmFileCmd);
  15444. }
  15445. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15446. if(fp == NULL)
  15447. {
  15448. DEBUG_INFO("log is NULL\n");
  15449. return FALSE;
  15450. }
  15451. else
  15452. {
  15453. fprintf(fp, "%s\n", url);
  15454. fprintf(fp, "%s\n", filename);
  15455. fclose(fp);
  15456. }
  15457. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15458. if(phpFP == NULL)
  15459. {
  15460. DEBUG_INFO("PHP upload fail.\n");
  15461. return FALSE;
  15462. }
  15463. else
  15464. {
  15465. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15466. {
  15467. if(strstr(buf, "result") != NULL)
  15468. {
  15469. sscanf(buf, "result: %d", &systemresult);
  15470. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15471. }
  15472. }
  15473. pclose(phpFP);
  15474. }
  15475. if(systemresult != 1)
  15476. {
  15477. DEBUG_INFO("HTTP upload error!\n");
  15478. return FALSE;
  15479. }
  15480. return TRUE;
  15481. }
  15482. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15483. {
  15484. struct hostent* server;
  15485. char *IPbuffer;
  15486. char ftpbuf[200];
  15487. int systemresult;
  15488. // To retrieve host information
  15489. server = gethostbyname(location);
  15490. // To convert an Internet network
  15491. // address into ASCII string
  15492. IPbuffer = inet_ntoa(*((struct in_addr*)
  15493. server->h_addr_list[0]));
  15494. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15495. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15496. /* format : ftpput -u username -p passwd IP target source*/
  15497. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15498. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15499. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15500. systemresult = system(ftpbuf);
  15501. DEBUG_INFO("systemresult=%d\n",systemresult);
  15502. if(systemresult != 0)
  15503. {
  15504. DEBUG_INFO("ftpput error!\n");
  15505. return FALSE;
  15506. }
  15507. return TRUE;
  15508. }
  15509. int GetOcppServerURL()
  15510. {
  15511. int result = FALSE;
  15512. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15513. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15514. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15515. struct yuarel url;
  15516. char urlStr[512];
  15517. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15518. {
  15519. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15520. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15521. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15522. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15523. if(yuarel_parse(&url, urlStr) != -1)
  15524. {
  15525. sprintf(OcppProtocol, "%s", url.scheme);
  15526. sprintf(OcppHost, "%s", url.host);
  15527. if(url.path == NULL)
  15528. OcppTempPath[0] = '\0';
  15529. else
  15530. {
  15531. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15532. {
  15533. sprintf(OcppTempPath, "%s/", url.path);
  15534. }
  15535. else
  15536. {
  15537. sprintf(OcppTempPath, "%s", url.path);
  15538. }
  15539. }
  15540. if(url.port == 0)
  15541. {
  15542. if(strcmp(OcppProtocol, "wss") == 0)
  15543. OcppPort = 443;
  15544. else
  15545. OcppPort = 80;
  15546. }
  15547. else
  15548. OcppPort = url.port;
  15549. result = TRUE;
  15550. }
  15551. }
  15552. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15553. {
  15554. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15555. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15556. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15557. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15558. if(yuarel_parse(&url, urlStr) != -1)
  15559. {
  15560. sprintf(OcppProtocol, "%s", url.scheme);
  15561. sprintf(OcppHost, "%s", url.host);
  15562. if(url.path == NULL)
  15563. OcppTempPath[0] = '\0';
  15564. else
  15565. sprintf(OcppTempPath, "%s", url.path);
  15566. if(url.port == 0)
  15567. {
  15568. if(strcmp(OcppProtocol, "wss") == 0)
  15569. OcppPort = 443;
  15570. else
  15571. OcppPort = 80;
  15572. }
  15573. else
  15574. OcppPort = url.port;
  15575. result = TRUE;
  15576. }
  15577. }
  15578. else
  15579. {
  15580. strcpy(OcppHost,"");
  15581. }
  15582. return result;
  15583. }
  15584. int GetOcppPath()
  15585. {
  15586. int result = FALSE;
  15587. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15588. {
  15589. if(OcppTempPath == NULL)
  15590. {
  15591. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15592. }
  15593. else
  15594. {
  15595. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15596. }
  15597. result = TRUE;
  15598. goto End;
  15599. }
  15600. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15601. {
  15602. if(OcppTempPath == NULL)
  15603. {
  15604. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15605. }
  15606. else
  15607. {
  15608. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15609. }
  15610. result = TRUE;
  15611. goto End;
  15612. }
  15613. else
  15614. {
  15615. strcpy(OcppPath,"");
  15616. }
  15617. End:
  15618. return result;
  15619. }
  15620. int GetOcppPort()
  15621. {
  15622. return OcppPort;
  15623. }
  15624. int GetOcppConnStatus(void)
  15625. {
  15626. return ShmOCPP16Data->OcppConnStatus;
  15627. }
  15628. void SetOcppConnStatus(uint8_t status)
  15629. {
  15630. ShmOCPP16Data->OcppConnStatus = status;
  15631. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15632. }
  15633. int GetHeartBeatWithNOResponse(void)
  15634. {
  15635. return HeartBeatWithNOResponse;
  15636. }
  15637. void SetHeartBeatWithNOResponse(void)
  15638. {
  15639. HeartBeatWithNOResponse = 0;
  15640. }
  15641. void GetStartTransactionIdTag(int gun_index)
  15642. {
  15643. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15644. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15645. }
  15646. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15647. {
  15648. char ch;
  15649. FILE *fptr1;
  15650. int temptransactionId;
  15651. char str[100]={0};
  15652. temptransactionId = 0;
  15653. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15654. {
  15655. DEBUG_INFO("IdTag is empty.\n");
  15656. return temptransactionId;
  15657. }
  15658. /*------ Read the file ----------------*/
  15659. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15660. if (!fptr1)
  15661. {
  15662. DEBUG_INFO("QueueTransactionId file open error.\n");
  15663. //printf(" File not found or unable to open the input file!!\n");
  15664. return temptransactionId;
  15665. }
  15666. ch=fgetc(fptr1);
  15667. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15668. rewind(fptr1);
  15669. if(ch!=EOF)
  15670. {
  15671. // printf("%c",ch);
  15672. while (fgets(str, 100, fptr1) != NULL)
  15673. {
  15674. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15675. if(str[0]=='\0')
  15676. {
  15677. break;
  15678. }
  15679. char *revbuf[8] = {0}; // Variable store string split
  15680. int num = 0;// Quantity after string split
  15681. DEBUG_INFO("Transaction queue data= %s\n", str);
  15682. splitstring(str,",",revbuf,&num); // String split
  15683. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15684. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15685. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15686. DEBUG_INFO("------------------------------\n");
  15687. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15688. {
  15689. if(isStopTransaction)
  15690. {
  15691. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15692. {
  15693. temptransactionId = atoi(revbuf[2]);
  15694. //break;
  15695. }
  15696. }
  15697. else
  15698. {
  15699. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15700. {
  15701. temptransactionId = atoi(revbuf[2]);
  15702. //break;
  15703. }
  15704. }
  15705. }
  15706. }
  15707. }
  15708. else
  15709. DEBUG_INFO("EOF\n");
  15710. fclose(fptr1);
  15711. /*------- End of reading ---------------*/
  15712. return temptransactionId;
  15713. }
  15714. void SetTransactionIdZero(int transactionId)
  15715. {
  15716. char ch;
  15717. FILE *fptr1, *fptr2;
  15718. int temptransactionId = 0;
  15719. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15720. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15721. if (!fptr1)
  15722. {
  15723. //printf(" File not found or unable to open the input file!!\n");
  15724. return ;
  15725. }
  15726. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15727. if (!fptr2)
  15728. {
  15729. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15730. fclose(fptr1);
  15731. return ;
  15732. }
  15733. ch=fgetc(fptr1);
  15734. rewind(fptr1);
  15735. if(ch!=EOF)
  15736. {
  15737. // copy all contents to the temporary file except the specific line
  15738. while (fgets(str, 100, fptr1) != NULL)
  15739. {
  15740. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15741. if(str[0]=='\0')
  15742. {
  15743. break;
  15744. }
  15745. char *revbuf[8] = {0};
  15746. int num = 0;
  15747. strcpy(strtemp, str);
  15748. splitstring(str,",",revbuf,&num);
  15749. if(revbuf[2][0] != '\0')
  15750. {
  15751. temptransactionId = atoi(revbuf[2]);
  15752. if(transactionId != temptransactionId)
  15753. {
  15754. fprintf(fptr2, "%s\n", strtemp);
  15755. }
  15756. }
  15757. }
  15758. }
  15759. fclose(fptr1);
  15760. fclose(fptr2);
  15761. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15762. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15763. /*------ Read the file ----------------*/
  15764. }
  15765. int InternetDisconnect(void)
  15766. {
  15767. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15768. }
  15769. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15770. void storeTempStopTransaction(int gun_index)
  15771. {
  15772. char guid[37]={0};
  15773. int tempIndex = 0;
  15774. char TempStopTransaction[256];
  15775. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15776. DEBUG_INFO("storeTempStopTransaction...\n");
  15777. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15778. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15779. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15780. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15782. {
  15783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15784. {
  15785. tempIndex = ((gun_index==2) ? 1: 0);
  15786. }
  15787. else
  15788. {
  15789. tempIndex = gun_index;
  15790. }
  15791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15792. {
  15793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15794. {
  15795. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15796. }
  15797. }// END OF CHAdeMO_QUANTITY
  15798. }
  15799. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15800. {
  15801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15802. {
  15803. tempIndex = ((gun_index==2) ? 1: 0);
  15804. }
  15805. else
  15806. {
  15807. tempIndex = gun_index;
  15808. }
  15809. for (int index = 0; index < CCS_QUANTITY; index++)
  15810. {
  15811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15812. {
  15813. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15814. }
  15815. }// END OF CCS_QUANTITY
  15816. }
  15817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15818. {
  15819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15820. {
  15821. tempIndex = ((gun_index==2) ? 1: 0);
  15822. }
  15823. else
  15824. {
  15825. tempIndex = gun_index;
  15826. }
  15827. for (int index = 0; index < GB_QUANTITY; index++)
  15828. {
  15829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15830. {
  15831. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15832. }
  15833. }// END OF GB_QUANTITY
  15834. }
  15835. else if(gunType[gun_index] == GUN_TYPE_DO)
  15836. {
  15837. tempIndex = gun_index;
  15838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15839. {
  15840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15841. {
  15842. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15843. }
  15844. }
  15845. }
  15846. else
  15847. {
  15848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15849. {
  15850. tempIndex = 2;
  15851. }
  15852. else
  15853. {
  15854. tempIndex = gun_index;
  15855. }
  15856. for (int index = 0; index < AC_QUANTITY; index++)
  15857. {
  15858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15859. {
  15860. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15861. }
  15862. }// END OF AC_QUANTITY
  15863. }
  15864. //Stop Transaction Time
  15865. struct timeval tmnow;
  15866. struct tm *tm;
  15867. char buf[28];//, usec_buf[6];
  15868. gettimeofday(&tmnow, NULL);
  15869. time_t t;
  15870. t = time(NULL);
  15871. /*UTC time and date*/
  15872. tm = gmtime(&t);
  15873. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15875. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15877. random_uuid(guid);
  15878. /***********************************transactionData******************************************************/
  15879. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15881. //=================================
  15882. //1. Transaction_Begin
  15883. //=================================
  15884. //============================== Energy.Active.Import.Interval ===========================================
  15885. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15886. {
  15887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15890. 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*/]);
  15891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15892. 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))
  15893. {
  15894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15895. }
  15896. else
  15897. {
  15898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15899. }
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15902. }
  15903. //=================================
  15904. //2. Transaction_End
  15905. //=================================
  15906. //2.1====================================== Current.Import L1 ==============================================
  15907. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15908. {
  15909. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15910. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15911. {
  15912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15913. {
  15914. tempIndex = ((gun_index==2) ? 1: 0);
  15915. }
  15916. else
  15917. {
  15918. tempIndex = gun_index;
  15919. }
  15920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15921. {
  15922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15923. {
  15924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15925. }
  15926. }// End of for CHAdeMO_QUANTITY
  15927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15928. }
  15929. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15930. {
  15931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15932. {
  15933. tempIndex = ((gun_index==2) ? 1: 0);
  15934. }
  15935. else
  15936. {
  15937. tempIndex = gun_index;
  15938. }
  15939. for (int index = 0; index < CCS_QUANTITY; index++)
  15940. {
  15941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15942. {
  15943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15944. }
  15945. }// End of for CCS_QUANTITY
  15946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15947. }
  15948. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15949. {
  15950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15951. {
  15952. tempIndex = ((gun_index==2) ? 1: 0);
  15953. }
  15954. else
  15955. {
  15956. tempIndex = gun_index;
  15957. }
  15958. for (int index = 0; index < GB_QUANTITY; index++)
  15959. {
  15960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15961. {
  15962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15963. }
  15964. }// End of for GB_QUANTITY
  15965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15966. }
  15967. else if(gunType[gun_index] == GUN_TYPE_DO)
  15968. {
  15969. tempIndex = gun_index;
  15970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15971. {
  15972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15973. {
  15974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15975. }
  15976. }
  15977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15978. }
  15979. else
  15980. {
  15981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15982. {
  15983. tempIndex = 2;
  15984. }
  15985. else
  15986. {
  15987. tempIndex = gun_index;
  15988. }
  15989. for (int index = 0; index < AC_QUANTITY; index++)
  15990. {
  15991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15992. {
  15993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15994. }
  15995. }// End of for AC_QUANTITY
  15996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15997. }
  15998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16001. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16004. }
  16005. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16006. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16007. {
  16008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16010. {
  16011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16012. {
  16013. tempIndex = ((gun_index==2) ? 1: 0);
  16014. }
  16015. else
  16016. {
  16017. tempIndex = gun_index;
  16018. }
  16019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16020. {
  16021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16022. {
  16023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16024. }
  16025. }// END OF CHAdeMO_QUANTITY
  16026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16027. }
  16028. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16029. {
  16030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16031. {
  16032. tempIndex = ((gun_index==2) ? 1: 0);
  16033. }
  16034. else
  16035. {
  16036. tempIndex = gun_index;
  16037. }
  16038. for (int index = 0; index < CCS_QUANTITY; index++)
  16039. {
  16040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16041. {
  16042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16043. }
  16044. }// END OF CCS_QUANTITY
  16045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16046. }
  16047. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16048. {
  16049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16050. {
  16051. tempIndex = ((gun_index==2) ? 1: 0);
  16052. }
  16053. else
  16054. {
  16055. tempIndex = gun_index;
  16056. }
  16057. for (int index = 0; index < GB_QUANTITY; index++)
  16058. {
  16059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16060. {
  16061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16062. }
  16063. }// END OF GB_QUANTITY
  16064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16065. }
  16066. else if(gunType[gun_index] == GUN_TYPE_DO)
  16067. {
  16068. tempIndex = gun_index;
  16069. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16070. {
  16071. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16072. {
  16073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16074. }
  16075. }
  16076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16077. }
  16078. else
  16079. {
  16080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16081. {
  16082. tempIndex = 2;
  16083. }
  16084. else
  16085. {
  16086. tempIndex = gun_index;
  16087. }
  16088. for (int index = 0; index < AC_QUANTITY; index++)
  16089. {
  16090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16091. {
  16092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16093. }
  16094. }// END OF AC_QUANTITY
  16095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16096. }
  16097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16100. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16103. }
  16104. //2.3====================================== Power.Active.Import =========================================
  16105. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16106. {
  16107. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16108. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16109. {
  16110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16111. {
  16112. tempIndex = ((gun_index==2) ? 1: 0);
  16113. }
  16114. else
  16115. {
  16116. tempIndex = gun_index;
  16117. }
  16118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16119. {
  16120. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16121. {
  16122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16123. }
  16124. } // End for CHAdeMO_QUANTITY
  16125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16126. }
  16127. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16128. {
  16129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16130. {
  16131. tempIndex = ((gun_index==2) ? 1: 0);
  16132. }
  16133. else
  16134. {
  16135. tempIndex = gun_index;
  16136. }
  16137. for (int index = 0; index < CCS_QUANTITY; index++)
  16138. {
  16139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16140. {
  16141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16142. }
  16143. } // END for CCS_QUANTITY
  16144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16145. }
  16146. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16147. {
  16148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16149. {
  16150. tempIndex = ((gun_index==2) ? 1: 0);
  16151. }
  16152. else
  16153. {
  16154. tempIndex = gun_index;
  16155. }
  16156. for (int index = 0; index < GB_QUANTITY; index++)
  16157. {
  16158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16159. {
  16160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16161. }
  16162. }// END for GB_QUANTITY
  16163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16164. }
  16165. else if(gunType[gun_index] == GUN_TYPE_DO)
  16166. {
  16167. tempIndex = gun_index;
  16168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16169. {
  16170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16171. {
  16172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16173. }
  16174. }
  16175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16176. }
  16177. else
  16178. {
  16179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16180. {
  16181. tempIndex = 2;
  16182. }
  16183. else
  16184. {
  16185. tempIndex = gun_index;
  16186. }
  16187. for (int index = 0; index < AC_QUANTITY; index++)
  16188. {
  16189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16190. {
  16191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16192. }
  16193. } // END for AC_QUANTITY
  16194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16195. }
  16196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16199. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16202. }
  16203. //2.4====================================== Voltage L1 ====================================================
  16204. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16205. {
  16206. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16207. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16208. {
  16209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16210. {
  16211. tempIndex = ((gun_index==2) ? 1: 0);
  16212. }
  16213. else
  16214. {
  16215. tempIndex = gun_index;
  16216. }
  16217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16218. {
  16219. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16220. {
  16221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16222. }
  16223. } // END OF FOR CHAdeMO_QUANTITY
  16224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16225. }
  16226. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16227. {
  16228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16229. {
  16230. tempIndex = ((gun_index==2) ? 1: 0);
  16231. }
  16232. else
  16233. {
  16234. tempIndex = gun_index;
  16235. }
  16236. for (int index = 0; index < CCS_QUANTITY; index++)
  16237. {
  16238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16239. {
  16240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16241. }
  16242. } // END OF FOR CCS_QUANTITY
  16243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16244. }
  16245. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16246. {
  16247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16248. {
  16249. tempIndex = ((gun_index==2) ? 1: 0);
  16250. }
  16251. else
  16252. {
  16253. tempIndex = gun_index;
  16254. }
  16255. for (int index = 0; index < GB_QUANTITY; index++)
  16256. {
  16257. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16258. {
  16259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16260. }
  16261. } // END OF FOR GB_QUANTITY
  16262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16263. }
  16264. else if(gunType[gun_index] == GUN_TYPE_DO)
  16265. {
  16266. tempIndex = gun_index;
  16267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16268. {
  16269. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16270. {
  16271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16272. }
  16273. }
  16274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16275. }
  16276. else
  16277. {
  16278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16279. {
  16280. tempIndex = 2;
  16281. }
  16282. else
  16283. {
  16284. tempIndex = gun_index;
  16285. }
  16286. for (int index = 0; index < AC_QUANTITY; index++)
  16287. {
  16288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16289. {
  16290. 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
  16291. }
  16292. } // END OF FOR AC_QUANTITY
  16293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16294. }
  16295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16298. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16301. }
  16302. //2.5============================================== End SoC =========================================================
  16303. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16304. {
  16305. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16306. 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))
  16307. {
  16308. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16309. {
  16310. tempIndex = ((gun_index==2) ? 1: 0);
  16311. }
  16312. else
  16313. {
  16314. tempIndex = gun_index;
  16315. }
  16316. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16317. {
  16318. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16319. {
  16320. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16321. {
  16322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16323. }
  16324. }
  16325. }
  16326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16327. {
  16328. for (int index = 0; index < CCS_QUANTITY; index++)
  16329. {
  16330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16331. {
  16332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16333. }
  16334. }
  16335. }
  16336. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16337. {
  16338. for (int index = 0; index < GB_QUANTITY; index++)
  16339. {
  16340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16341. {
  16342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16343. }
  16344. }
  16345. }
  16346. else if(gunType[gun_index] == GUN_TYPE_DO)
  16347. {
  16348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16349. {
  16350. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16351. {
  16352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16353. }
  16354. }
  16355. }
  16356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16362. } // END FOR DC CASE
  16363. }
  16364. //2.6====================================== Current.Import L2 ==============================================
  16365. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16366. {
  16367. // AC 3 phase L2 current
  16368. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16369. {
  16370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16371. {
  16372. tempIndex = 2;
  16373. }
  16374. else
  16375. {
  16376. tempIndex = gun_index;
  16377. }
  16378. for (int index = 0; index < AC_QUANTITY; index++)
  16379. {
  16380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16381. {
  16382. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16383. }
  16384. }// End of for AC_QUANTITY
  16385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16386. }
  16387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16392. }
  16393. //2.7====================================== Current.Import L3 ==============================================
  16394. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16395. {
  16396. // AC 3 phase L3 current
  16397. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16398. {
  16399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16400. {
  16401. tempIndex = 2;
  16402. }
  16403. else
  16404. {
  16405. tempIndex = gun_index;
  16406. }
  16407. for (int index = 0; index < AC_QUANTITY; index++)
  16408. {
  16409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16410. {
  16411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16412. }
  16413. }// End of for AC_QUANTITY
  16414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16415. }
  16416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16421. }
  16422. //2.9====================================== Voltage L2 ====================================================
  16423. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16424. {
  16425. // AC 3 phase L2 volatge
  16426. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16427. {
  16428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16429. {
  16430. tempIndex = 2;
  16431. }
  16432. else
  16433. {
  16434. tempIndex = gun_index;
  16435. }
  16436. for (int index = 0; index < AC_QUANTITY; index++)
  16437. {
  16438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16439. {
  16440. 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
  16441. }
  16442. } // END OF FOR AC_QUANTITY
  16443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16444. }
  16445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16450. }
  16451. //2.10====================================== Voltage L3 ====================================================
  16452. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16453. {
  16454. // AC 3 phase L3 volatge
  16455. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16456. {
  16457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16458. {
  16459. tempIndex = 2;
  16460. }
  16461. else
  16462. {
  16463. tempIndex = gun_index;
  16464. }
  16465. for (int index = 0; index < AC_QUANTITY; index++)
  16466. {
  16467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16468. {
  16469. 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
  16470. }
  16471. } // END OF FOR AC_QUANTITY
  16472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16473. }
  16474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16479. }
  16480. //====================== Start SoC ================================
  16481. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16482. {
  16483. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16484. 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))
  16485. {
  16486. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16487. {
  16488. tempIndex = ((gun_index==2) ? 1: 0);
  16489. }
  16490. else
  16491. {
  16492. tempIndex = gun_index;
  16493. }
  16494. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16495. {
  16496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16497. {
  16498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16499. {
  16500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16501. }
  16502. }
  16503. }
  16504. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16505. {
  16506. for (int index = 0; index < CCS_QUANTITY; index++)
  16507. {
  16508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16509. {
  16510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16511. }
  16512. }
  16513. }
  16514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16515. {
  16516. for (int index = 0; index < GB_QUANTITY; index++)
  16517. {
  16518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16519. {
  16520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16521. }
  16522. }
  16523. }
  16524. else if(gunType[gun_index] == GUN_TYPE_DO)
  16525. {
  16526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16527. {
  16528. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16529. {
  16530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16531. }
  16532. }
  16533. }
  16534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16540. } // END FOR DC CASE
  16541. }
  16542. //======================================== Message create ==============================================
  16543. json_object *StopTransaction = json_object_new_object();
  16544. json_object *transactionDatas = json_object_new_array();
  16545. json_object *sampledValues = json_object_new_array();
  16546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16547. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16548. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16549. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16550. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16551. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16552. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16553. {
  16554. json_object *transactionData = json_object_new_object();
  16555. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16556. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16557. {
  16558. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16559. {
  16560. json_object *sampledValue = json_object_new_object();
  16561. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16563. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16565. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16567. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16569. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16571. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16573. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16574. json_object_array_add(sampledValues, sampledValue);
  16575. }
  16576. }
  16577. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16578. json_object_array_add(transactionDatas, transactionData);
  16579. }
  16580. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16581. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16582. ,MESSAGE_TYPE_CALL
  16583. ,guid
  16584. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16585. json_object_put(StopTransaction);
  16586. // Check File "TempStopTransaction" Exist
  16587. if((access(TempStopTransaction,F_OK))!=-1)
  16588. {
  16589. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16590. fclose(fopen(TempStopTransaction, "w"));
  16591. }
  16592. else
  16593. {
  16594. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16595. FILE *log = fopen(TempStopTransaction, "w+");
  16596. if(log == NULL)
  16597. {
  16598. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16599. return ;
  16600. }
  16601. else
  16602. {
  16603. fclose(log);
  16604. }
  16605. }
  16606. //Add TempStopTransaction | Update TempStopTransaction
  16607. // open file for writing
  16608. FILE *outfile;
  16609. outfile = fopen (TempStopTransaction, "a");
  16610. //DEBUG_INFO("data = %s\n", queuedata);
  16611. fputs(queuedata, outfile);
  16612. fputs("\n", outfile);
  16613. fclose (outfile);
  16614. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16615. }
  16616. void checkTempStopTransaction(int gun_index)
  16617. {
  16618. FILE *fptr1;
  16619. char ch;
  16620. char str[QUEUE_MESSAGE_LENGTH]={0};
  16621. char guid[37]={0};
  16622. char tempdata[65]={0};
  16623. char connectorStr[2]={0};
  16624. char TempStopTransaction[256];
  16625. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16626. fptr1 = fopen(TempStopTransaction, "r");
  16627. //TempStopTransaction格式: 槍號,StopTransaction封包
  16628. if (!fptr1)
  16629. {
  16630. //printf(" File not found or unable to open the input file!!\n");
  16631. return ;
  16632. }
  16633. ch=fgetc(fptr1);
  16634. //printf(" Now the content of the file %s is : \n",fname);
  16635. rewind(fptr1);
  16636. if(ch!=EOF)
  16637. {
  16638. // copy all contents to the temporary file except the specific line
  16639. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16640. {
  16641. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16642. if(str[0]=='\0')
  16643. {
  16644. break;
  16645. }
  16646. //TempStopTransaction格式: 槍號,StopTransaction封包
  16647. strncpy(connectorStr, str, 1);
  16648. if(atoi(connectorStr) != (gun_index+1))
  16649. {
  16650. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16651. fclose(fptr1);
  16652. return ;
  16653. }
  16654. //random_uuid(guid);
  16655. strncpy(guid, str+6, 36); //copy guid
  16656. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16658. {
  16659. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16660. }
  16661. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16662. OCPP_insert_transaction_msg(NO, str);
  16663. memset(str,0,ARRAY_SIZE(str));
  16664. }
  16665. }
  16666. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16667. fclose(fptr1);
  16668. remove(TempStopTransaction); // remove the original file
  16669. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16670. }
  16671. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16672. {
  16673. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16674. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16675. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16676. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16677. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16678. }
  16679. int GetWebSocketPingInterval(void)
  16680. {
  16681. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16682. }
  16683. int GetServerSign(void)
  16684. {
  16685. return server_sign;
  16686. }
  16687. uint8_t GetOcppSecurityProfile()
  16688. {
  16689. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16690. }
  16691. void GetOcppChargerBoxId(uint8_t *data)
  16692. {
  16693. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16694. }
  16695. void GetOcppSecurityPassword(uint8_t *data)
  16696. {
  16697. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16698. }
  16699. void SetOcppVersion(uint8_t *version)
  16700. {
  16701. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16702. DEBUG_INFO("ocpp version: %s\n", version);
  16703. if(strstr((char*)version, "ocpp1.6") != NULL)
  16704. {
  16705. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16706. }
  16707. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16708. {
  16709. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16710. system("pkill OcppBackend");
  16711. }
  16712. }
  16713. void SetServerSign(int value)
  16714. {
  16715. server_sign = value;
  16716. }
  16717. int GetBootNotificationInterval(void)
  16718. {
  16719. return BootNotificationInterval;
  16720. }
  16721. int GetInternetConn(void)
  16722. {
  16723. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16724. }
  16725. int GetBackendConnectionTimeout(void)
  16726. {
  16727. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16728. }
  16729. int isConnectorInitMode(int gun_index)
  16730. {
  16731. int tempIndex = 0;
  16732. int result = TRUE;
  16733. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16734. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16735. {
  16736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16737. {
  16738. tempIndex = ((gun_index==2) ? 1: 0);
  16739. }
  16740. else
  16741. {
  16742. tempIndex = gun_index;
  16743. }
  16744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16745. {
  16746. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16747. {
  16748. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16749. } //end of the same index
  16750. }//end of for CHAdeMO_QUANTITY
  16751. }
  16752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16753. {
  16754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16755. {
  16756. tempIndex = ((gun_index==2) ? 1: 0);
  16757. }
  16758. else
  16759. {
  16760. tempIndex = gun_index;
  16761. }
  16762. for (int index = 0; index < CCS_QUANTITY; index++)
  16763. {
  16764. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16765. {
  16766. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16767. } //end of the same index
  16768. } // end of for CCS_QUANTITY
  16769. }
  16770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16771. {
  16772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16773. {
  16774. tempIndex = ((gun_index==2) ? 1: 0);
  16775. }
  16776. else
  16777. {
  16778. tempIndex = gun_index;
  16779. }
  16780. for (int index = 0; index < GB_QUANTITY; index++)
  16781. {
  16782. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16783. {
  16784. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16785. } //end of the same index
  16786. } // end of for GB_QUANTITY
  16787. }
  16788. else if(gunType[gun_index] == GUN_TYPE_DO)
  16789. {
  16790. tempIndex = gun_index;
  16791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16792. {
  16793. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16794. {
  16795. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16796. } //end of the same index
  16797. }
  16798. }
  16799. else
  16800. {
  16801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16802. {
  16803. tempIndex = 2;
  16804. }
  16805. else
  16806. {
  16807. tempIndex = gun_index;
  16808. }
  16809. for (int index = 0; index < AC_QUANTITY; index++)
  16810. {
  16811. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16812. {
  16813. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16814. }//end of the same index
  16815. }//end of for AC_QUANTITY
  16816. }
  16817. return result;
  16818. }
  16819. void refreshProcDogTimer()
  16820. {
  16821. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16822. }
  16823. void InitialSystemValue(void)
  16824. {
  16825. int connectorIndex = 0;
  16826. //int valueASCII = 0;
  16827. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16828. gunTotalNumber=0;
  16829. SystemInitial = 0;
  16830. locallistVersion=0;
  16831. BootNotificationInterval = 0;
  16832. authorizeRetryTimes = 0;
  16833. GunStatusInterval = 10;
  16834. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16835. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16836. //Hear Beat
  16837. HeartBeatWithNOResponse = 0;
  16838. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16839. FirstHeartBeat = 0;
  16840. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16841. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16842. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16843. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16844. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16845. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16846. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16847. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16848. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16849. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16850. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16851. memset(gunType, 0, ARRAY_SIZE(gunType));
  16852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16853. {
  16854. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16855. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16856. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16857. {
  16858. // DO series
  16859. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16860. {
  16861. SystemInitial = SystemInitial + 1;
  16862. gunTotalNumber = gunTotalNumber + 1;
  16863. gunType[connectorIndex] = GUN_TYPE_DO;
  16864. connectorIndex = connectorIndex + 1;
  16865. }
  16866. }
  16867. else
  16868. {
  16869. // DM, DW, DS series
  16870. //check connector / socket type (index: 8, 9, 10)
  16871. for(int index=7; index <10 ; index++)
  16872. {
  16873. if(index != 8)
  16874. {
  16875. // DC Connector
  16876. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16877. {
  16878. SystemInitial = SystemInitial + 1;
  16879. gunTotalNumber = gunTotalNumber + 1;
  16880. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16881. connectorIndex = connectorIndex + 1;
  16882. }
  16883. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16884. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16885. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16886. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16887. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16888. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16889. {
  16890. SystemInitial = SystemInitial + 1;
  16891. gunTotalNumber = gunTotalNumber + 1;
  16892. gunType[connectorIndex] = GUN_TYPE_CCS;
  16893. connectorIndex = connectorIndex + 1;
  16894. }
  16895. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16896. {
  16897. SystemInitial = SystemInitial + 1;
  16898. gunTotalNumber = gunTotalNumber + 1;
  16899. gunType[connectorIndex] = GUN_TYPE_GBT;
  16900. connectorIndex = connectorIndex + 1;
  16901. }
  16902. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16903. {
  16904. SystemInitial = SystemInitial + 1;
  16905. gunTotalNumber = gunTotalNumber + 1;
  16906. gunType[connectorIndex] = GUN_TYPE_DO;
  16907. connectorIndex = connectorIndex + 1;
  16908. }
  16909. }
  16910. else
  16911. {
  16912. // AC Connector
  16913. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16914. {
  16915. SystemInitial = SystemInitial + 1;
  16916. gunTotalNumber = gunTotalNumber + 1;
  16917. gunType[connectorIndex] = GUN_TYPE_AC;
  16918. connectorIndex = connectorIndex + 1;
  16919. }
  16920. }
  16921. }
  16922. }
  16923. //DEBUG_INFO("DC ...\n");
  16924. }
  16925. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16926. {
  16927. //check connector / socket type (index: 8, 9, 10)
  16928. for(int index=7; index <10 ; index++)
  16929. {
  16930. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16931. {
  16932. SystemInitial = SystemInitial + 1;
  16933. gunTotalNumber = gunTotalNumber + 1;
  16934. gunType[connectorIndex] = GUN_TYPE_AC;
  16935. connectorIndex = connectorIndex + 1;
  16936. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16937. }
  16938. }
  16939. }
  16940. //Status && ConnectorPlugIn Setting
  16941. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16942. {
  16943. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16944. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16945. }
  16946. for (int index = 0; index < CCS_QUANTITY; index++)
  16947. {
  16948. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16949. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16950. }
  16951. for (int index = 0; index < GB_QUANTITY; index++)
  16952. {
  16953. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16954. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16955. }
  16956. for (int index = 0; index < AC_QUANTITY; index++)
  16957. {
  16958. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16959. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16960. }
  16961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16962. {
  16963. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16964. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16965. }
  16966. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16967. {
  16968. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16969. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16970. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16971. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16972. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16973. }
  16974. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16975. clientTime.Heartbeat=time((time_t*)NULL);
  16976. sleep(1);
  16977. }
  16978. void LWS_Send(char *str)
  16979. {
  16980. //=====================================================
  16981. // Check InternetConn 0: disconnected, 1: connected
  16982. //====================================================
  16983. if(GetOcppConnStatus() == 0)
  16984. {
  16985. DEBUG_INFO("offline now !!!\n");
  16986. return;
  16987. }
  16988. // Only disable isWebsocketSendable operation initiated by charger
  16989. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16990. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16991. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16992. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16993. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16994. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16995. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16996. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16997. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16998. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16999. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17000. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17001. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17002. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17003. {
  17004. isWebsocketSendable = 0;
  17005. }
  17006. pthread_mutex_lock(&lock_send);
  17007. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17008. sprintf((char *)SendBuffer, "%s", str);
  17009. SendBufLen = strlen(str);
  17010. pthread_mutex_unlock(&lock_send);
  17011. lws_callback_on_writable(wsi_client);
  17012. //lws_service(context, 0);
  17013. //sleep(1);
  17014. }
  17015. void LWS_SendNow(char *str)
  17016. {
  17017. //=====================================================
  17018. // Check InternetConn 0: disconnected, 1: connected
  17019. //====================================================
  17020. if(GetOcppConnStatus() == 0)
  17021. {
  17022. DEBUG_INFO("offline now !!!\n");
  17023. return;
  17024. }
  17025. // Only disable isWebsocketSendable operation initiated by charger
  17026. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17027. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17028. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17029. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17030. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17031. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17032. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17033. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17034. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17035. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17036. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17037. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17038. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17039. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17040. {
  17041. isWebsocketSendable = 0;
  17042. }
  17043. pthread_mutex_lock(&lock_send);
  17044. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17045. sprintf((char *)SendBuffer, "%s", str);
  17046. SendBufLen = strlen(str);
  17047. pthread_mutex_unlock(&lock_send);
  17048. lws_callback_on_writable(wsi_client);
  17049. lws_service(context, 0);
  17050. //sleep(1);
  17051. }