MessageHandler.c 847 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480
  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 InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  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[1]={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. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1132. if(strstr((char*)start, ".") != NULL)
  1133. {
  1134. // Original data with mini second
  1135. if(strstr((char*)start, "Z") != NULL)
  1136. {
  1137. // Original data with Z
  1138. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1139. &parsingResult.year,
  1140. &parsingResult.month,
  1141. &parsingResult.mday,
  1142. &parsingResult.hour,
  1143. &parsingResult.min,
  1144. &parsingResult.sec,
  1145. &parsingResult.minSec);
  1146. }
  1147. else
  1148. {
  1149. // Original data without Z
  1150. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1151. &parsingResult.year,
  1152. &parsingResult.month,
  1153. &parsingResult.mday,
  1154. &parsingResult.hour,
  1155. &parsingResult.min,
  1156. &parsingResult.sec,
  1157. &parsingResult.minSec,
  1158. &parsingResult.tz_hour,
  1159. &parsingResult.tz_min);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. // Original data without mini second
  1165. if(strstr((char*)start, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec);
  1175. }
  1176. else
  1177. {
  1178. // Original data without Z
  1179. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1180. &parsingResult.year,
  1181. &parsingResult.month,
  1182. &parsingResult.mday,
  1183. &parsingResult.hour,
  1184. &parsingResult.min,
  1185. &parsingResult.sec,
  1186. &parsingResult.tz_hour,
  1187. &parsingResult.tz_min);
  1188. }
  1189. }
  1190. if(parsingResult.scanedElement >= 6)
  1191. {
  1192. tmStart.tm_year = parsingResult.year - 1900;
  1193. tmStart.tm_mon = parsingResult.month - 1;
  1194. tmStart.tm_mday = parsingResult.mday;
  1195. tmStart.tm_hour = parsingResult.hour;
  1196. tmStart.tm_min = parsingResult.min;
  1197. tmStart.tm_sec = parsingResult.sec;
  1198. tmStart.tm_gmtoff = 0;
  1199. tbStart.time = mktime(&tmStart);
  1200. tbStart.timezone = 0;
  1201. tbStart.millitm = 0;
  1202. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1203. if(DiffTimebWithNowSec(tbStart) <= 0)
  1204. result = NO;
  1205. else
  1206. result = YES;
  1207. }
  1208. else
  1209. {
  1210. DEBUG_WARN("Start date parsing error.\n");
  1211. }
  1212. return result;
  1213. }
  1214. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1215. {
  1216. int result = -1;
  1217. struct tm tmStart;
  1218. struct timeb tbStart;
  1219. struct tm tmStop;
  1220. struct timeb tbStop;
  1221. 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) &&
  1222. (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))
  1223. {
  1224. tmStart.tm_year -= 1900;
  1225. tmStart.tm_mon -= 1;
  1226. tbStart.time = mktime(&tmStart);
  1227. tbStart.millitm = 0;
  1228. tmStop.tm_year -= 1900;
  1229. tmStop.tm_mon -= 1;
  1230. tbStop.time = mktime(&tmStop);
  1231. tbStop.millitm = 0;
  1232. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1233. }
  1234. return result;
  1235. }
  1236. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1237. {
  1238. FILE *fp;
  1239. char profileFileName[128];
  1240. char *line = NULL;
  1241. size_t len = 0;
  1242. time_t CurrentTime;
  1243. struct tm *tmComposite;
  1244. struct StructChargingProfile maxProfile;
  1245. uint8_t limitMax=0;
  1246. int compositePeriodIdx = 0;
  1247. CurrentTime = time(NULL);
  1248. tmComposite=localtime(&CurrentTime);
  1249. 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);
  1250. if(isUnitA)
  1251. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1252. else
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1254. compositeProfile->ChargingSchedule.Duration = durationReq;
  1255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1256. {
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1260. }
  1261. compositeProfile->ChargingProfileId = 0;
  1262. compositeProfile->StackLevel = 99 ;
  1263. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1264. maxProfile.ChargingProfileId = -1;
  1265. maxProfile.ChargingSchedule.Duration = -1;
  1266. system("rm -f /tmp/*.json");
  1267. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1268. // Search max profile
  1269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1270. if((access(profileFileName, F_OK))!=-1)
  1271. {
  1272. fp = fopen(profileFileName, "r");
  1273. while(getline(&line, &len, fp) != -1)
  1274. {
  1275. json_object *obj = NULL;
  1276. obj = json_tokener_parse(line);
  1277. if(is_error(obj))
  1278. {
  1279. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1280. }
  1281. else
  1282. {
  1283. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1284. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1285. )
  1286. {
  1287. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1288. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1289. )
  1290. {
  1291. struct tm tmFrom, tmTo;
  1292. struct timeb tbFrom, tbTo;
  1293. 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) &&
  1294. (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))
  1295. {
  1296. tmFrom.tm_year -= 1900;
  1297. tmFrom.tm_mon -= 1;
  1298. tbFrom.time = mktime(&tmFrom);
  1299. tmTo.tm_year -= 1900;
  1300. tmTo.tm_mon -= 1;
  1301. tbTo.time = mktime(&tmTo);
  1302. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1303. {
  1304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1305. {
  1306. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1309. }
  1310. maxProfile.ChargingProfileId = -1;
  1311. maxProfile.StackLevel = -1;
  1312. if(maxProfile.ChargingProfileId == -1)
  1313. DEBUG_INFO("MaxProfile found.\n");
  1314. else
  1315. DEBUG_INFO("MaxProfile updated.\n");
  1316. // Required item
  1317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1320. if(isUnitA)
  1321. {
  1322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1323. 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++)
  1324. {
  1325. 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"));
  1326. 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?
  1327. 3:
  1328. 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")));
  1329. 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")));
  1330. }
  1331. }
  1332. else
  1333. {
  1334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1335. 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++)
  1336. {
  1337. 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"));
  1338. 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?
  1339. 3:
  1340. 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")));
  1341. 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));
  1342. }
  1343. }
  1344. // Optional item
  1345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)maxProfile.ValidFrom, " ");
  1352. }
  1353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1356. }
  1357. else
  1358. {
  1359. sprintf((char*)maxProfile.ValidTo, " ");
  1360. }
  1361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1368. }
  1369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1370. {
  1371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1372. }
  1373. else
  1374. {
  1375. maxProfile.TransactionId = -1;
  1376. }
  1377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1380. }
  1381. else
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = 86400;
  1384. }
  1385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1386. {
  1387. 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")));
  1388. }
  1389. else
  1390. {
  1391. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1392. }
  1393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1396. }
  1397. else
  1398. {
  1399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1411. }
  1412. maxProfile.ChargingProfileId = -1;
  1413. maxProfile.StackLevel = -1;
  1414. if(maxProfile.ChargingProfileId == -1)
  1415. DEBUG_INFO("MaxProfile found.\n");
  1416. else
  1417. DEBUG_INFO("MaxProfile updated.\n");
  1418. // Required item
  1419. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1420. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1421. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1422. if(isUnitA)
  1423. {
  1424. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1425. 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++)
  1426. {
  1427. 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"));
  1428. 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?
  1429. 3:
  1430. 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")));
  1431. 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")));
  1432. }
  1433. }
  1434. else
  1435. {
  1436. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1437. 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++)
  1438. {
  1439. 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"));
  1440. 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?
  1441. 3:
  1442. 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")));
  1443. 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));
  1444. }
  1445. }
  1446. // Optional item
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidFrom, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ValidTo, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1464. {
  1465. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1466. }
  1467. else
  1468. {
  1469. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1470. }
  1471. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1472. {
  1473. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.TransactionId = -1;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1480. {
  1481. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1482. }
  1483. else
  1484. {
  1485. maxProfile.ChargingSchedule.Duration = 86400;
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1488. {
  1489. 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")));
  1490. }
  1491. else
  1492. {
  1493. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1494. }
  1495. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1496. {
  1497. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1498. }
  1499. else
  1500. {
  1501. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1502. }
  1503. }
  1504. }
  1505. }
  1506. json_object_put(obj);
  1507. }
  1508. fclose(fp);
  1509. /*
  1510. if(maxProfile.ChargingProfileId !=-1)
  1511. {
  1512. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1513. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1514. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1515. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1516. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1517. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1518. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1519. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1520. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1521. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1522. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1526. {
  1527. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1528. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1529. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1530. }
  1531. }
  1532. }
  1533. else
  1534. DEBUG_INFO("MaxProfile not found.\n");
  1535. DEBUG_INFO("------------------------------------\n");*/
  1536. }
  1537. if(maxProfile.ChargingProfileId != -1)
  1538. {
  1539. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1540. {
  1541. if(maxProfile.ChargingSchedule.Duration != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. }
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1552. 0:
  1553. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1554. if(idxPeriod > 0)
  1555. {
  1556. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1565. {
  1566. if(maxProfile.ChargingSchedule.Duration != -1)
  1567. {
  1568. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1569. }
  1570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1571. {
  1572. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1588. {
  1589. if(maxProfile.ChargingSchedule.Duration != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. }
  1595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1596. {
  1597. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1598. {
  1599. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1600. 0:
  1601. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1602. if(idxPeriod > 0)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1605. {
  1606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. else
  1613. {
  1614. if(maxProfile.ChargingSchedule.Duration != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. }
  1620. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1621. {
  1622. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1623. {
  1624. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1625. 0:
  1626. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1627. if(idxPeriod > 0)
  1628. {
  1629. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1630. {
  1631. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1632. }
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. /*
  1639. DEBUG_INFO("MaxProfile after align.\n");
  1640. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1641. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1642. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1643. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1644. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1645. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1646. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1647. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1648. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1649. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1650. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1652. {
  1653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1654. {
  1655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1658. }
  1659. }
  1660. DEBUG_INFO("------------------------------------\n");*/
  1661. }
  1662. // Find each profile period quantity
  1663. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1664. {
  1665. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1666. limitMax = idx+1;
  1667. }
  1668. if(maxProfile.ChargingProfileId != -1)
  1669. {
  1670. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1671. {
  1672. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1673. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1674. (maxProfile.ChargingSchedule.Duration > 0))
  1675. {
  1676. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1677. {
  1678. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1679. compositePeriodIdx++;
  1680. }
  1681. else
  1682. {
  1683. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1684. }
  1685. }
  1686. }
  1687. }
  1688. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1689. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1690. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1691. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1692. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1693. {
  1694. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1695. {
  1696. compositeProfile->ChargingProfileId = 1;
  1697. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1698. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1699. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1700. }
  1701. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1702. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1703. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1704. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1705. }
  1706. if(line)
  1707. free(line);
  1708. }
  1709. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1710. {
  1711. FILE *fp;
  1712. char profileFileName[128];
  1713. char *line = NULL;
  1714. size_t len = 0;
  1715. time_t CurrentTime;
  1716. struct tm *tmComposite;
  1717. struct StructChargingProfile maxProfile;
  1718. struct StructChargingProfile defaultTxProfile;
  1719. struct StructChargingProfile txProfile;
  1720. struct StructChargingSchedulePeriod tmpPeriod;
  1721. uint8_t limitMax=0;
  1722. uint8_t limitDef=0;
  1723. uint8_t limitTx=0;
  1724. int compositePeriodIdx = 0;
  1725. CurrentTime = time(NULL);
  1726. tmComposite=localtime(&CurrentTime);
  1727. 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);
  1728. if(isUnitA)
  1729. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1730. else
  1731. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1732. compositeProfile->ChargingSchedule.Duration = durationReq;
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1736. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1738. }
  1739. compositeProfile->ChargingProfileId = 0;
  1740. compositeProfile->StackLevel = 99 ;
  1741. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1742. maxProfile.ChargingProfileId = -1;
  1743. defaultTxProfile.ChargingProfileId = -1;
  1744. txProfile.ChargingProfileId = -1;
  1745. maxProfile.ChargingSchedule.Duration = -1;
  1746. defaultTxProfile.ChargingSchedule.Duration = -1;
  1747. txProfile.ChargingSchedule.Duration = -1;
  1748. system("rm -f /tmp/*.json");
  1749. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1750. /*
  1751. * Search valid charging profile
  1752. */
  1753. //DEBUG_INFO("====================================\n");
  1754. // Search tx profile
  1755. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1756. if((access(profileFileName, F_OK))!=-1)
  1757. {
  1758. fp = fopen(profileFileName, "r");
  1759. while(getline(&line, &len, fp) != -1)
  1760. {
  1761. json_object *obj = NULL;
  1762. obj = json_tokener_parse(line);
  1763. if(is_error(obj))
  1764. {
  1765. DEBUG_ERROR("Parse txProfile from file error.\n");
  1766. }
  1767. else
  1768. {
  1769. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1770. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1771. )
  1772. {
  1773. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1774. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1775. )
  1776. {
  1777. struct tm tmFrom, tmTo;
  1778. struct timeb tbFrom, tbTo;
  1779. 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) &&
  1780. (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))
  1781. {
  1782. tmFrom.tm_year -= 1900;
  1783. tmFrom.tm_mon -= 1;
  1784. tbFrom.time = mktime(&tmFrom);
  1785. tmTo.tm_year -= 1900;
  1786. tmTo.tm_mon -= 1;
  1787. tbTo.time = mktime(&tmTo);
  1788. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1789. {
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1795. }
  1796. txProfile.ChargingProfileId = -1;
  1797. txProfile.StackLevel = -1;
  1798. if(txProfile.ChargingProfileId == -1)
  1799. DEBUG_INFO("TxProfile found.\n");
  1800. else
  1801. DEBUG_INFO("TxProfile updated.\n");
  1802. // Required item
  1803. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1804. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1805. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1806. if(isUnitA)
  1807. {
  1808. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1809. 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++)
  1810. {
  1811. 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"));
  1812. 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?
  1813. 3:
  1814. 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")));
  1815. 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")));
  1816. }
  1817. }
  1818. else
  1819. {
  1820. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1821. 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++)
  1822. {
  1823. 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"));
  1824. 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?
  1825. 3:
  1826. 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")));
  1827. 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));
  1828. }
  1829. }
  1830. // Optional item
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidFrom, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.ValidTo, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1848. {
  1849. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1850. }
  1851. else
  1852. {
  1853. sprintf((char*)txProfile.RecurrencyKind, " ");
  1854. }
  1855. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1856. {
  1857. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.TransactionId = -1;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1864. {
  1865. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1866. }
  1867. else
  1868. {
  1869. txProfile.ChargingSchedule.Duration = 86400;
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1872. {
  1873. 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")));
  1874. }
  1875. else
  1876. {
  1877. 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));
  1878. }
  1879. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1880. {
  1881. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1882. }
  1883. else
  1884. {
  1885. txProfile.ChargingSchedule.MinChargingRate = -1;
  1886. }
  1887. }
  1888. }
  1889. }
  1890. else
  1891. {
  1892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1893. {
  1894. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1895. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1897. }
  1898. txProfile.ChargingProfileId = -1;
  1899. txProfile.StackLevel = -1;
  1900. if(txProfile.ChargingProfileId == -1)
  1901. DEBUG_INFO("TxProfile found.\n");
  1902. else
  1903. DEBUG_INFO("TxProfile updated.\n");
  1904. // Required item
  1905. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1906. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1907. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1908. if(isUnitA)
  1909. {
  1910. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1911. 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++)
  1912. {
  1913. 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"));
  1914. 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?
  1915. 3:
  1916. 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")));
  1917. 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")));
  1918. }
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1923. 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++)
  1924. {
  1925. 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"));
  1926. 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?
  1927. 3:
  1928. 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")));
  1929. 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));
  1930. }
  1931. }
  1932. // Optional item
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.ValidFrom, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1942. {
  1943. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1944. }
  1945. else
  1946. {
  1947. sprintf((char*)txProfile.ValidTo, " ");
  1948. }
  1949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1950. {
  1951. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1952. }
  1953. else
  1954. {
  1955. sprintf((char*)txProfile.RecurrencyKind, " ");
  1956. }
  1957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1958. {
  1959. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1960. }
  1961. else
  1962. {
  1963. txProfile.TransactionId = -1;
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.Duration = 86400;
  1972. }
  1973. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1974. {
  1975. 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")));
  1976. }
  1977. else
  1978. {
  1979. 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));
  1980. }
  1981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1982. {
  1983. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1984. }
  1985. else
  1986. {
  1987. txProfile.ChargingSchedule.MinChargingRate = -1;
  1988. }
  1989. }
  1990. }
  1991. }
  1992. json_object_put(obj);
  1993. }
  1994. fclose(fp);
  1995. /*
  1996. if(txProfile.ChargingProfileId != -1)
  1997. {
  1998. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1999. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2000. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2001. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2002. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2003. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2004. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2005. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2006. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2007. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2008. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2010. {
  2011. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2012. {
  2013. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2014. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2015. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2016. }
  2017. }
  2018. }
  2019. else
  2020. DEBUG_INFO("TxProfile not found.\n");*/
  2021. }
  2022. // Search default tx profile
  2023. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2024. if((access(profileFileName, F_OK))==-1)
  2025. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2026. if((access(profileFileName, F_OK))!=-1)
  2027. {
  2028. fp = fopen(profileFileName, "r");
  2029. while(getline(&line, &len, fp) != -1)
  2030. {
  2031. json_object *obj = NULL;
  2032. obj = json_tokener_parse(line);
  2033. if(is_error(obj))
  2034. {
  2035. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2036. }
  2037. else
  2038. {
  2039. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2040. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2041. )
  2042. {
  2043. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2044. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2045. )
  2046. {
  2047. struct tm tmFrom, tmTo;
  2048. struct timeb tbFrom, tbTo;
  2049. 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) &&
  2050. (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))
  2051. {
  2052. tmFrom.tm_year -= 1900;
  2053. tmFrom.tm_mon -= 1;
  2054. tbFrom.time = mktime(&tmFrom);
  2055. tmTo.tm_year -= 1900;
  2056. tmTo.tm_mon -= 1;
  2057. tbTo.time = mktime(&tmTo);
  2058. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2059. {
  2060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2061. {
  2062. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2063. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2065. }
  2066. defaultTxProfile.ChargingProfileId = -1;
  2067. defaultTxProfile.StackLevel = -1;
  2068. if(defaultTxProfile.ChargingProfileId == -1)
  2069. DEBUG_INFO("TxDefaultProfile found.\n");
  2070. else
  2071. DEBUG_INFO("TxDefaultProfile updated.\n");
  2072. // Required item
  2073. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2074. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2075. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2076. if(isUnitA)
  2077. {
  2078. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2079. 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++)
  2080. {
  2081. 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"));
  2082. 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?
  2083. 3:
  2084. 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")));
  2085. 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")));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2091. 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++)
  2092. {
  2093. 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"));
  2094. 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?
  2095. 3:
  2096. 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")));
  2097. 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));
  2098. }
  2099. }
  2100. // Optional item
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2110. {
  2111. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2116. }
  2117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2118. {
  2119. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2124. }
  2125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2126. {
  2127. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2128. }
  2129. else
  2130. {
  2131. defaultTxProfile.TransactionId = -1;
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2140. }
  2141. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2142. {
  2143. 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")));
  2144. }
  2145. else
  2146. {
  2147. 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));
  2148. }
  2149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2150. {
  2151. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2152. }
  2153. else
  2154. {
  2155. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2165. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2167. }
  2168. defaultTxProfile.ChargingProfileId = -1;
  2169. defaultTxProfile.StackLevel = -1;
  2170. if(defaultTxProfile.ChargingProfileId == -1)
  2171. DEBUG_INFO("TxDefaultProfile found.\n");
  2172. else
  2173. DEBUG_INFO("TxDefaultProfile updated.\n");
  2174. // Required item
  2175. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2176. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2177. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2178. if(isUnitA)
  2179. {
  2180. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2181. 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++)
  2182. {
  2183. 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"));
  2184. 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?
  2185. 3:
  2186. 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")));
  2187. 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")));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2193. 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++)
  2194. {
  2195. 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"));
  2196. 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?
  2197. 3:
  2198. 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")));
  2199. 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));
  2200. }
  2201. }
  2202. // Optional item
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2204. {
  2205. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2206. }
  2207. else
  2208. {
  2209. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2210. }
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2220. {
  2221. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2228. {
  2229. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.TransactionId = -1;
  2234. }
  2235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2236. {
  2237. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2238. }
  2239. else
  2240. {
  2241. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2244. {
  2245. 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")));
  2246. }
  2247. else
  2248. {
  2249. 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));
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2252. {
  2253. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2254. }
  2255. else
  2256. {
  2257. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. json_object_put(obj);
  2263. }
  2264. fclose(fp);
  2265. /*
  2266. if(defaultTxProfile.ChargingProfileId != -1)
  2267. {
  2268. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2269. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2270. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2271. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2272. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2273. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2274. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2275. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2276. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2277. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2278. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2279. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2280. {
  2281. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2282. {
  2283. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2284. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2285. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2286. }
  2287. }
  2288. }
  2289. else
  2290. DEBUG_INFO("TxDefaultProfile not found.\n");
  2291. DEBUG_INFO("------------------------------------\n");*/
  2292. }
  2293. // Search max profile
  2294. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2295. if((access(profileFileName, F_OK))!=-1)
  2296. {
  2297. fp = fopen(profileFileName, "r");
  2298. while(getline(&line, &len, fp) != -1)
  2299. {
  2300. json_object *obj = NULL;
  2301. obj = json_tokener_parse(line);
  2302. if(is_error(obj))
  2303. {
  2304. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2305. }
  2306. else
  2307. {
  2308. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2309. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2310. )
  2311. {
  2312. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2313. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2314. )
  2315. {
  2316. struct tm tmFrom, tmTo;
  2317. struct timeb tbFrom, tbTo;
  2318. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2319. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2320. {
  2321. tmFrom.tm_year -= 1900;
  2322. tmFrom.tm_mon -= 1;
  2323. tbFrom.time = mktime(&tmFrom);
  2324. tmTo.tm_year -= 1900;
  2325. tmTo.tm_mon -= 1;
  2326. tbTo.time = mktime(&tmTo);
  2327. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2328. {
  2329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2330. {
  2331. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2334. }
  2335. maxProfile.ChargingProfileId = -1;
  2336. maxProfile.StackLevel = -1;
  2337. if(maxProfile.ChargingProfileId == -1)
  2338. DEBUG_INFO("MaxProfile found.\n");
  2339. else
  2340. DEBUG_INFO("MaxProfile updated.\n");
  2341. // Required item
  2342. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2343. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2344. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2345. if(isUnitA)
  2346. {
  2347. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2348. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2349. {
  2350. 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"));
  2351. 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?
  2352. 3:
  2353. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2354. 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")));
  2355. }
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2360. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2361. {
  2362. 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"));
  2363. 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?
  2364. 3:
  2365. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2366. 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));
  2367. }
  2368. }
  2369. // Optional item
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2371. {
  2372. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2373. }
  2374. else
  2375. {
  2376. sprintf((char*)maxProfile.ValidFrom, " ");
  2377. }
  2378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2379. {
  2380. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2381. }
  2382. else
  2383. {
  2384. sprintf((char*)maxProfile.ValidTo, " ");
  2385. }
  2386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2387. {
  2388. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2393. }
  2394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2395. {
  2396. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.TransactionId = -1;
  2401. }
  2402. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2403. {
  2404. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2405. }
  2406. else
  2407. {
  2408. maxProfile.ChargingSchedule.Duration = 86400;
  2409. }
  2410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2411. {
  2412. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2413. }
  2414. else
  2415. {
  2416. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2417. }
  2418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2419. {
  2420. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2421. }
  2422. else
  2423. {
  2424. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. else
  2430. {
  2431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2432. {
  2433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2436. }
  2437. maxProfile.ChargingProfileId = -1;
  2438. maxProfile.StackLevel = -1;
  2439. if(maxProfile.ChargingProfileId == -1)
  2440. DEBUG_INFO("MaxProfile found.\n");
  2441. else
  2442. DEBUG_INFO("MaxProfile updated.\n");
  2443. // Required item
  2444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2447. if(isUnitA)
  2448. {
  2449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2450. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2451. {
  2452. 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"));
  2453. 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?
  2454. 3:
  2455. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2456. 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")));
  2457. }
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2462. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2463. {
  2464. 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"));
  2465. 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?
  2466. 3:
  2467. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2468. 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));
  2469. }
  2470. }
  2471. // Optional item
  2472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2473. {
  2474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2475. }
  2476. else
  2477. {
  2478. sprintf((char*)maxProfile.ValidFrom, " ");
  2479. }
  2480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2481. {
  2482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)maxProfile.ValidTo, " ");
  2487. }
  2488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2489. {
  2490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2495. }
  2496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2497. {
  2498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2499. }
  2500. else
  2501. {
  2502. maxProfile.TransactionId = -1;
  2503. }
  2504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2505. {
  2506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2507. }
  2508. else
  2509. {
  2510. maxProfile.ChargingSchedule.Duration = 86400;
  2511. }
  2512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2513. {
  2514. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2515. }
  2516. else
  2517. {
  2518. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2519. }
  2520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2521. {
  2522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2523. }
  2524. else
  2525. {
  2526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. json_object_put(obj);
  2532. }
  2533. fclose(fp);
  2534. /*
  2535. if(maxProfile.ChargingProfileId !=-1)
  2536. {
  2537. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2538. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2539. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2540. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2541. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2542. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2543. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2544. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2545. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2546. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2547. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2551. {
  2552. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2554. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2555. }
  2556. }
  2557. }
  2558. else
  2559. DEBUG_INFO("MaxProfile not found.\n");
  2560. DEBUG_INFO("------------------------------------\n");*/
  2561. }
  2562. /*
  2563. * Align found profile start schedule & periods
  2564. */
  2565. //DEBUG_INFO("====================================\n");
  2566. /*
  2567. // For local test usage, force modify found profile start schedule info
  2568. 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);
  2569. 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);
  2570. 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);
  2571. */
  2572. if(txProfile.ChargingProfileId != -1)
  2573. {
  2574. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2575. {
  2576. if(txProfile.ChargingSchedule.Duration != -1)
  2577. {
  2578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2579. 0:
  2580. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2581. }
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2587. 0:
  2588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2600. {
  2601. if(txProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. 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?
  2604. 0:
  2605. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. 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?
  2612. 0:
  2613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2614. if(idxPeriod > 0)
  2615. {
  2616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2617. {
  2618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2627. {
  2628. if(txProfile.ChargingSchedule.Duration != -1)
  2629. {
  2630. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2631. 0:
  2632. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2633. }
  2634. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2639. 0:
  2640. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2641. if(idxPeriod > 0)
  2642. {
  2643. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2644. {
  2645. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2646. }
  2647. }
  2648. }
  2649. }
  2650. }
  2651. else
  2652. {
  2653. if(txProfile.ChargingSchedule.Duration != -1)
  2654. {
  2655. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2656. 0:
  2657. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2658. }
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2662. {
  2663. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2664. 0:
  2665. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2666. if(idxPeriod > 0)
  2667. {
  2668. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2669. {
  2670. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. /*
  2678. DEBUG_INFO("txProfile after align.\n");
  2679. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2680. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2681. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2682. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2683. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2684. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2685. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2686. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2687. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2688. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2689. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2690. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2691. {
  2692. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2693. {
  2694. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2695. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2696. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2697. }
  2698. }*/
  2699. }
  2700. if(defaultTxProfile.ChargingProfileId != -1)
  2701. {
  2702. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2703. {
  2704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2707. 0:
  2708. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2709. }
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2718. {
  2719. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2720. }
  2721. if(idxPeriod > 0)
  2722. {
  2723. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2724. {
  2725. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2732. {
  2733. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2734. {
  2735. 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?
  2736. 0:
  2737. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2738. }
  2739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2740. {
  2741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2742. {
  2743. 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?
  2744. 0:
  2745. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2746. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2747. {
  2748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2749. }
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. else
  2761. {
  2762. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2763. {
  2764. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2765. {
  2766. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2769. }
  2770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2771. {
  2772. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2773. {
  2774. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2777. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2778. {
  2779. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2780. }
  2781. if(idxPeriod > 0)
  2782. {
  2783. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2784. {
  2785. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. else
  2792. {
  2793. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2794. {
  2795. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2796. 0:
  2797. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2798. }
  2799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2800. {
  2801. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2802. {
  2803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2804. 0:
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2807. {
  2808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2809. }
  2810. if(idxPeriod > 0)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. /*
  2822. DEBUG_INFO("defaultTxProfile after align.\n");
  2823. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2824. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2825. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2826. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2827. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2828. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2829. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2830. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2831. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2832. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2833. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2834. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2835. {
  2836. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2837. {
  2838. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2839. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2840. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2841. }
  2842. }
  2843. DEBUG_INFO("------------------------------------\n");*/
  2844. }
  2845. if(maxProfile.ChargingProfileId != -1)
  2846. {
  2847. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2848. {
  2849. if(maxProfile.ChargingSchedule.Duration != -1)
  2850. {
  2851. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2852. 0:
  2853. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2854. }
  2855. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2860. 0:
  2861. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2862. if(idxPeriod > 0)
  2863. {
  2864. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2865. {
  2866. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2867. }
  2868. }
  2869. }
  2870. }
  2871. }
  2872. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2873. {
  2874. if(maxProfile.ChargingSchedule.Duration != -1)
  2875. {
  2876. 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?
  2877. 0:
  2878. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2879. }
  2880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2881. {
  2882. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2883. {
  2884. 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?
  2885. 0:
  2886. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2887. if(idxPeriod > 0)
  2888. {
  2889. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2890. {
  2891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2892. }
  2893. }
  2894. }
  2895. }
  2896. }
  2897. else
  2898. {
  2899. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2900. {
  2901. if(maxProfile.ChargingSchedule.Duration != -1)
  2902. {
  2903. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2904. 0:
  2905. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2906. }
  2907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2912. 0:
  2913. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2914. if(idxPeriod > 0)
  2915. {
  2916. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2917. {
  2918. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924. else
  2925. {
  2926. if(maxProfile.ChargingSchedule.Duration != -1)
  2927. {
  2928. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2929. 0:
  2930. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2931. }
  2932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2933. {
  2934. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2935. {
  2936. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2937. 0:
  2938. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2939. if(idxPeriod > 0)
  2940. {
  2941. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2942. {
  2943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. /*
  2951. DEBUG_INFO("MaxProfile after align.\n");
  2952. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2953. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2954. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2955. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2956. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2957. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2958. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2959. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2960. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2961. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2962. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2963. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2964. {
  2965. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2966. {
  2967. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2968. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2969. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2970. }
  2971. }
  2972. DEBUG_INFO("------------------------------------\n");*/
  2973. }
  2974. /*
  2975. * Merge to conposite schedule
  2976. */
  2977. //DEBUG_INFO("====================================\n");
  2978. // Find each profile period quantity
  2979. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2980. {
  2981. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2982. limitMax = idx+1;
  2983. }
  2984. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2985. {
  2986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2987. limitDef = idx+1;
  2988. }
  2989. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2990. {
  2991. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2992. limitTx = idx+1;
  2993. }
  2994. // TxProfile found, composite schedule based on it
  2995. if(txProfile.ChargingProfileId != -1)
  2996. {
  2997. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2998. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2999. {
  3000. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3001. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3002. (txProfile.ChargingSchedule.Duration > 0))
  3003. {
  3004. if(maxProfile.ChargingProfileId != -1)
  3005. {
  3006. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3007. {
  3008. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3009. {
  3010. if((maxProfile.ChargingSchedule.Duration > 0))
  3011. {
  3012. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3013. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3014. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3015. }
  3016. else
  3017. {
  3018. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3019. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3020. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3021. }
  3022. }
  3023. if(idxMaxPeriod == (limitMax-1))
  3024. {
  3025. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3026. {
  3027. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3028. {
  3029. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3030. compositePeriodIdx++;
  3031. }
  3032. else
  3033. {
  3034. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3035. }
  3036. }
  3037. }
  3038. }
  3039. }
  3040. else
  3041. {
  3042. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3043. {
  3044. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3045. compositePeriodIdx++;
  3046. }
  3047. else
  3048. {
  3049. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3050. }
  3051. }
  3052. }
  3053. if(idxTxPeriod == (limitTx-1))
  3054. {
  3055. if(defaultTxProfile.ChargingProfileId != -1)
  3056. {
  3057. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3058. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3059. {
  3060. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3061. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3062. (defaultTxProfile.ChargingSchedule.Duration>0))
  3063. {
  3064. if(maxProfile.ChargingProfileId != -1)
  3065. {
  3066. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3067. {
  3068. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3069. {
  3070. if((maxProfile.ChargingSchedule.Duration > 0))
  3071. {
  3072. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3073. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3074. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3075. }
  3076. else
  3077. {
  3078. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3079. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3080. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3081. }
  3082. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3083. {
  3084. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3085. {
  3086. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3087. compositePeriodIdx++;
  3088. }
  3089. else
  3090. {
  3091. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3092. }
  3093. }
  3094. // Delete duplicate period
  3095. if(compositePeriodIdx > 1)
  3096. {
  3097. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3098. {
  3099. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3100. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3101. compositePeriodIdx -= 1;
  3102. }
  3103. }
  3104. }
  3105. else
  3106. {
  3107. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3108. {
  3109. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3110. compositePeriodIdx++;
  3111. }
  3112. else
  3113. {
  3114. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3115. }
  3116. break;
  3117. }
  3118. }
  3119. }
  3120. else
  3121. {
  3122. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3123. {
  3124. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3125. compositePeriodIdx++;
  3126. }
  3127. else
  3128. {
  3129. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3139. else if(defaultTxProfile.ChargingProfileId != -1)
  3140. {
  3141. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3142. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3143. {
  3144. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3145. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3146. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3147. {
  3148. if(maxProfile.ChargingProfileId != -1)
  3149. {
  3150. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3151. {
  3152. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3153. {
  3154. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3155. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3156. if((maxProfile.ChargingSchedule.Duration > 0))
  3157. {
  3158. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3159. }
  3160. else
  3161. {
  3162. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3163. }
  3164. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3165. {
  3166. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3167. {
  3168. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3169. compositePeriodIdx++;
  3170. }
  3171. else
  3172. {
  3173. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3174. }
  3175. }
  3176. // Delete duplicate period
  3177. if(compositePeriodIdx > 1)
  3178. {
  3179. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3180. {
  3181. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3182. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3183. compositePeriodIdx -= 1;
  3184. }
  3185. }
  3186. }
  3187. else
  3188. {
  3189. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3190. {
  3191. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3192. compositePeriodIdx++;
  3193. }
  3194. else
  3195. {
  3196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3197. }
  3198. break;
  3199. }
  3200. }
  3201. }
  3202. else
  3203. {
  3204. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3205. {
  3206. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3207. compositePeriodIdx++;
  3208. }
  3209. else
  3210. {
  3211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3212. }
  3213. }
  3214. }
  3215. }
  3216. }
  3217. // Fill other period by MaxProfile
  3218. if(maxProfile.ChargingProfileId != -1)
  3219. {
  3220. if(compositePeriodIdx==0)
  3221. {
  3222. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3223. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3224. {
  3225. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3226. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3227. (maxProfile.ChargingSchedule.Duration > 0))
  3228. {
  3229. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3230. {
  3231. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3232. compositePeriodIdx++;
  3233. }
  3234. else
  3235. {
  3236. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. }
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. int lastCompositePeriodIdx = compositePeriodIdx;
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3247. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3248. (maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3251. {
  3252. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3253. {
  3254. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3255. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3256. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3257. }
  3258. else
  3259. {
  3260. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3261. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3262. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3263. }
  3264. }
  3265. if(tmpPeriod.Limit != -1)
  3266. {
  3267. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3268. {
  3269. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3270. {
  3271. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. compositePeriodIdx++;
  3273. }
  3274. else
  3275. {
  3276. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3277. }
  3278. }
  3279. // Delete duplicate period
  3280. if(compositePeriodIdx > 1)
  3281. {
  3282. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3283. {
  3284. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3285. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3286. compositePeriodIdx -= 1;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. compositeProfile->ChargingSchedule.Duration = durationReq;
  3295. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3296. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3297. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3298. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3300. {
  3301. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3302. {
  3303. compositeProfile->ChargingProfileId = 1;
  3304. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3305. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3306. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3307. }
  3308. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3309. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3310. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3311. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3312. }
  3313. if(line)
  3314. free(line);
  3315. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3316. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3317. }
  3318. //==========================================
  3319. // Init all share memory
  3320. //==========================================
  3321. int InitShareMemory()
  3322. {
  3323. int result = PASS;
  3324. int MeterSMId;
  3325. //creat ShmSysConfigAndInfo
  3326. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3327. {
  3328. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3329. result = FAIL;
  3330. }
  3331. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3332. {
  3333. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3334. result = FAIL;
  3335. }
  3336. else
  3337. {}
  3338. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3339. {
  3340. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3341. result = FAIL;
  3342. }
  3343. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3344. {
  3345. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3346. result = FAIL;
  3347. }
  3348. else
  3349. {}
  3350. //creat ShmPsuData
  3351. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3352. {
  3353. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3354. result = FAIL;
  3355. }
  3356. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3357. {
  3358. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3359. result = FAIL;
  3360. }
  3361. else
  3362. {}
  3363. //creat ShmOCPP16Data
  3364. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3365. {
  3366. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3367. result = FAIL;
  3368. }
  3369. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3370. {
  3371. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3372. result = FAIL;
  3373. }
  3374. else
  3375. {}
  3376. /****************************** For Initial Settings************************************************/
  3377. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3379. // allocate Configuration memory address
  3380. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3381. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3382. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3383. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3384. //offline MeterValue Interval
  3385. TempMeterValueInterval = 0;
  3386. return result;
  3387. }
  3388. int ProcessShareMemory()
  3389. {
  3390. int result = PASS;
  3391. ParsingRatedCur modelnameInfo={0};
  3392. if(InitShareMemory() == FAIL)
  3393. {
  3394. DEBUG_ERROR("InitShareMemory NG\n");
  3395. if(ShmStatusCodeData!=NULL)
  3396. {
  3397. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3398. }
  3399. result = FAIL;
  3400. }
  3401. // Model name parsing
  3402. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3403. {
  3404. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3405. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3406. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3407. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3408. ) // 'D' means DC
  3409. {
  3410. // DO series
  3411. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3412. {
  3413. SystemInitial += 1;
  3414. gunTotalNumber += 1;
  3415. gunType[gun_index] = GUN_TYPE_DO;
  3416. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3417. {
  3418. case Gun_Type_Chademo:
  3419. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3420. break;
  3421. case Gun_Type_CCS_2:
  3422. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3423. break;
  3424. case Gun_Type_GB:
  3425. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3426. break;
  3427. case Gun_Type_AC:
  3428. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3429. break;
  3430. default:
  3431. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3432. break;
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3439. {
  3440. SystemInitial += 1;
  3441. gunTotalNumber += 1;
  3442. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3443. {
  3444. case Gun_Type_Chademo:
  3445. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3446. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3447. break;
  3448. case Gun_Type_CCS_2:
  3449. gunType[gun_index] = GUN_TYPE_CCS;
  3450. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3451. break;
  3452. case Gun_Type_GB:
  3453. gunType[gun_index] = GUN_TYPE_GBT;
  3454. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3455. break;
  3456. case Gun_Type_AC:
  3457. gunType[gun_index] = GUN_TYPE_AC;
  3458. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3459. break;
  3460. default:
  3461. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3462. break;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. else
  3468. {
  3469. DEBUG_ERROR("Model name parsing fail.\n");
  3470. result = FAIL;
  3471. }
  3472. if(result != PASS)sleep(5);
  3473. return result;
  3474. }
  3475. void CheckSystemValue(void)
  3476. {
  3477. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3478. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3479. char filenmae[100]={0};
  3480. char str[100]={0};
  3481. int tempIndex = 0;
  3482. //===============================
  3483. // send Heartbeat
  3484. //===============================
  3485. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3486. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3487. {
  3488. clientTime.Heartbeat=time((time_t*)NULL);
  3489. if(server_sign == TRUE)
  3490. {
  3491. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3492. }
  3493. else
  3494. {
  3495. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3496. }
  3497. }
  3498. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3499. {
  3500. //parameter for test
  3501. sendHeartbeatRequest(0);
  3502. //==============================================
  3503. // Reset Waiting Time
  3504. //==============================================
  3505. HeartBeatWithNOResponse += 1;
  3506. }
  3507. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3508. {
  3509. //==========================================
  3510. // csu trigger DataTransferReq
  3511. //==========================================
  3512. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3513. {
  3514. sendDataTransferRequest(gun_index);
  3515. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3516. }
  3517. //===============================
  3518. // CSU Trigger Authorize Request
  3519. //===============================
  3520. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3521. {
  3522. sendAuthorizeRequest(0);
  3523. authorizeRetryTimes = authorizeRetryTimes + 1;
  3524. if(authorizeRetryTimes < 3)
  3525. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3526. }
  3527. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3528. {
  3529. authorizeRetryTimes = 0;
  3530. SetOcppConnStatus(FALSE);
  3531. server_sign = FALSE;
  3532. }
  3533. 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))
  3534. {
  3535. sendAuthorizeRequest(0);
  3536. }
  3537. //==============================================
  3538. // Charger start transaction
  3539. //==============================================
  3540. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3541. {
  3542. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3543. sendStartTransactionRequest(gun_index);
  3544. clientTime.StartTransaction = time((time_t*)NULL);
  3545. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3546. storeTempStopTransaction(gun_index);
  3547. }
  3548. //==============================================
  3549. // Charger stop transaction
  3550. //==============================================
  3551. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3552. {
  3553. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3554. sendStopTransactionRequest(gun_index);
  3555. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3556. clientTime.StopTransaction = time((time_t*)NULL);
  3557. }
  3558. //==============================================
  3559. // Charger status report
  3560. //==============================================
  3561. //--- Check Mode Change ---//
  3562. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3564. {
  3565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3566. {
  3567. tempIndex = ((gun_index==2) ? 1: 0);
  3568. }
  3569. else
  3570. {
  3571. tempIndex = gun_index;
  3572. }
  3573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3574. {
  3575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3576. {
  3577. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3578. {
  3579. // Sent unplug message for California pricing logic
  3580. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3581. {
  3582. uint8_t ts[20];
  3583. getNowDatetime(ts);
  3584. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3587. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3588. }
  3589. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3590. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3591. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3592. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3593. {
  3594. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3595. if((access(filenmae,F_OK))!=-1)
  3596. {
  3597. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3598. sprintf(str,"rm -f %s",filenmae);
  3599. system(str);
  3600. }
  3601. }
  3602. }
  3603. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3604. #if 1 // for TempStopTransaction
  3605. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3606. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3607. {
  3608. checkTempStopTransaction(gun_index);
  3609. }
  3610. #endif
  3611. }
  3612. }
  3613. }
  3614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3615. {
  3616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3617. {
  3618. tempIndex = ((gun_index==2) ? 1: 0);
  3619. }
  3620. else
  3621. {
  3622. tempIndex = gun_index;
  3623. }
  3624. for (int index = 0; index < CCS_QUANTITY; index++)
  3625. {
  3626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3627. {
  3628. 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]*/ )
  3629. {
  3630. // Sent unplug message for California pricing logic
  3631. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3632. {
  3633. uint8_t ts[20];
  3634. getNowDatetime(ts);
  3635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3639. }
  3640. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3641. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3643. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3644. {
  3645. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3646. if((access(filenmae,F_OK))!=-1)
  3647. {
  3648. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3649. sprintf(str,"rm -f %s",filenmae);
  3650. system(str);
  3651. }
  3652. }
  3653. }
  3654. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3655. #if 1 // for TempStopTransaction
  3656. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3657. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3658. {
  3659. checkTempStopTransaction(gun_index);
  3660. }
  3661. #endif
  3662. }
  3663. }
  3664. }
  3665. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3666. {
  3667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3668. {
  3669. tempIndex = ((gun_index==2) ? 1: 0);
  3670. }
  3671. else
  3672. {
  3673. tempIndex = gun_index;
  3674. }
  3675. for (int index = 0; index < GB_QUANTITY; index++)
  3676. {
  3677. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3678. {
  3679. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3680. {
  3681. // Sent unplug message for California pricing logic
  3682. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3683. {
  3684. uint8_t ts[20];
  3685. getNowDatetime(ts);
  3686. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3687. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3688. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3689. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3690. }
  3691. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3692. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3693. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3694. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3695. {
  3696. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3697. if((access(filenmae,F_OK))!=-1)
  3698. {
  3699. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3700. sprintf(str,"rm -f %s",filenmae);
  3701. system(str);
  3702. }
  3703. }
  3704. }
  3705. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3706. #if 1 // for TempStopTransaction
  3707. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3708. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3709. {
  3710. checkTempStopTransaction(gun_index);
  3711. }
  3712. #endif
  3713. }
  3714. }
  3715. }
  3716. else if(gunType[gun_index] == GUN_TYPE_DO)
  3717. {
  3718. tempIndex = gun_index;
  3719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3720. {
  3721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3722. {
  3723. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3724. {
  3725. // Sent unplug message for California pricing logic
  3726. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3727. {
  3728. uint8_t ts[20];
  3729. getNowDatetime(ts);
  3730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3731. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3732. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3733. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3734. }
  3735. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3736. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3737. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3738. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3739. {
  3740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3741. if((access(filenmae,F_OK))!=-1)
  3742. {
  3743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3744. sprintf(str,"rm -f %s",filenmae);
  3745. system(str);
  3746. }
  3747. }
  3748. }
  3749. 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);
  3750. #if 1 // for TempStopTransaction
  3751. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3752. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3753. {
  3754. checkTempStopTransaction(gun_index);
  3755. }
  3756. #endif
  3757. }
  3758. }
  3759. }
  3760. else
  3761. {
  3762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3763. {
  3764. tempIndex = 2;
  3765. }
  3766. else
  3767. {
  3768. tempIndex = gun_index;
  3769. }
  3770. for (int index = 0; index < AC_QUANTITY; index++)
  3771. {
  3772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3773. {
  3774. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3775. {
  3776. // Sent unplug message for California pricing logic
  3777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3778. {
  3779. uint8_t ts[20];
  3780. getNowDatetime(ts);
  3781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3782. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3783. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3784. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3785. }
  3786. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3787. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3788. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3789. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3790. {
  3791. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3792. if((access(filenmae,F_OK))!=-1)
  3793. {
  3794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3795. sprintf(str,"rm -f %s",filenmae);
  3796. system(str);
  3797. }
  3798. }
  3799. }
  3800. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3801. #if 1 // for TempStopTransaction
  3802. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3803. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3804. {
  3805. checkTempStopTransaction(gun_index);
  3806. }
  3807. #endif
  3808. }
  3809. }// END
  3810. }
  3811. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3812. (
  3813. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3814. )
  3815. )
  3816. {
  3817. if(SystemInitial > 0)
  3818. SystemInitial -= 1;
  3819. sendStatusNotificationRequest(gun_index);
  3820. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3821. }
  3822. //==============================================
  3823. // CSU Trigger Smart Charging Profilw
  3824. //==============================================
  3825. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3826. {
  3827. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3828. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3829. }
  3830. //==============================================
  3831. // Meter report
  3832. //==============================================
  3833. // Trigger MeterValue
  3834. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3835. {
  3836. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3837. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3838. }
  3839. // ClockAlign MeterValue
  3840. 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))
  3841. {
  3842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3843. {
  3844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3845. {
  3846. tempIndex = ((gun_index==2) ? 1: 0);
  3847. }
  3848. else
  3849. {
  3850. tempIndex = gun_index;
  3851. }
  3852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3853. {
  3854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3855. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3856. {
  3857. reqClockAlignMeter[gun_index] = 1;
  3858. }
  3859. }// End for CHAdeMO
  3860. }
  3861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3862. {
  3863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3864. {
  3865. tempIndex = ((gun_index==2) ? 1: 0);
  3866. }
  3867. else
  3868. {
  3869. tempIndex = gun_index;
  3870. }
  3871. for (int index = 0; index < CCS_QUANTITY; index++)
  3872. {
  3873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3874. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3875. {
  3876. reqClockAlignMeter[gun_index] = 1;
  3877. }
  3878. } // End for CCS
  3879. }
  3880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3883. {
  3884. tempIndex = ((gun_index==2) ? 1: 0);
  3885. }
  3886. else
  3887. {
  3888. tempIndex = gun_index;
  3889. }
  3890. for (int index = 0; index < GB_QUANTITY; index++)
  3891. {
  3892. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3893. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3894. {
  3895. reqClockAlignMeter[gun_index] = 1;
  3896. }
  3897. }// End for GB
  3898. }
  3899. else if(gunType[gun_index] == GUN_TYPE_DO)
  3900. {
  3901. tempIndex = gun_index;
  3902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3903. {
  3904. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3905. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3906. {
  3907. reqClockAlignMeter[gun_index] = 1;
  3908. }
  3909. }
  3910. }
  3911. else
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3914. {
  3915. tempIndex = 2;
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < AC_QUANTITY; index++)
  3922. {
  3923. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3924. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3925. {
  3926. reqClockAlignMeter[gun_index] = 1;
  3927. }
  3928. }//End for AC
  3929. }
  3930. if(reqClockAlignMeter[gun_index] == 1)
  3931. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3932. }
  3933. // Sample period MeterValue
  3934. 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))))
  3935. {
  3936. //check Transaction active
  3937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3938. {
  3939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3940. {
  3941. tempIndex = ((gun_index==2) ? 1: 0);
  3942. }
  3943. else
  3944. {
  3945. tempIndex = gun_index;
  3946. }
  3947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3948. {
  3949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3950. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3951. {
  3952. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3953. {
  3954. reqSampleMeter[gun_index] = 1;
  3955. }
  3956. }
  3957. }// End for CHAdeMO
  3958. }
  3959. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3960. {
  3961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3962. {
  3963. tempIndex = ((gun_index==2) ? 1: 0);
  3964. }
  3965. else
  3966. {
  3967. tempIndex = gun_index;
  3968. }
  3969. for (int index = 0; index < CCS_QUANTITY; index++)
  3970. {
  3971. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3973. {
  3974. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3975. {
  3976. reqSampleMeter[gun_index] = 1;
  3977. }
  3978. }
  3979. } // End for CCS
  3980. }
  3981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < GB_QUANTITY; index++)
  3992. {
  3993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3997. {
  3998. reqSampleMeter[gun_index] = 1;
  3999. }
  4000. }
  4001. }// End for GB
  4002. }
  4003. else if(gunType[gun_index] == GUN_TYPE_DO)
  4004. {
  4005. tempIndex = gun_index;
  4006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4007. {
  4008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4009. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4010. {
  4011. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4012. {
  4013. reqSampleMeter[gun_index] = 1;
  4014. }
  4015. }
  4016. }
  4017. }
  4018. else
  4019. {
  4020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4021. {
  4022. tempIndex = 2;
  4023. }
  4024. else
  4025. {
  4026. tempIndex = gun_index;
  4027. }
  4028. for (int index = 0; index < AC_QUANTITY; index++)
  4029. {
  4030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4031. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4032. {
  4033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4034. {
  4035. reqSampleMeter[gun_index] = 1;
  4036. }
  4037. }
  4038. }//End for AC
  4039. }
  4040. if(reqSampleMeter[gun_index] == 1)
  4041. {
  4042. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4043. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4044. storeTempStopTransaction(gun_index);
  4045. }
  4046. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4047. }
  4048. //==============================================
  4049. // Check Connector reserved
  4050. //==============================================
  4051. //===============================
  4052. // Check if Reserve is expired
  4053. //===============================
  4054. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4055. {
  4056. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4057. {
  4058. DEBUG_INFO("reserve expired.\n");
  4059. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4060. }
  4061. }//END OF Check if Reserve is expired
  4062. //==========================================
  4063. // csu trigger FirmwareStatusNotificationReq
  4064. //==========================================
  4065. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4066. {
  4067. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4068. }
  4069. //==========================================
  4070. // csu trigger DiagnosticsStatusNotificationReq
  4071. //==========================================
  4072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4073. {
  4074. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4075. }
  4076. //==========================================
  4077. // csu trigger CancelReservationConf
  4078. //==========================================
  4079. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4080. {
  4081. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4082. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4083. }
  4084. //==========================================
  4085. // csu trigger ChangeAvailabilityConf
  4086. //==========================================
  4087. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4088. {
  4089. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4090. }
  4091. //==========================================
  4092. // csu trigger UnlockConnectorConf
  4093. //==========================================
  4094. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4095. {
  4096. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4097. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4098. }
  4099. //==========================================
  4100. // csu trigger ReserveNowConf
  4101. //==========================================
  4102. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4103. {
  4104. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4105. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4106. }
  4107. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4108. {
  4109. sendSignCertificateRequest();
  4110. }
  4111. }
  4112. }
  4113. //==========================================
  4114. // send request routine
  4115. //==========================================
  4116. int sendAuthorizeRequest(int gun_index)
  4117. {
  4118. mtrace();
  4119. int result = FAIL;
  4120. char message[100]={0};
  4121. char guid[37];
  4122. char tempdata[65]={0};
  4123. DEBUG_INFO("sendAuthorizeRequest...\n");
  4124. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4125. //Local Authorize
  4126. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4127. {
  4128. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4130. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4131. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4132. result = PASS;
  4133. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4134. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4135. authorizeRetryTimes = 0;
  4136. return result;
  4137. }
  4138. 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))||
  4139. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4140. {
  4141. // Query from cache
  4142. DEBUG_INFO("Authorize from cache.\n");
  4143. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4144. // Query from list
  4145. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4146. {
  4147. DEBUG_INFO("Authorize from list.\n");
  4148. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4149. }
  4150. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4151. {
  4152. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4153. {
  4154. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4155. }
  4156. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4157. {
  4158. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4159. }
  4160. if(!GetOcppConnStatus())
  4161. {
  4162. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4163. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4164. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4165. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4166. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4167. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4168. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4169. authorizeRetryTimes = 0;
  4170. return result;
  4171. }
  4172. }
  4173. else
  4174. {
  4175. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4176. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4177. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4178. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4179. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4180. else
  4181. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4182. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4183. result = PASS;
  4184. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4185. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4186. authorizeRetryTimes = 0;
  4187. return result;
  4188. }
  4189. }
  4190. //initialize struct Authorize
  4191. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4192. //get data from shared memory
  4193. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4194. random_uuid(guid);
  4195. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4196. LWS_Send(message);
  4197. sprintf(tempdata, "Authorize,%d", gun_index);
  4198. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4199. {
  4200. result = PASS;
  4201. DEBUG_INFO("Authorize mapItem pass\n");
  4202. }
  4203. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4204. return result;
  4205. }
  4206. int sendBootNotificationRequest(void)
  4207. {
  4208. mtrace();
  4209. int result = FAIL;
  4210. char message[500]={0}, payload[700]={0};
  4211. char guid[37]={0};
  4212. char tempdata[65]={0};
  4213. // Fill BootNotification fields
  4214. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4215. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4216. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4217. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4218. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4219. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4220. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4221. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4222. ShmOCPP16Data->ChargeBoxId
  4223. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4224. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4225. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4226. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4227. ,ShmOCPP16Data->BootNotification.CpIccid
  4228. ,ShmOCPP16Data->BootNotification.CpImsi);
  4229. random_uuid(guid);
  4230. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4231. LWS_Send(message);
  4232. sprintf(tempdata, "BootNotification,0");
  4233. 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*/)
  4234. {
  4235. result = PASS;
  4236. }
  4237. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4238. strcpy(queuedata,message);
  4239. return result;
  4240. }
  4241. int sendDataTransferRequest(int gun_index)
  4242. {
  4243. mtrace();
  4244. char message[1000]={0};
  4245. char guid[37]={0};
  4246. char tempdata[65]={0};
  4247. int result = FAIL;
  4248. random_uuid(guid);
  4249. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4250. MESSAGE_TYPE_CALL,
  4251. guid,
  4252. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4253. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4254. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4255. LWS_Send(message);
  4256. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4257. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4258. {
  4259. result = PASS;
  4260. DEBUG_INFO("DataTransfer mapItem pass\n");
  4261. }
  4262. return result;
  4263. }
  4264. int sendDiagnosticsStatusNotificationRequest(char *status)
  4265. {
  4266. mtrace();
  4267. int result = FAIL;
  4268. char message[110]={0};
  4269. char guid[37]={0};
  4270. char tempdata[65]={0};
  4271. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4272. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4273. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4274. random_uuid(guid);
  4275. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4276. LWS_SendNow(message);
  4277. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4278. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4279. {
  4280. result = PASS;
  4281. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4282. }
  4283. //#ifdef SystemLogMessage
  4284. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4285. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4286. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4287. //#endif
  4288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4289. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4290. //record status
  4291. if(strcmp(status,"Idle")==0)
  4292. {
  4293. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4294. }
  4295. else if(strcmp(status,"Uploaded")==0)
  4296. {
  4297. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4298. }
  4299. else if(strcmp(status,"UploadFailed")==0)
  4300. {
  4301. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4302. }
  4303. else if(strcmp(status,"Uploading")==0)
  4304. {
  4305. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4306. }
  4307. return result;
  4308. }
  4309. int sendFirmwareStatusNotificationRequest(char *status)
  4310. {
  4311. mtrace();
  4312. int result = FAIL;
  4313. char message[110]={0};
  4314. char guid[37]={0};
  4315. char tempdata[65]={0};
  4316. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4317. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4318. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4319. random_uuid(guid);
  4320. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4321. LWS_SendNow(message);
  4322. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4323. 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*/)
  4324. {
  4325. result = PASS;
  4326. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4327. }
  4328. //#ifdef SystemLogMessage
  4329. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4330. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4331. //#endif
  4332. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4333. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4334. //record status
  4335. if(strcmp(status,"Downloaded")==0)
  4336. {
  4337. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4338. }
  4339. else if(strcmp(status,"DownloadFailed")==0)
  4340. {
  4341. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4342. }
  4343. else if(strcmp(status,"Downloading")==0)
  4344. {
  4345. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4346. }
  4347. else if(strcmp(status,"Idle")==0)
  4348. {
  4349. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4350. }
  4351. else if(strcmp(status,"InstallationFailed")==0)
  4352. {
  4353. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4354. }
  4355. else if(strcmp(status,"Installing")==0)
  4356. {
  4357. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4358. }
  4359. else if(strcmp(status,"Installed")==0)
  4360. {
  4361. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4362. }
  4363. return result;
  4364. }
  4365. int sendHeartbeatRequest(int gun_index)
  4366. {
  4367. mtrace();
  4368. int result = FAIL;
  4369. char message[80]={0};
  4370. char guid[37]={0};
  4371. char tempdata[65]={0};
  4372. random_uuid(guid);
  4373. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4374. , MESSAGE_TYPE_CALL
  4375. , guid );
  4376. LWS_Send(message);
  4377. sprintf(tempdata, "Heartbeat,%d", 0);
  4378. 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*/)
  4379. {
  4380. result = PASS;
  4381. }
  4382. return result;
  4383. }
  4384. int sendStartTransactionRequest(int gun_index)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. char message[250]={0};
  4389. char guid[37]={0};
  4390. struct timeval tmnow;
  4391. struct tm *tm;
  4392. char buf[28];//, usec_buf[6];
  4393. char tempdata[65]={0};
  4394. int tempIndex = 0;
  4395. DEBUG_INFO("sendStartTransactionRequest...\n");
  4396. gettimeofday(&tmnow, NULL);
  4397. time_t t;
  4398. t = time(NULL);
  4399. /*UTC time and date*/
  4400. tm = gmtime(&t);
  4401. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4402. #if 0 // remove temporally
  4403. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4404. strcat(buf,".");
  4405. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4406. strcat(buf,usec_buf);
  4407. #endif
  4408. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4409. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4410. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4411. // clear StartTransaction Response
  4412. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4413. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4414. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4415. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4416. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4429. {
  4430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4431. {
  4432. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4433. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4434. }
  4435. }
  4436. }
  4437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4440. {
  4441. tempIndex = ((gun_index==2) ? 1: 0);
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < CCS_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4450. {
  4451. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4452. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4453. }
  4454. }
  4455. }
  4456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4459. {
  4460. tempIndex = ((gun_index==2) ? 1: 0);
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < GB_QUANTITY; index++)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4469. {
  4470. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4471. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4472. }
  4473. }
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_DO)
  4476. {
  4477. tempIndex = gun_index;
  4478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4481. {
  4482. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4483. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4484. }
  4485. }
  4486. }
  4487. else
  4488. {
  4489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4490. {
  4491. tempIndex = 2;
  4492. }
  4493. else
  4494. {
  4495. tempIndex = gun_index;
  4496. }
  4497. for (int index = 0; index < AC_QUANTITY; index++)
  4498. {
  4499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4500. {
  4501. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4502. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4503. }
  4504. }
  4505. }
  4506. random_uuid(guid);
  4507. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4508. {
  4509. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4510. , gun_index +1
  4511. , MESSAGE_TYPE_CALL
  4512. , guid
  4513. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4514. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4515. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4516. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4517. }
  4518. else
  4519. {
  4520. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4521. , gun_index +1
  4522. , MESSAGE_TYPE_CALL
  4523. , guid
  4524. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4525. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4526. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4527. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4528. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4529. }
  4530. #if 1
  4531. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4532. 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*/)
  4533. {
  4534. result = PASS;
  4535. }
  4536. #endif
  4537. strcpy(queuedata, message);
  4538. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4539. OCPP_insert_transaction_msg(YES, queuedata);
  4540. return result;
  4541. }
  4542. int sendStatusNotificationRequest(int gun_index)
  4543. {
  4544. mtrace();
  4545. int result = FAIL;
  4546. char message[600]={0};
  4547. char guid[37];
  4548. int currentStatus = 0;
  4549. struct timeval tmnow;
  4550. struct tm *tm;
  4551. char buf[28];//, usec_buf[6];
  4552. char tempdata[65]={0};
  4553. int tempIndex = 0;
  4554. uint8_t isStateChanged = TRUE;
  4555. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4556. gettimeofday(&tmnow, NULL);
  4557. time_t t;
  4558. t = time(NULL);
  4559. /*UTC time and date*/
  4560. tm = gmtime(&t);
  4561. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4562. #if 0 // remove temporally
  4563. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4564. strcat(buf,".");
  4565. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4566. strcat(buf,usec_buf);
  4567. #endif
  4568. //printf("%s",buf);
  4569. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4570. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4571. // it's option
  4572. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4573. /*
  4574. enum _SYSTEM_STATUS
  4575. {
  4576. S_BOOTING = 0,
  4577. S_IDLE, = 1
  4578. S_AUTHORIZING, =2
  4579. S_REASSIGN_CHECK, =3
  4580. S_REASSIGN, =4
  4581. S_PRECHARGE, =5
  4582. S_PREPARING_FOR_EV, =6
  4583. S_PREPARING_FOR_EVSE, =7
  4584. S_CHARGING, =8
  4585. S_TERMINATING, =9
  4586. S_COMPLETE, =10
  4587. S_ALARM, =11
  4588. S_FAULT =12
  4589. }
  4590. */
  4591. //check Transaction active
  4592. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4594. {
  4595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4596. {
  4597. tempIndex = ((gun_index==2) ? 1: 0);
  4598. }
  4599. else
  4600. {
  4601. tempIndex = gun_index;
  4602. }
  4603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4604. {
  4605. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4606. {
  4607. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4608. {
  4609. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4610. {
  4611. currentStatus = Preparing; //OCPP Status: Preparing
  4612. }
  4613. else
  4614. {
  4615. currentStatus = Available; //OCPP Status: Available
  4616. }
  4617. }
  4618. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4619. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4620. ) //S_PRECHARGE
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4625. {
  4626. currentStatus = Charging; //OCPP Status: Charging
  4627. }
  4628. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4629. {
  4630. currentStatus = Finishing; //OCPP Status: Finishing
  4631. }
  4632. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4633. {
  4634. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4635. }
  4636. 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
  4637. {
  4638. currentStatus = Unavailable; //OCPP Status: Unavailable
  4639. }
  4640. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4641. {
  4642. currentStatus = Faulted; //OCPP Status: Faulted
  4643. }
  4644. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4645. {
  4646. currentStatus = Reserved; //OCPP Status: Reserved
  4647. }
  4648. } //end of the same index
  4649. }//end of for CHAdeMO_QUANTITY
  4650. }
  4651. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4652. {
  4653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4654. {
  4655. tempIndex = ((gun_index==2) ? 1: 0);
  4656. }
  4657. else
  4658. {
  4659. tempIndex = gun_index;
  4660. }
  4661. for (int index = 0; index < CCS_QUANTITY; index++)
  4662. {
  4663. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4664. {
  4665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4666. {
  4667. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4668. {
  4669. currentStatus = Preparing; //OCPP Status: Preparing
  4670. }
  4671. else
  4672. {
  4673. currentStatus = Available; //OCPP Status: Available
  4674. }
  4675. }
  4676. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4677. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4678. ) //S_PRECHARGE
  4679. {
  4680. currentStatus = Preparing; //OCPP Status: Preparing
  4681. }
  4682. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4683. {
  4684. currentStatus = Charging; //OCPP Status: Charging
  4685. }
  4686. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4687. {
  4688. currentStatus = Finishing; //OCPP Status: Finishing
  4689. }
  4690. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4691. {
  4692. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4693. }
  4694. 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
  4695. {
  4696. currentStatus = Unavailable; //OCPP Status : Unavailable
  4697. }
  4698. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4699. {
  4700. currentStatus = Faulted; //OCPP Status: Faulted
  4701. }
  4702. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4703. {
  4704. currentStatus = Reserved; //OCPP Status: Reserved
  4705. }
  4706. } //end of the same index
  4707. } // end of for CCS_QUANTITY
  4708. }
  4709. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4710. {
  4711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4712. {
  4713. tempIndex = ((gun_index==2) ? 1: 0);
  4714. }
  4715. else
  4716. {
  4717. tempIndex = gun_index;
  4718. }
  4719. for (int index = 0; index < GB_QUANTITY; index++)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4722. {
  4723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4724. {
  4725. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4726. {
  4727. currentStatus = Preparing; //OCPP Status: Preparing
  4728. }
  4729. else
  4730. {
  4731. currentStatus = Available; //OCPP Status: Available
  4732. }
  4733. }
  4734. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4735. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4736. ) //S_PRECHARGE
  4737. {
  4738. currentStatus = Preparing; //OCPP Status: Preparing
  4739. }
  4740. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4741. {
  4742. currentStatus = Charging; //OCPP Status: Charging
  4743. }
  4744. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4745. {
  4746. currentStatus = Finishing; //OCPP Status: Finishing
  4747. }
  4748. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4749. {
  4750. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4751. }
  4752. 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
  4753. {
  4754. currentStatus = Unavailable; //OCPP Status: Unavailable
  4755. }
  4756. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4757. {
  4758. currentStatus = Faulted; //OCPP Status: Faulted
  4759. }
  4760. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4761. {
  4762. currentStatus = Reserved; //OCPP Status: Reserved
  4763. }
  4764. } //end of the same index
  4765. } // end of for GB_QUANTITY
  4766. }
  4767. else if(gunType[gun_index] == GUN_TYPE_DO)
  4768. {
  4769. tempIndex = gun_index;
  4770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4771. {
  4772. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4775. {
  4776. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4777. {
  4778. currentStatus = Preparing; //OCPP Status: Preparing
  4779. }
  4780. else
  4781. {
  4782. currentStatus = Available; //OCPP Status: Available
  4783. }
  4784. }
  4785. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4786. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4787. ) //S_PRECHARGE
  4788. {
  4789. currentStatus = Preparing; //OCPP Status: Preparing
  4790. }
  4791. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4792. {
  4793. currentStatus = Charging; //OCPP Status: Charging
  4794. }
  4795. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4796. {
  4797. currentStatus = Finishing; //OCPP Status: Finishing
  4798. }
  4799. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4800. {
  4801. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4802. }
  4803. 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
  4804. {
  4805. currentStatus = Unavailable; //OCPP Status: Unavailable
  4806. }
  4807. 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
  4808. {
  4809. currentStatus = Faulted; //OCPP Status: Faulted
  4810. }
  4811. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4812. {
  4813. currentStatus = Reserved; //OCPP Status: Reserved
  4814. }
  4815. } //end of the same index
  4816. }
  4817. }
  4818. else
  4819. {
  4820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4821. {
  4822. tempIndex = 2;
  4823. }
  4824. else
  4825. {
  4826. tempIndex = gun_index;
  4827. }
  4828. for (int index = 0; index < AC_QUANTITY; index++)
  4829. {
  4830. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4831. {
  4832. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4833. {
  4834. 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))
  4835. {
  4836. currentStatus = Preparing; //OCPP Status: Preparing
  4837. }
  4838. else
  4839. {
  4840. currentStatus = Available; //OCPP Status: Available
  4841. }
  4842. }
  4843. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4844. {
  4845. currentStatus = Preparing; //OCPP Status: Preparing
  4846. }
  4847. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4848. {
  4849. currentStatus = Charging; //OCPP Status: Charging
  4850. }
  4851. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4852. {
  4853. currentStatus = Finishing; //OCPP Status: Finishing
  4854. }
  4855. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4856. {
  4857. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4858. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4859. else
  4860. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4861. }
  4862. 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
  4863. {
  4864. currentStatus = Unavailable; //OCPP Status: Unavailable
  4865. }
  4866. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4867. {
  4868. currentStatus = Faulted; //OCPP Status: Faulted
  4869. }
  4870. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4871. {
  4872. currentStatus = Reserved; //OCPP Status: Reserved
  4873. }
  4874. }//end of the same index
  4875. }//end of for AC_QUANTITY
  4876. }
  4877. //it's option
  4878. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4879. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4880. {
  4881. isStateChanged = FALSE;
  4882. }
  4883. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4884. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4885. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4886. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4887. random_uuid(guid);
  4888. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4889. , MESSAGE_TYPE_CALL
  4890. , guid
  4891. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4892. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4893. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4894. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4895. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4896. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4897. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4898. if((server_sign == TRUE) && isStateChanged)
  4899. {
  4900. LWS_Send(message);
  4901. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4902. 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*/)
  4903. {
  4904. //DEBUG_ERROR("statusNotification mapitem pass");
  4905. result = PASS;
  4906. }
  4907. }
  4908. else
  4909. {
  4910. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4911. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4912. result = PASS;
  4913. }
  4914. return result;
  4915. }
  4916. int sendStopTransactionRequest(int gun_index)
  4917. {
  4918. mtrace();
  4919. int result = FAIL;
  4920. //char message[1500]={0};
  4921. char guid[37]={0};
  4922. char tempdata[65]={0};
  4923. int tempIndex = 0;
  4924. char TempStopTransaction[256];
  4925. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4926. //int idx_sample=0;
  4927. DEBUG_INFO("sendStopTransactionRequest \n");
  4928. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4929. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4930. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4935. {
  4936. tempIndex = ((gun_index==2) ? 1: 0);
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4943. {
  4944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4945. {
  4946. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4947. }
  4948. }// END OF CHAdeMO_QUANTITY
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < CCS_QUANTITY; index++)
  4961. {
  4962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4963. {
  4964. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4965. }
  4966. }// END OF CCS_QUANTITY
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4969. {
  4970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4971. {
  4972. tempIndex = ((gun_index==2) ? 1: 0);
  4973. }
  4974. else
  4975. {
  4976. tempIndex = gun_index;
  4977. }
  4978. for (int index = 0; index < GB_QUANTITY; index++)
  4979. {
  4980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4981. {
  4982. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4983. }
  4984. }// END OF GB_QUANTITY
  4985. }
  4986. else if(gunType[gun_index] == GUN_TYPE_DO)
  4987. {
  4988. tempIndex = gun_index;
  4989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4992. {
  4993. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4994. }
  4995. }// END OF GB_QUANTITY
  4996. }
  4997. else
  4998. {
  4999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5000. {
  5001. tempIndex = 2;
  5002. }
  5003. else
  5004. {
  5005. tempIndex = gun_index;
  5006. }
  5007. for (int index = 0; index < AC_QUANTITY; index++)
  5008. {
  5009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5010. {
  5011. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5012. }
  5013. }// END OF AC_QUANTITY
  5014. }
  5015. //====================================== Stop Transaction Time =====================================================
  5016. struct timeval tmnow;
  5017. struct tm *tm;
  5018. char buf[28];//, usec_buf[6];
  5019. gettimeofday(&tmnow, NULL);
  5020. time_t t;
  5021. t = time(NULL);
  5022. /*UTC time and date*/
  5023. tm = gmtime(&t);
  5024. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5026. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5027. random_uuid(guid);
  5028. /***********************************transactionData******************************************************/
  5029. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5031. //=================================
  5032. // Transaction_Begin
  5033. //=================================
  5034. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5035. {
  5036. //============================================ Energy.Active.Import.Interval ================================
  5037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5040. 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*/]);
  5041. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5042. 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))
  5043. {
  5044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5045. }
  5046. else
  5047. {
  5048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5049. }
  5050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5052. }
  5053. //=================================
  5054. // Transaction_End
  5055. //=================================
  5056. // ================================= Current.Import L1 ===============================================
  5057. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5058. {
  5059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5061. {
  5062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5063. {
  5064. tempIndex = ((gun_index==2) ? 1: 0);
  5065. }
  5066. else
  5067. {
  5068. tempIndex = gun_index;
  5069. }
  5070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5075. }
  5076. }// End of for CHAdeMO_QUANTITY
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5078. }
  5079. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5082. {
  5083. tempIndex = ((gun_index==2) ? 1: 0);
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < CCS_QUANTITY; index++)
  5090. {
  5091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5092. {
  5093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5094. }
  5095. }// End of for CCS_QUANTITY
  5096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5097. }
  5098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5099. {
  5100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5101. {
  5102. tempIndex = ((gun_index==2) ? 1: 0);
  5103. }
  5104. else
  5105. {
  5106. tempIndex = gun_index;
  5107. }
  5108. for (int index = 0; index < GB_QUANTITY; index++)
  5109. {
  5110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5111. {
  5112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5113. }
  5114. }// End of for GB_QUANTITY
  5115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_DO)
  5118. {
  5119. tempIndex = gun_index;
  5120. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5121. {
  5122. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5123. {
  5124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5125. }
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5128. }
  5129. else
  5130. {
  5131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5132. {
  5133. tempIndex = 2;
  5134. }
  5135. else
  5136. {
  5137. tempIndex = gun_index;
  5138. }
  5139. for (int index = 0; index < AC_QUANTITY; index++)
  5140. {
  5141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5142. {
  5143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5144. }
  5145. }// End of for AC_QUANTITY
  5146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5147. }
  5148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5153. }
  5154. // ================================= Energy.Active.Import.Interval ==============================================
  5155. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5156. {
  5157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5173. }
  5174. }// END OF CHAdeMO_QUANTITY
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5192. }
  5193. }// END OF CCS_QUANTITY
  5194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < GB_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5209. {
  5210. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5211. }
  5212. }// END OF GB_QUANTITY
  5213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_DO)
  5216. {
  5217. tempIndex = gun_index;
  5218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5219. {
  5220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5221. {
  5222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5223. }
  5224. }
  5225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5226. }
  5227. else
  5228. {
  5229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5230. {
  5231. tempIndex = 2;
  5232. }
  5233. else
  5234. {
  5235. tempIndex = gun_index;
  5236. }
  5237. for (int index = 0; index < AC_QUANTITY; index++)
  5238. {
  5239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5240. {
  5241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5242. }
  5243. }// END OF AC_QUANTITY
  5244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5245. }
  5246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5251. }
  5252. //=================================== Power.Active.Import ==================================================
  5253. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5254. {
  5255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5259. {
  5260. tempIndex = ((gun_index==2) ? 1: 0);
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5269. {
  5270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5271. }
  5272. } // End for CHAdeMO_QUANTITY
  5273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5274. }
  5275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5278. {
  5279. tempIndex = ((gun_index==2) ? 1: 0);
  5280. }
  5281. else
  5282. {
  5283. tempIndex = gun_index;
  5284. }
  5285. for (int index = 0; index < CCS_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5290. }
  5291. } // END for CCS_QUANTITY
  5292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5293. }
  5294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. for (int index = 0; index < GB_QUANTITY; index++)
  5305. {
  5306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5307. {
  5308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5309. }
  5310. }// END for GB_QUANTITY
  5311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_DO)
  5314. {
  5315. tempIndex = gun_index;
  5316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5317. {
  5318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5319. {
  5320. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5321. }
  5322. }
  5323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5324. }
  5325. else
  5326. {
  5327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5328. {
  5329. tempIndex = 2;
  5330. }
  5331. else
  5332. {
  5333. tempIndex = gun_index;
  5334. }
  5335. for (int index = 0; index < AC_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5340. }
  5341. } // END for AC_QUANTITY
  5342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5343. }
  5344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5349. }
  5350. //============================ Voltage L1 ====================================
  5351. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5352. {
  5353. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5354. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5355. {
  5356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5357. {
  5358. tempIndex = ((gun_index==2) ? 1: 0);
  5359. }
  5360. else
  5361. {
  5362. tempIndex = gun_index;
  5363. }
  5364. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5365. {
  5366. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5367. {
  5368. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5369. }
  5370. } // END OF FOR CHAdeMO_QUANTITY
  5371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5372. }
  5373. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5376. {
  5377. tempIndex = ((gun_index==2) ? 1: 0);
  5378. }
  5379. else
  5380. {
  5381. tempIndex = gun_index;
  5382. }
  5383. for (int index = 0; index < CCS_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5388. }
  5389. } // END OF FOR CCS_QUANTITY
  5390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5393. {
  5394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5395. {
  5396. tempIndex = ((gun_index==2) ? 1: 0);
  5397. }
  5398. else
  5399. {
  5400. tempIndex = gun_index;
  5401. }
  5402. for (int index = 0; index < GB_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5407. }
  5408. } // END OF FOR GB_QUANTITY
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_DO)
  5412. {
  5413. tempIndex = gun_index;
  5414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5419. }
  5420. }
  5421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5422. }
  5423. else
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//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[4].Phase,PhaseStr[L1_N]);
  5441. }
  5442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5447. }
  5448. //====================== End SoC ================================
  5449. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5450. {
  5451. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5452. 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))
  5453. {
  5454. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5455. {
  5456. tempIndex = ((gun_index==2) ? 1: 0);
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5463. {
  5464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5465. {
  5466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5467. {
  5468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5469. }
  5470. }
  5471. }
  5472. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5473. {
  5474. for (int index = 0; index < CCS_QUANTITY; index++)
  5475. {
  5476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5477. {
  5478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5479. }
  5480. }
  5481. }
  5482. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5483. {
  5484. for (int index = 0; index < GB_QUANTITY; index++)
  5485. {
  5486. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5487. {
  5488. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5489. }
  5490. }
  5491. }
  5492. else if(gunType[gun_index] == GUN_TYPE_DO)
  5493. {
  5494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5495. {
  5496. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5497. {
  5498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5499. }
  5500. }
  5501. }
  5502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5508. } // END FOR DC CASE
  5509. }
  5510. // ================================= Current.Import L2 ===============================================
  5511. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5512. {
  5513. // AC 3 phse L2 current
  5514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5515. {
  5516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5517. {
  5518. tempIndex = 2;
  5519. }
  5520. else
  5521. {
  5522. tempIndex = gun_index;
  5523. }
  5524. for (int index = 0; index < AC_QUANTITY; index++)
  5525. {
  5526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5527. {
  5528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5529. }
  5530. }// End of for AC_QUANTITY
  5531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5532. }
  5533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5538. }
  5539. // ================================= Current.Import L3 ===============================================
  5540. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5541. {
  5542. // AC 3 phse L3 current
  5543. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5546. {
  5547. tempIndex = 2;
  5548. }
  5549. else
  5550. {
  5551. tempIndex = gun_index;
  5552. }
  5553. for (int index = 0; index < AC_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5556. {
  5557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5558. }
  5559. }// End of for AC_QUANTITY
  5560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5561. }
  5562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5567. }
  5568. //============================ Voltage L2 ====================================
  5569. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5570. {
  5571. // AC 3 phse L2 voltage
  5572. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5573. {
  5574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5575. {
  5576. tempIndex = 2;
  5577. }
  5578. else
  5579. {
  5580. tempIndex = gun_index;
  5581. }
  5582. for (int index = 0; index < AC_QUANTITY; index++)
  5583. {
  5584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5585. {
  5586. 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
  5587. }
  5588. } // END OF FOR AC_QUANTITY
  5589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5590. }
  5591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5596. }
  5597. //============================ Voltage L3 ====================================
  5598. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5599. {
  5600. // AC 3 phse L3 voltage
  5601. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5602. {
  5603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5604. {
  5605. tempIndex = 2;
  5606. }
  5607. else
  5608. {
  5609. tempIndex = gun_index;
  5610. }
  5611. for (int index = 0; index < AC_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5614. {
  5615. 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
  5616. }
  5617. } // END OF FOR AC_QUANTITY
  5618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5619. }
  5620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5625. }
  5626. //====================== Start SoC ================================
  5627. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5628. {
  5629. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5630. 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))
  5631. {
  5632. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5641. {
  5642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5647. }
  5648. }
  5649. }
  5650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5651. {
  5652. for (int index = 0; index < CCS_QUANTITY; index++)
  5653. {
  5654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5655. {
  5656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5657. }
  5658. }
  5659. }
  5660. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5661. {
  5662. for (int index = 0; index < GB_QUANTITY; index++)
  5663. {
  5664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5665. {
  5666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5667. }
  5668. }
  5669. }
  5670. else if(gunType[gun_index] == GUN_TYPE_DO)
  5671. {
  5672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5673. {
  5674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5675. {
  5676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5677. }
  5678. }
  5679. }
  5680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5686. } // END FOR DC CASE
  5687. }
  5688. //================================================ Message create ====================================================
  5689. json_object *StopTransaction = json_object_new_object();
  5690. json_object *transactionDatas = json_object_new_array();
  5691. json_object *sampledValues = json_object_new_array();
  5692. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5693. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5694. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5695. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5696. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5697. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5698. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5699. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5700. {
  5701. json_object *transactionData = json_object_new_object();
  5702. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5703. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5704. {
  5705. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5706. {
  5707. json_object *sampledValue = json_object_new_object();
  5708. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5709. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5710. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5711. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5712. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5713. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5714. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5715. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5716. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5717. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5718. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5719. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5720. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5721. json_object_array_add(sampledValues, sampledValue);
  5722. }
  5723. }
  5724. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5725. json_object_array_add(transactionDatas, transactionData);
  5726. }
  5727. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5728. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5729. ,MESSAGE_TYPE_CALL
  5730. ,guid
  5731. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5732. json_object_put(StopTransaction);
  5733. #if 1 // for TempStopTransaction
  5734. //Delete TempStopTransaction
  5735. if((access(TempStopTransaction,F_OK))!=-1)
  5736. {
  5737. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5738. }
  5739. #endif
  5740. #if 1
  5741. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5742. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5743. {
  5744. result = PASS;
  5745. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5746. }
  5747. #endif
  5748. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5749. OCPP_insert_transaction_msg(NO, queuedata);
  5750. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5751. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5752. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5753. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5754. {
  5755. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5756. }
  5757. //for test
  5758. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5759. return result;
  5760. }
  5761. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5762. {
  5763. mtrace();
  5764. int result = FAIL;
  5765. char guid[37]={0};
  5766. char tempdata[65]={0};
  5767. int tempIndex = 0;
  5768. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5769. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5770. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5771. //set value
  5772. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5773. 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) )?
  5774. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5775. -1);
  5776. random_uuid(guid);
  5777. //UTC Date time
  5778. struct timeval tmnow;
  5779. struct tm *tm;
  5780. char buf[28];//, usec_buf[6];
  5781. gettimeofday(&tmnow, NULL);
  5782. time_t t;
  5783. t = time(NULL);
  5784. /*UTC time and date*/
  5785. tm = gmtime(&t);
  5786. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5788. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5789. //********************************(1)Current.Import L1************************************************/
  5790. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5791. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5792. (dataType == ReadingContext_Trigger))
  5793. {
  5794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5796. {
  5797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5798. {
  5799. tempIndex = ((gun_index==2) ? 1: 0);
  5800. }
  5801. else
  5802. {
  5803. tempIndex = gun_index;
  5804. }
  5805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5806. {
  5807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5808. {
  5809. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5810. }
  5811. }
  5812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5813. }
  5814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5815. {
  5816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. for (int index = 0; index < CCS_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5829. }
  5830. }
  5831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < GB_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5848. }
  5849. }
  5850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5851. }
  5852. else if(gunType[gun_index] == GUN_TYPE_DO)
  5853. {
  5854. tempIndex = gun_index;
  5855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5856. {
  5857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5858. {
  5859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5860. }
  5861. }
  5862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5863. }
  5864. else
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5867. {
  5868. tempIndex = 2;
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < AC_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5879. }
  5880. }
  5881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5882. }
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5888. }
  5889. //********************************(2)Energy.Active.Import.Register ************************************************/
  5890. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5891. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5892. (dataType == ReadingContext_Trigger))
  5893. {
  5894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5898. {
  5899. tempIndex = ((gun_index==2) ? 1: 0);
  5900. }
  5901. else
  5902. {
  5903. tempIndex = gun_index;
  5904. }
  5905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5906. {
  5907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5908. {
  5909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5910. }
  5911. }
  5912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5913. }
  5914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5915. {
  5916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5917. {
  5918. tempIndex = ((gun_index==2) ? 1: 0);
  5919. }
  5920. else
  5921. {
  5922. tempIndex = gun_index;
  5923. }
  5924. for (int index = 0; index < CCS_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5927. {
  5928. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5929. }
  5930. }
  5931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5932. }
  5933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5934. {
  5935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5936. {
  5937. tempIndex = ((gun_index==2) ? 1: 0);
  5938. }
  5939. else
  5940. {
  5941. tempIndex = gun_index;
  5942. }
  5943. for (int index = 0; index < GB_QUANTITY; index++)
  5944. {
  5945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5946. {
  5947. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5948. }
  5949. }
  5950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5951. }
  5952. else if(gunType[gun_index] == GUN_TYPE_DO)
  5953. {
  5954. tempIndex = gun_index;
  5955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5958. {
  5959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5960. }
  5961. }
  5962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5963. }
  5964. else
  5965. {
  5966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5967. {
  5968. tempIndex = 2;
  5969. }
  5970. else
  5971. {
  5972. tempIndex = gun_index;
  5973. }
  5974. for (int index = 0; index < AC_QUANTITY; index++)
  5975. {
  5976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5977. {
  5978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5979. }
  5980. }
  5981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5982. }
  5983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5988. }
  5989. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5990. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5991. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5992. (dataType == ReadingContext_Trigger))
  5993. {
  5994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5995. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5996. {
  5997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5998. {
  5999. tempIndex = ((gun_index==2) ? 1: 0);
  6000. }
  6001. else
  6002. {
  6003. tempIndex = gun_index;
  6004. }
  6005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6010. }
  6011. } // END OF FOR CHAdeMO_QUANTITY
  6012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6013. }
  6014. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6015. {
  6016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6017. {
  6018. tempIndex = ((gun_index==2) ? 1: 0);
  6019. }
  6020. else
  6021. {
  6022. tempIndex = gun_index;
  6023. }
  6024. for (int index = 0; index < CCS_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6027. {
  6028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6029. }
  6030. } // END OF CCS_QUANTITY
  6031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6032. }
  6033. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6034. {
  6035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6036. {
  6037. tempIndex = ((gun_index==2) ? 1: 0);
  6038. }
  6039. else
  6040. {
  6041. tempIndex = gun_index;
  6042. }
  6043. for (int index = 0; index < GB_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6046. {
  6047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6048. }
  6049. } // END OF GB_QUANTITY
  6050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6051. }
  6052. else if(gunType[gun_index] == GUN_TYPE_DO)
  6053. {
  6054. tempIndex = gun_index;
  6055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6056. {
  6057. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6058. {
  6059. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6060. }
  6061. }
  6062. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6063. }
  6064. else
  6065. {
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. tempIndex = 2;
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. for (int index = 0; index < AC_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6079. }
  6080. }
  6081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6082. }
  6083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6086. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6087. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6088. }
  6089. //********************************(4)Power.Active.Import************************************************/
  6090. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6091. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6092. (dataType == ReadingContext_Trigger))
  6093. {
  6094. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6096. {
  6097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6098. {
  6099. tempIndex = ((gun_index==2) ? 1: 0);
  6100. }
  6101. else
  6102. {
  6103. tempIndex = gun_index;
  6104. }
  6105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6106. {
  6107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6108. {
  6109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6110. }
  6111. } // END OF FOR
  6112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6113. }
  6114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CCS_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6127. {
  6128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6129. }
  6130. }
  6131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6136. {
  6137. tempIndex = ((gun_index==2) ? 1: 0);
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < GB_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6146. {
  6147. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6149. }
  6150. }
  6151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_DO)
  6154. {
  6155. tempIndex = gun_index;
  6156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6159. {
  6160. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6162. }
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6165. }
  6166. else
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6181. }
  6182. }
  6183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6190. }
  6191. //***********************************************(5)VOLTAGE L1******************************************************/
  6192. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6193. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6194. (dataType == ReadingContext_Trigger))
  6195. {
  6196. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6197. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6198. {
  6199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6200. {
  6201. tempIndex = ((gun_index==2) ? 1: 0);
  6202. }
  6203. else
  6204. {
  6205. tempIndex = gun_index;
  6206. }
  6207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6210. {
  6211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6212. }
  6213. }
  6214. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6215. }
  6216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6217. {
  6218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6219. {
  6220. tempIndex = ((gun_index==2) ? 1: 0);
  6221. }
  6222. else
  6223. {
  6224. tempIndex = gun_index;
  6225. }
  6226. for (int index = 0; index < CCS_QUANTITY; index++)
  6227. {
  6228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6229. {
  6230. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6231. }
  6232. }
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6234. }
  6235. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6236. {
  6237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6238. {
  6239. tempIndex = ((gun_index==2) ? 1: 0);
  6240. }
  6241. else
  6242. {
  6243. tempIndex = gun_index;
  6244. }
  6245. for (int index = 0; index < GB_QUANTITY; index++)
  6246. {
  6247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6248. {
  6249. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6250. }
  6251. }
  6252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6253. }
  6254. else if(gunType[gun_index] == GUN_TYPE_DO)
  6255. {
  6256. tempIndex = gun_index;
  6257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6258. {
  6259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6262. }
  6263. }
  6264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6265. }
  6266. else
  6267. {
  6268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6269. {
  6270. tempIndex = 2;
  6271. }
  6272. else
  6273. {
  6274. tempIndex = gun_index;
  6275. }
  6276. for (int index = 0; index < AC_QUANTITY; index++)
  6277. {
  6278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6279. {
  6280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6281. }
  6282. }
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6284. }
  6285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6290. }
  6291. //***********************************************(6)SOC******************************************************/
  6292. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6293. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6294. (dataType == ReadingContext_Trigger))
  6295. {
  6296. 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))
  6297. {
  6298. //idx_sample=5;
  6299. //sampledValue = NULL;
  6300. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6301. {
  6302. tempIndex = ((gun_index==2) ? 1: 0);
  6303. }
  6304. else
  6305. {
  6306. tempIndex = gun_index;
  6307. }
  6308. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6309. {
  6310. //tempIndex = ((gun_index==2) ? 1: 0);
  6311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6316. }
  6317. }
  6318. }
  6319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6320. {
  6321. //tempIndex = ((gun_index==2) ? 1: 0);
  6322. for (int index = 0; index < CCS_QUANTITY; index++)
  6323. {
  6324. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6325. {
  6326. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6327. }
  6328. }
  6329. }
  6330. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6331. {
  6332. //tempIndex = ((gun_index==2) ? 1: 0);
  6333. for (int index = 0; index < GB_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6336. {
  6337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6338. }
  6339. }
  6340. }
  6341. else if(gunType[gun_index] == GUN_TYPE_DO)
  6342. {
  6343. //tempIndex = ((gun_index==2) ? 1: 0);
  6344. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6349. }
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6358. }
  6359. }
  6360. //********************************(7)Current.Import L2************************************************/
  6361. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6362. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6363. (dataType == ReadingContext_Trigger))
  6364. {
  6365. // Only for AC 3 phase
  6366. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6367. {
  6368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6369. {
  6370. tempIndex = 2;
  6371. }
  6372. else
  6373. {
  6374. tempIndex = gun_index;
  6375. }
  6376. for (int index = 0; index < AC_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6381. }
  6382. }
  6383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6384. }
  6385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6390. }
  6391. //********************************(8)Current.Import L3************************************************/
  6392. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6393. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6394. (dataType == ReadingContext_Trigger))
  6395. {
  6396. // Only for AC 3 phase
  6397. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6400. {
  6401. tempIndex = 2;
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < AC_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6410. {
  6411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6412. }
  6413. }
  6414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6415. }
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6421. }
  6422. //***********************************************(9)VOLTAGE L2******************************************************/
  6423. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6424. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6425. (dataType == ReadingContext_Trigger))
  6426. {
  6427. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6430. {
  6431. tempIndex = 2;
  6432. }
  6433. else
  6434. {
  6435. tempIndex = gun_index;
  6436. }
  6437. for (int index = 0; index < AC_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6440. {
  6441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6442. }
  6443. }
  6444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6445. }
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6451. }
  6452. //***********************************************(10)VOLTAGE L3******************************************************/
  6453. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6454. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6455. (dataType == ReadingContext_Trigger))
  6456. {
  6457. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6458. {
  6459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6460. {
  6461. tempIndex = 2;
  6462. }
  6463. else
  6464. {
  6465. tempIndex = gun_index;
  6466. }
  6467. for (int index = 0; index < AC_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6470. {
  6471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6472. }
  6473. }
  6474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6475. }
  6476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6481. }
  6482. //***********************************************(11)Current.Offered******************************************************/
  6483. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6484. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6485. (dataType == ReadingContext_Trigger))
  6486. {
  6487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6488. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6491. {
  6492. tempIndex = ((gun_index==2) ? 1: 0);
  6493. }
  6494. else
  6495. {
  6496. tempIndex = gun_index;
  6497. }
  6498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6499. {
  6500. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6501. {
  6502. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6503. }
  6504. } // END OF FOR CHAdeMO_QUANTITY
  6505. }
  6506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6507. {
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6509. {
  6510. tempIndex = ((gun_index==2) ? 1: 0);
  6511. }
  6512. else
  6513. {
  6514. tempIndex = gun_index;
  6515. }
  6516. for (int index = 0; index < CCS_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6519. {
  6520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6521. }
  6522. } // END OF CCS_QUANTITY
  6523. }
  6524. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6525. {
  6526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6527. {
  6528. tempIndex = ((gun_index==2) ? 1: 0);
  6529. }
  6530. else
  6531. {
  6532. tempIndex = gun_index;
  6533. }
  6534. for (int index = 0; index < GB_QUANTITY; index++)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6537. {
  6538. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6539. }
  6540. } // END OF GB_QUANTITY
  6541. }
  6542. else if(gunType[gun_index] == GUN_TYPE_DO)
  6543. {
  6544. tempIndex = gun_index;
  6545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6548. {
  6549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6550. }
  6551. }
  6552. }
  6553. else
  6554. {
  6555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6556. {
  6557. tempIndex = 2;
  6558. }
  6559. else
  6560. {
  6561. tempIndex = gun_index;
  6562. }
  6563. for (int index = 0; index < AC_QUANTITY; index++)
  6564. {
  6565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6566. {
  6567. uint16_t currentOffer;
  6568. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6569. {
  6570. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6571. }
  6572. else
  6573. {
  6574. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6575. }
  6576. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6577. }
  6578. }
  6579. }
  6580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6585. }
  6586. //***********************************************(12)Power.Offered******************************************************/
  6587. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6588. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6589. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6590. {
  6591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6595. {
  6596. tempIndex = ((gun_index==2) ? 1: 0);
  6597. }
  6598. else
  6599. {
  6600. tempIndex = gun_index;
  6601. }
  6602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6605. {
  6606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6607. }
  6608. } // END OF FOR CHAdeMO_QUANTITY
  6609. }
  6610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6611. {
  6612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6613. {
  6614. tempIndex = ((gun_index==2) ? 1: 0);
  6615. }
  6616. else
  6617. {
  6618. tempIndex = gun_index;
  6619. }
  6620. for (int index = 0; index < CCS_QUANTITY; index++)
  6621. {
  6622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6623. {
  6624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6625. }
  6626. } // END OF CCS_QUANTITY
  6627. }
  6628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6629. {
  6630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6631. {
  6632. tempIndex = ((gun_index==2) ? 1: 0);
  6633. }
  6634. else
  6635. {
  6636. tempIndex = gun_index;
  6637. }
  6638. for (int index = 0; index < GB_QUANTITY; index++)
  6639. {
  6640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6641. {
  6642. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6643. }
  6644. } // END OF GB_QUANTITY
  6645. }
  6646. else if(gunType[gun_index] == GUN_TYPE_DO)
  6647. {
  6648. tempIndex = gun_index;
  6649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6650. {
  6651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6652. {
  6653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6654. }
  6655. }
  6656. }
  6657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6662. }
  6663. // Message create ====================================================================================================
  6664. if(TRUE)
  6665. {
  6666. json_object *MeterValueReq = json_object_new_object();
  6667. json_object *MeterValues = json_object_new_array();
  6668. json_object *sampledValues = json_object_new_array();
  6669. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6670. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6671. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6672. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6673. {
  6674. json_object *MeterValue = json_object_new_object();
  6675. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6676. {
  6677. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6678. {
  6679. json_object *sampledValue = json_object_new_object();
  6680. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6681. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6682. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6683. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6684. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6685. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6686. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6687. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6688. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6689. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6690. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6691. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6692. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6693. json_object_array_add(sampledValues, sampledValue);
  6694. }
  6695. }
  6696. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6697. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6698. json_object_array_add(MeterValues, MeterValue);
  6699. }
  6700. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6701. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6702. ,gun_index + 1
  6703. ,MESSAGE_TYPE_CALL
  6704. ,guid
  6705. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6706. json_object_put(MeterValueReq);
  6707. }
  6708. // Put request guid to hash map
  6709. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6710. 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*/)
  6711. {
  6712. result = PASS;
  6713. //DEBUG_INFO("MeterValues mapitem pass\n");
  6714. }
  6715. if((dataType != ReadingContext_Trigger) &&
  6716. (dataType != ReadingContext_Sample_Clock) &&
  6717. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6718. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6719. else
  6720. {
  6721. if(FirstHeartBeat)
  6722. LWS_Send(queuedata +2);
  6723. }
  6724. return result;
  6725. }
  6726. int sendLogStatusNotificationRequest(char *status)
  6727. {
  6728. mtrace();
  6729. int result = PASS;
  6730. char message[4096]={0};
  6731. char guid[37]={0};
  6732. char tempdata[128]={0};
  6733. json_object *LogStatusNotification = json_object_new_object();
  6734. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6735. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6736. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6737. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6738. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6739. random_uuid(guid);
  6740. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6741. json_object_put(LogStatusNotification);
  6742. LWS_Send(message);
  6743. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6744. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6745. {
  6746. result = PASS;
  6747. }
  6748. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6749. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6750. return result;
  6751. }
  6752. int sendSecurityEventNotificationRequest()
  6753. {
  6754. mtrace();
  6755. int result = PASS;
  6756. char message[4096]={0};
  6757. char guid[37]={0};
  6758. char tempdata[128]={0};
  6759. json_object *SecurityEventNotification = json_object_new_object();
  6760. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6761. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6762. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6763. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6764. random_uuid(guid);
  6765. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6766. json_object_put(SecurityEventNotification);
  6767. LWS_Send(message);
  6768. sprintf(tempdata, "SecurityEventNotification,0");
  6769. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6770. {
  6771. result = PASS;
  6772. }
  6773. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6774. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6775. return result;
  6776. }
  6777. int sendSignCertificateRequest()
  6778. {
  6779. mtrace();
  6780. int result = PASS;
  6781. char message[4096]={0};
  6782. char guid[37]={0};
  6783. char tempdata[128]={0};
  6784. json_object *SignCertificate = json_object_new_object();
  6785. DEBUG_INFO("sendSignCertificateRequest...\n");
  6786. // Read csr file content
  6787. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6788. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6789. char *line = NULL;
  6790. size_t len = 0;
  6791. while(getline(&line, &len, fp) != -1)
  6792. {
  6793. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6794. {
  6795. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6796. }
  6797. }
  6798. fclose(fp);
  6799. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6800. random_uuid(guid);
  6801. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6802. json_object_put(SignCertificate);
  6803. LWS_Send(message);
  6804. sprintf(tempdata, "SignCertificate,0");
  6805. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6806. {
  6807. result = PASS;
  6808. }
  6809. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6810. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6811. return result;
  6812. }
  6813. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6814. {
  6815. mtrace();
  6816. int result = PASS;
  6817. char message[110]={0};
  6818. char guid[37]={0};
  6819. char tempdata[65]={0};
  6820. json_object *FirmwareStatusNotification = json_object_new_object();
  6821. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6822. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6823. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6824. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6825. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6826. random_uuid(guid);
  6827. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6828. json_object_put(FirmwareStatusNotification);
  6829. LWS_Send(message);
  6830. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6831. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6832. {
  6833. result = PASS;
  6834. }
  6835. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6836. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6837. return result;
  6838. }
  6839. //==========================================
  6840. // send confirm routine
  6841. //==========================================
  6842. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. char message[100]={0};
  6847. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6848. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6849. LWS_Send(message);
  6850. result = TRUE;
  6851. return result;
  6852. }
  6853. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6854. {
  6855. mtrace();
  6856. int result = FAIL;
  6857. char message[100]={0};
  6858. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6859. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6860. LWS_Send(message);
  6861. result = TRUE;
  6862. return result;
  6863. }
  6864. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6865. {
  6866. mtrace();
  6867. int result = FAIL;
  6868. char message[100]={0};
  6869. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6870. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6871. LWS_Send(message);
  6872. result = TRUE;
  6873. return result;
  6874. }
  6875. int sendClearCacheConfirmation(char *uuid,char *payload)
  6876. {
  6877. mtrace();
  6878. int result = FAIL;
  6879. char message[500]={0};
  6880. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6881. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6882. LWS_Send(message);
  6883. return result;
  6884. }
  6885. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6886. {
  6887. mtrace();
  6888. int result = FAIL;
  6889. char message[500]={0};
  6890. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6891. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6892. LWS_Send(message);
  6893. return result;
  6894. }
  6895. int sendDataTransferConfirmation(char *uuid,char *payload)
  6896. {
  6897. mtrace();
  6898. char statusStr[20]={0};
  6899. char dataStr[10]={0};
  6900. char sstr[20]={0};
  6901. int c = 0;
  6902. char *loc;
  6903. int result = FAIL;
  6904. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6905. /**********************status**************************/
  6906. loc = strstr(payload, "status");
  6907. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6908. c = 0;
  6909. while (loc[3+strlen("status")+c] != '\"')
  6910. {
  6911. sstr[c] = loc[3+strlen("status")+c];
  6912. c++;
  6913. }
  6914. sstr[c] = '\0';
  6915. strcpy(statusStr, sstr);
  6916. /**********************data**************************/
  6917. loc = strstr(payload, "data");
  6918. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6919. c = 0;
  6920. while (loc[3+strlen("data")+c] != '\"')
  6921. {
  6922. sstr[c] = loc[3+strlen("data")+c];
  6923. c++;
  6924. }
  6925. sstr[c] = '\0';
  6926. strcpy(dataStr, sstr);
  6927. return result;
  6928. }
  6929. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6930. {
  6931. mtrace();
  6932. int result = FAIL;
  6933. char message[1000]={0};
  6934. int CompositeScheduleIndex = 0;
  6935. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6936. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6937. if(nPeriod == 0)
  6938. {
  6939. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6940. {
  6941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6942. ,MESSAGE_TYPE_CALLRESULT
  6943. ,uuid
  6944. ,payload
  6945. ,connectorIdInt);
  6946. }
  6947. else
  6948. {
  6949. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6950. ,MESSAGE_TYPE_CALLRESULT
  6951. ,uuid
  6952. ,payload
  6953. ,connectorIdInt
  6954. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6955. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6956. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6957. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6958. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6959. }
  6960. }
  6961. else
  6962. {
  6963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6964. ,MESSAGE_TYPE_CALLRESULT
  6965. ,uuid
  6966. ,payload
  6967. ,connectorIdInt
  6968. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6972. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6973. {
  6974. if (idx_sample == 0)
  6975. {
  6976. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6977. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6980. }
  6981. else
  6982. {
  6983. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6984. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6985. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6986. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6987. }
  6988. }
  6989. sprintf(message + strlen(message), "]}}]");
  6990. }
  6991. LWS_Send(message);
  6992. result = TRUE;
  6993. return result;
  6994. }
  6995. int sendGetConfigurationConfirmation(char *uuid)
  6996. {
  6997. mtrace();
  6998. int result = FAIL;
  6999. int MaxKeySupported = 0;
  7000. int sentConfigurationNumber= 0;
  7001. int sentunConfigurationNumber= 0;
  7002. char message[1024*10]={0};
  7003. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7004. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7005. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7006. ,MESSAGE_TYPE_CALLRESULT
  7007. ,uuid );
  7008. //configuration key
  7009. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7010. {
  7011. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7012. {
  7013. if (sentConfigurationNumber == 0)
  7014. {
  7015. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7016. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7017. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7018. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7019. }
  7020. else
  7021. {
  7022. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7023. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7024. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7025. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7026. }
  7027. sentConfigurationNumber = sentConfigurationNumber + 1;
  7028. }
  7029. }
  7030. sprintf(message + strlen(message), "]");
  7031. if(UnknownKeynum != 0)
  7032. {
  7033. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7034. //unkown key
  7035. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7036. {
  7037. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7038. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7039. if(sentunConfigurationNumber == 0)
  7040. {
  7041. sprintf(message + strlen(message), "\"%s\""
  7042. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7043. }
  7044. else
  7045. {
  7046. sprintf(message + strlen(message), ",\"%s\""
  7047. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7048. }
  7049. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7050. }
  7051. sprintf(message + strlen(message), "]");
  7052. }
  7053. sprintf(message + strlen(message), "}]");
  7054. LWS_Send(message);
  7055. return result;
  7056. }
  7057. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7058. {
  7059. mtrace();
  7060. int result = FAIL;
  7061. char message[400]={0};
  7062. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7063. if(strcmp(payload,"")==0)
  7064. {
  7065. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7066. }
  7067. else
  7068. {
  7069. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7070. }
  7071. LWS_Send(message);
  7072. result = TRUE;
  7073. return result;
  7074. }
  7075. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7076. {
  7077. mtrace();
  7078. int result = FAIL;
  7079. char message[80]={0};
  7080. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7081. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7082. LWS_Send(message);
  7083. result = TRUE;
  7084. return result;
  7085. }
  7086. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7087. {
  7088. mtrace();
  7089. int result = FAIL;
  7090. char message[80]={0};
  7091. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7092. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7093. LWS_Send(message);
  7094. result = TRUE;
  7095. return result;
  7096. }
  7097. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7098. {
  7099. mtrace();
  7100. int result = FAIL;
  7101. char message[80]={0};
  7102. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7104. LWS_Send(message);
  7105. result = TRUE;
  7106. return result;
  7107. }
  7108. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7109. {
  7110. mtrace();
  7111. int result = FAIL;
  7112. char message[80]={0};
  7113. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7114. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7116. LWS_Send(message);
  7117. result = TRUE;
  7118. return result;
  7119. }
  7120. int sendResetConfirmation(char *uuid,char *payload)
  7121. {
  7122. mtrace();
  7123. int result = FAIL;
  7124. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7125. char message[80]={0};
  7126. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7127. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7128. LWS_Send(message);
  7129. result = TRUE;
  7130. return result;
  7131. }
  7132. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7133. {
  7134. mtrace();
  7135. int result = FAIL;
  7136. char message[500]={0};
  7137. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7138. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7139. LWS_Send(message);
  7140. result = TRUE;
  7141. return result;
  7142. }
  7143. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7144. {
  7145. mtrace();
  7146. int result = FAIL;
  7147. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7148. char message[80]={0};
  7149. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7150. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7151. LWS_Send(message);
  7152. result = TRUE;
  7153. return result;
  7154. }
  7155. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7156. {
  7157. mtrace();
  7158. int result = FAIL;
  7159. char message[80]={0};
  7160. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7161. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7162. LWS_Send(message);
  7163. result = TRUE;
  7164. return result;
  7165. }
  7166. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7167. {
  7168. mtrace();
  7169. int result = FAIL;
  7170. char message[80]={0};
  7171. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7172. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7173. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7174. LWS_Send(message);
  7175. result = TRUE;
  7176. return result;
  7177. }
  7178. int sendUpdateFirmwareConfirmation(char *uuid)
  7179. {
  7180. mtrace();
  7181. int result = FAIL;
  7182. char message[60]={0};
  7183. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7184. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7185. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7186. LWS_Send(message);
  7187. result = TRUE;
  7188. return result;
  7189. }
  7190. int sendCertificateSignedConfirmation(char *uuid)
  7191. {
  7192. mtrace();
  7193. int result = PASS;
  7194. char message[4096]={0};
  7195. json_object *CertificateSigned = json_object_new_object();
  7196. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7197. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7198. sprintf(message,"[%d,\"%s\",%s]"
  7199. ,MESSAGE_TYPE_CALLRESULT
  7200. ,uuid
  7201. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7202. json_object_put(CertificateSigned);
  7203. LWS_Send(message);
  7204. return result;
  7205. }
  7206. int sendDeleteCertificateConfirmation(char *uuid)
  7207. {
  7208. mtrace();
  7209. int result = PASS;
  7210. char message[4096]={0};
  7211. json_object *DeleteCertificate = json_object_new_object();
  7212. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7213. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7214. sprintf(message,"[%d,\"%s\",%s]"
  7215. ,MESSAGE_TYPE_CALLRESULT
  7216. ,uuid
  7217. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7218. json_object_put(DeleteCertificate);
  7219. LWS_Send(message);
  7220. return result;
  7221. }
  7222. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7223. {
  7224. mtrace();
  7225. int result = PASS;
  7226. char message[4096]={0};
  7227. json_object *ExtendedTriggerMessage = json_object_new_object();
  7228. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7229. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7230. sprintf(message,"[%d,\"%s\",%s]"
  7231. ,MESSAGE_TYPE_CALLRESULT
  7232. ,uuid
  7233. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7234. json_object_put(ExtendedTriggerMessage);
  7235. LWS_Send(message);
  7236. return result;
  7237. }
  7238. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7239. {
  7240. mtrace();
  7241. int result = PASS;
  7242. char message[4096]={0};
  7243. json_object *GetInstalledCertificateIds = json_object_new_object();
  7244. json_object *certificateHashDataDatas = json_object_new_array();
  7245. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7246. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7247. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7248. {
  7249. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7250. {
  7251. json_object *certificateHashData = json_object_new_object();
  7252. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7253. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7254. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7255. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7256. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7257. }
  7258. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7259. }
  7260. else
  7261. {
  7262. json_object_put(certificateHashDataDatas);
  7263. }
  7264. sprintf(message,"[%d,\"%s\",%s]"
  7265. ,MESSAGE_TYPE_CALLRESULT
  7266. ,uuid
  7267. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7268. json_object_put(GetInstalledCertificateIds);
  7269. LWS_Send(message);
  7270. return result;
  7271. }
  7272. int sendGetLogConfirmation(char *uuid)
  7273. {
  7274. mtrace();
  7275. int result = PASS;
  7276. char message[4096]={0};
  7277. json_object *GetLog = json_object_new_object();
  7278. DEBUG_INFO("sendGetLogConfirmation...\n");
  7279. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7280. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7281. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7282. sprintf(message,"[%d,\"%s\",%s]"
  7283. ,MESSAGE_TYPE_CALLRESULT
  7284. ,uuid
  7285. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7286. json_object_put(GetLog);
  7287. LWS_Send(message);
  7288. return result;
  7289. }
  7290. int sendInstallCertificateConfirmation(char *uuid)
  7291. {
  7292. mtrace();
  7293. int result = PASS;
  7294. char message[4096]={0};
  7295. json_object *InstallCertificate = json_object_new_object();
  7296. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7297. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7298. sprintf(message,"[%d,\"%s\",%s]"
  7299. ,MESSAGE_TYPE_CALLRESULT
  7300. ,uuid
  7301. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7302. json_object_put(InstallCertificate);
  7303. LWS_Send(message);
  7304. return result;
  7305. }
  7306. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7307. {
  7308. mtrace();
  7309. int result = PASS;
  7310. char message[4096]={0};
  7311. json_object *SignedUpdateFirmware = json_object_new_object();
  7312. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7313. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7314. sprintf(message,"[%d,\"%s\",%s]"
  7315. ,MESSAGE_TYPE_CALLRESULT
  7316. ,uuid
  7317. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7318. json_object_put(SignedUpdateFirmware);
  7319. LWS_Send(message);
  7320. return result;
  7321. }
  7322. int sendUnknownConfirmation(char *uuid)
  7323. {
  7324. mtrace();
  7325. int result = PASS;
  7326. char message[256]={0};
  7327. DEBUG_INFO("sendUnknownConfirmation...\n");
  7328. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7329. LWS_Send(message);
  7330. return result;
  7331. }
  7332. //==========================================
  7333. // Handle server request routine Start
  7334. //==========================================
  7335. int handleCancelReservationRequest(char *uuid, char *payload)
  7336. {
  7337. mtrace();
  7338. int result = FAIL;
  7339. int gunNO = 0;
  7340. int reservationIdInt = -1;
  7341. char comfirmstr[20];
  7342. DEBUG_INFO("handleCancelReservationRequest...\n");
  7343. json_object *CancelReservation;
  7344. CancelReservation = json_tokener_parse(payload);
  7345. if(!is_error(CancelReservation))
  7346. {
  7347. // Required data
  7348. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7349. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7350. }
  7351. json_object_put(CancelReservation);
  7352. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7353. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7354. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7355. if(reservationIdInt != -1)
  7356. {
  7357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7358. //check Transaction active
  7359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7361. {
  7362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7363. {
  7364. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7365. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7366. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7367. {
  7368. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7369. }
  7370. else
  7371. {
  7372. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7373. }
  7374. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7375. goto end;
  7376. }
  7377. }
  7378. for (int index = 0; index < CCS_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7381. {
  7382. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7383. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7384. if(gunType[2] == GUN_TYPE_CCS)
  7385. {
  7386. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7387. }
  7388. else
  7389. {
  7390. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7391. }
  7392. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7393. goto end;
  7394. }
  7395. }
  7396. for (int index = 0; index < GB_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7399. {
  7400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7401. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7402. if(gunType[2] == GUN_TYPE_GBT)
  7403. {
  7404. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7405. }
  7406. else
  7407. {
  7408. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7409. }
  7410. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7411. goto end;
  7412. }
  7413. }
  7414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7417. {
  7418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7419. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7420. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7421. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7422. goto end;
  7423. }
  7424. }
  7425. for (int index = 0; index < AC_QUANTITY; index++)
  7426. {
  7427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7428. {
  7429. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7430. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7432. {
  7433. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7434. }
  7435. else
  7436. {
  7437. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7438. }
  7439. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7440. goto end;
  7441. }
  7442. }
  7443. }
  7444. //The reservationId does NOT match the reservationId
  7445. sendCancelReservationConfirmation(uuid, comfirmstr);
  7446. end:
  7447. // Fill in ocpp packet uuid
  7448. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7449. return result;
  7450. }
  7451. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7452. {
  7453. mtrace();
  7454. int result = FAIL;
  7455. int gunIndex = 0;
  7456. char typeStr[16]={0};
  7457. char comfirmstr[20];
  7458. int specificId = FALSE;
  7459. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7460. json_object *ChangeAvailability;
  7461. ChangeAvailability = json_tokener_parse(payload);
  7462. if(!is_error(ChangeAvailability))
  7463. {
  7464. // Required data
  7465. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7466. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7467. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7468. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7469. }
  7470. json_object_put(ChangeAvailability);
  7471. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7472. {
  7473. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7474. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7475. }
  7476. else if(gunIndex == 0)
  7477. {
  7478. for(int i=0; i < gunTotalNumber; i++)
  7479. {
  7480. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7481. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7482. }
  7483. }
  7484. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7486. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7487. {
  7488. specificId = TRUE;
  7489. }
  7490. if(specificId == FALSE)
  7491. goto end;
  7492. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7493. {
  7494. //----------------------gunIndex is 0 ------------------------------------------------//
  7495. if(gunIndex == 0)
  7496. {
  7497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7498. {
  7499. for(int i=0; i < gunTotalNumber; i++)
  7500. {
  7501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7502. {
  7503. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7504. {
  7505. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7506. {
  7507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7508. goto end;
  7509. }
  7510. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7511. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7513. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7514. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7515. {
  7516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7517. goto end;
  7518. }
  7519. }
  7520. }//END FOR CHAdeMO_QUANTITY
  7521. for (int index = 0; index < CCS_QUANTITY; index++)
  7522. {
  7523. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7524. {
  7525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7526. {
  7527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7528. goto end;
  7529. }
  7530. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7532. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7533. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7534. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7535. {
  7536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7537. goto end;
  7538. }
  7539. }
  7540. }//END FOR CCS_QUANTITY
  7541. for (int index = 0; index < GB_QUANTITY; index++)
  7542. {
  7543. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7544. {
  7545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7546. {
  7547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7548. goto end;
  7549. }
  7550. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7552. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7553. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7555. {
  7556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7557. goto end;
  7558. }
  7559. }
  7560. }// END FOR GB_QUANTITY
  7561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7562. {
  7563. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7564. {
  7565. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7566. {
  7567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7568. goto end;
  7569. }
  7570. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7572. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7573. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7574. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7575. {
  7576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7577. goto end;
  7578. }
  7579. }
  7580. }// END FOR GENERAL_GUN_QUANTITY
  7581. for (int index = 0; index < AC_QUANTITY; index++)
  7582. {
  7583. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7584. {
  7585. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7586. {
  7587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7588. goto end;
  7589. }
  7590. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7591. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7592. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7593. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7595. {
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7597. goto end;
  7598. }
  7599. }
  7600. }//END FOR AC_QUANTITY
  7601. }// END FOR gunTotalNumber
  7602. }
  7603. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7604. {
  7605. for(int i=0; i < gunTotalNumber; i++)
  7606. {
  7607. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7608. {
  7609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7610. goto end;
  7611. }
  7612. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7613. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7614. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7616. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7617. {
  7618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7619. goto end;
  7620. }
  7621. }
  7622. }
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7624. goto end;
  7625. }
  7626. //----------------------gunIndex is not 0 ------------------------------------------------//
  7627. //check Transaction active
  7628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7629. {
  7630. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7631. {
  7632. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7633. {
  7634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7635. goto end;
  7636. }
  7637. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7639. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7640. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7642. {
  7643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7644. goto end;
  7645. }
  7646. else
  7647. {
  7648. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7650. goto end;
  7651. }
  7652. }
  7653. }//END FOR CHAdeMO_QUANTITY
  7654. for (int index = 0; index < CCS_QUANTITY; index++)
  7655. {
  7656. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7657. {
  7658. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7659. {
  7660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7661. goto end;
  7662. }
  7663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7668. {
  7669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7670. goto end;
  7671. }
  7672. else
  7673. {
  7674. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7676. goto end;
  7677. }
  7678. }
  7679. }//END FOR CCS_QUANTITY
  7680. for (int index = 0; index < GB_QUANTITY; index++)
  7681. {
  7682. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7683. {
  7684. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7685. {
  7686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7687. goto end;
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7692. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7693. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7696. goto end;
  7697. }
  7698. else
  7699. {
  7700. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7701. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7702. goto end;
  7703. }
  7704. }
  7705. }// END FOR GB_QUANTITY
  7706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7707. {
  7708. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7709. {
  7710. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7711. {
  7712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7713. goto end;
  7714. }
  7715. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7718. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7720. {
  7721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7722. goto end;
  7723. }
  7724. else
  7725. {
  7726. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7728. goto end;
  7729. }
  7730. }
  7731. }// END FOR GENERAL_GUN_QUANTITY
  7732. for (int index = 0; index < AC_QUANTITY; index++)
  7733. {
  7734. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7735. {
  7736. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7737. {
  7738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7739. goto end;
  7740. }
  7741. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7745. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7746. {
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7748. goto end;
  7749. }
  7750. else
  7751. {
  7752. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7753. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7754. goto end;
  7755. }
  7756. }
  7757. }//END FOR AC_QUANTITY
  7758. }//END FOR AvailabilityTypeStr[Inoperative]
  7759. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7760. {
  7761. //----------------------gunIndex is 0 ------------------------------------------------//
  7762. if(gunIndex == 0)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7765. {
  7766. for(int i=0; i < gunTotalNumber; i++)
  7767. {
  7768. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7769. {
  7770. 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
  7771. {
  7772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7773. goto end;
  7774. }
  7775. }//END FOR CHAdeMO_QUANTITY
  7776. for (int index = 0; index < CCS_QUANTITY; index++)
  7777. {
  7778. 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
  7779. {
  7780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7781. goto end;
  7782. }
  7783. }//END FOR CCS_QUANTITY
  7784. for (int index = 0; index < GB_QUANTITY; index++)
  7785. {
  7786. 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
  7787. {
  7788. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7790. goto end;
  7791. }
  7792. }// END FOR GB_QUANTITY
  7793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7794. {
  7795. 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
  7796. {
  7797. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7799. goto end;
  7800. }
  7801. }// END FOR GENERAL_GUN_QUANTITY
  7802. for (int index = 0; index < AC_QUANTITY; index++)
  7803. {
  7804. 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
  7805. {
  7806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7807. goto end;
  7808. }
  7809. }//END FOR CHAdeMO_QUANTITY
  7810. }// END FOR gunTotalNumber
  7811. }
  7812. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7813. {
  7814. for(int i=0; i < gunTotalNumber; i++)
  7815. {
  7816. for (int index = 0; index < AC_QUANTITY; index++)
  7817. {
  7818. 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
  7819. {
  7820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7821. goto end;
  7822. }
  7823. }//END FOR CHAdeMO_QUANTITY
  7824. } // END FOR gunTotalNumber
  7825. }
  7826. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7827. goto end;
  7828. }
  7829. //----------------------gunIndex is not 0 ------------------------------------------------//
  7830. //check Transaction active
  7831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7832. {
  7833. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7834. {
  7835. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7836. goto end;
  7837. }
  7838. }//END FOR CHAdeMO_QUANTITY
  7839. for (int index = 0; index < CCS_QUANTITY; index++)
  7840. {
  7841. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7842. {
  7843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7844. goto end;
  7845. }
  7846. }//END FOR CCS_QUANTITY
  7847. for (int index = 0; index < GB_QUANTITY; index++)
  7848. {
  7849. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7850. {
  7851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7852. goto end;
  7853. }
  7854. }// END FOR GB_QUANTITY
  7855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7856. {
  7857. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7858. {
  7859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7860. goto end;
  7861. }
  7862. }// END FOR GENERAL_GUN_QUANTITY
  7863. for (int index = 0; index < AC_QUANTITY; index++)
  7864. {
  7865. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7866. {
  7867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7868. goto end;
  7869. }
  7870. }//END FOR AC_QUANTITY
  7871. }//END FOR AvailabilityTypeStr[Operative]
  7872. end:
  7873. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7874. {
  7875. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7876. }
  7877. else
  7878. {
  7879. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7880. }
  7881. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7882. {
  7883. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7884. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7885. }
  7886. else if(gunIndex == 0)
  7887. {
  7888. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7889. {
  7890. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7891. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7892. }
  7893. }
  7894. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7896. return result;
  7897. }
  7898. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7899. {
  7900. mtrace();
  7901. int result = FAIL;
  7902. char keystr[40]={0};
  7903. char valuestr[256]={0};
  7904. char comfirmstr[20]={0};
  7905. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7906. json_object *ChangeConfiguration;
  7907. ChangeConfiguration = json_tokener_parse(payload);
  7908. if(!is_error(ChangeConfiguration))
  7909. {
  7910. // Required data
  7911. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7912. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7913. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7914. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7915. }
  7916. json_object_put(ChangeConfiguration);
  7917. if((uuid==NULL) || (payload ==NULL) )
  7918. {
  7919. DEBUG_ERROR("Payload is null\n");
  7920. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7921. }
  7922. else
  7923. {
  7924. int status = setKeyValue(keystr, valuestr);
  7925. switch(status)
  7926. {
  7927. case ConfigurationStatus_Accepted:
  7928. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7929. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7930. StoreConfigurationTable();
  7931. break;
  7932. case RebootRequired:
  7933. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7934. StoreConfigurationTable();
  7935. break;
  7936. case NotSupported:
  7937. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7938. break;
  7939. case ConfigurationStatus_Rejected:
  7940. default:
  7941. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7942. break;
  7943. }
  7944. }
  7945. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7946. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7947. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7948. {
  7949. ChageWebSocketPingInterval(atoi(valuestr));
  7950. }
  7951. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7952. {
  7953. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7954. SetOcppConnStatus(FALSE);
  7955. }
  7956. return result;
  7957. }
  7958. int handleClearCacheRequest(char *uuid, char *payload)
  7959. {
  7960. mtrace();
  7961. int result = FAIL;
  7962. char comfirmstr[20];
  7963. char rmFileCmd[100]={0};
  7964. struct stat stats;
  7965. DEBUG_INFO("handleClearCacheRequest...\n");
  7966. stat("/Storage/OCPP", &stats);
  7967. // Check for directory existence
  7968. if (S_ISDIR(stats.st_mode) == 1)
  7969. {}
  7970. else
  7971. {
  7972. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7973. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7974. system(rmFileCmd);
  7975. }
  7976. if(OCPP_cleanLocalCache())
  7977. {
  7978. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7979. }
  7980. else
  7981. {
  7982. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7983. }
  7984. sendClearCacheConfirmation(uuid, comfirmstr);
  7985. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7986. return result;
  7987. }
  7988. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7989. {
  7990. mtrace();
  7991. int result = FAIL;
  7992. int resultRename;
  7993. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7994. char chargingProfilePurposeStr[26]={0};
  7995. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7996. char tempchargingProfilePurposeStr[26]={0};
  7997. char str[100]={0};
  7998. char fname[200]={0};
  7999. char comfirmstr[20]={0};
  8000. char word[1600]={0};
  8001. int clearflag = FALSE;
  8002. int chargingProfileIdIsNULL = FALSE;
  8003. int connectorIsNULL = FALSE;
  8004. int chargingProfilePurposeIsNULL = FALSE;
  8005. int stackLevelIsNULL = FALSE;
  8006. //int GotoEnd = FALSE;
  8007. FILE *fptr1, *fptr2;
  8008. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8009. int n_chargingProfile=0;
  8010. int isEmptyFile = FALSE;
  8011. char sLineWord[1600]={0};
  8012. char chargingProfiles[10][100]={0};
  8013. int ChargeProfileCount = 0;
  8014. int ch;
  8015. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8016. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8017. json_object *ClearChargingProfile;
  8018. ClearChargingProfile = json_tokener_parse(payload);
  8019. if(!is_error(ClearChargingProfile))
  8020. {
  8021. // Optional data
  8022. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8023. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8024. else
  8025. chargingProfileIdIsNULL = TRUE;
  8026. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8027. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8028. else
  8029. connectorIsNULL = TRUE;
  8030. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8031. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8032. else
  8033. chargingProfilePurposeIsNULL = TRUE;
  8034. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8035. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8036. else
  8037. stackLevelIsNULL = TRUE;
  8038. }
  8039. json_object_put(ClearChargingProfile);
  8040. if(connectorIsNULL == FALSE)
  8041. {
  8042. switch(connectorIdInt)
  8043. {
  8044. case 0:
  8045. if(chargingProfilePurposeIsNULL == TRUE)
  8046. {
  8047. int l = 0;
  8048. strcpy(fname, ChargePointMaxProfile_JSON);
  8049. if((access(fname,F_OK))!=-1)
  8050. {
  8051. strcpy(chargingProfiles[l], fname);
  8052. l = l + 1;
  8053. }
  8054. strcpy(fname, TxDefaultProfile_0_JSON);
  8055. if((access(fname,F_OK))!=-1)
  8056. {
  8057. strcpy(chargingProfiles[l], fname);
  8058. l = l + 1;
  8059. }
  8060. ChargeProfileCount = l;
  8061. }
  8062. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8063. {
  8064. strcpy(fname, ChargePointMaxProfile_JSON);
  8065. if((access(fname,F_OK))!=-1)
  8066. {
  8067. strcpy(chargingProfiles[0], fname);
  8068. ChargeProfileCount = 1;
  8069. }
  8070. }
  8071. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8072. {
  8073. strcpy(fname, TxDefaultProfile_0_JSON);
  8074. if((access(fname,F_OK))!=-1)
  8075. {
  8076. strcpy(chargingProfiles[0], fname);
  8077. ChargeProfileCount = 1;
  8078. }
  8079. }
  8080. break;
  8081. default:
  8082. if(chargingProfilePurposeIsNULL == TRUE)
  8083. {
  8084. int m = 0;
  8085. memset(fname, 0, ARRAY_SIZE(fname));
  8086. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8087. if((access(fname,F_OK))!=-1)
  8088. {
  8089. strcpy(chargingProfiles[m], fname);
  8090. m = m + 1;
  8091. }
  8092. memset(fname, 0, ARRAY_SIZE(fname));
  8093. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8094. if((access(fname,F_OK))!=-1)
  8095. {
  8096. strcpy(chargingProfiles[m], fname);
  8097. m = m + 1;
  8098. }
  8099. ChargeProfileCount = m;
  8100. }
  8101. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8102. {
  8103. //strcpy(fname, TxDefaultProfile_1_JSON);
  8104. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8105. if((access(fname,F_OK))!=-1)
  8106. {
  8107. strcpy(chargingProfiles[0], fname);
  8108. ChargeProfileCount = 1;
  8109. }
  8110. }
  8111. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8112. {
  8113. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8114. if((access(fname,F_OK))!=-1)
  8115. {
  8116. strcpy(chargingProfiles[0], fname);
  8117. ChargeProfileCount = 1;
  8118. }
  8119. //strcpy(fname, TxProfile_1_JSON);
  8120. }
  8121. //strcpy(fname, ChargePointMaxProfile_JSON );
  8122. break;
  8123. }
  8124. }
  8125. else // Check all Charging Profiles
  8126. {
  8127. int i = 0;
  8128. char fnametemp[200]={0};
  8129. ChargeProfileCount = 0;
  8130. //Check ChargePointMaxProfile.json exit
  8131. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8132. {
  8133. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8134. i = i + 1;
  8135. }
  8136. //Check TxDefaultProfile_0.json exit
  8137. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8138. {
  8139. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8140. i = i + 1;
  8141. }
  8142. //Check TxDefaultProfile_%d.json
  8143. for(int j=1; j <= gunTotalNumber; j++)
  8144. {
  8145. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8146. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8147. if((access(fnametemp,F_OK))!=-1)
  8148. {
  8149. strcpy(chargingProfiles[i], fnametemp);
  8150. i = i + 1;
  8151. }
  8152. }
  8153. //Check TxProfile_%d.json
  8154. for(int j=1; j <= gunTotalNumber; j++)
  8155. {
  8156. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8157. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8158. if((access(fnametemp,F_OK))!=-1)
  8159. {
  8160. strcpy(chargingProfiles[i], fnametemp);
  8161. i = i + 1;
  8162. }
  8163. }
  8164. ChargeProfileCount = i;
  8165. }// End connectorIsNULL is TRUE
  8166. if(ChargeProfileCount == 0)
  8167. {
  8168. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8169. goto end;
  8170. }
  8171. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8172. {
  8173. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8174. goto end;
  8175. }
  8176. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8177. {
  8178. memset(str, 0, ARRAY_SIZE(str));
  8179. // clear temp file
  8180. sprintf(str,"rm -f %s",temp);
  8181. system(str);
  8182. for(int k=0; k < ChargeProfileCount; k++)
  8183. {
  8184. memset(str, 0, ARRAY_SIZE(str));
  8185. //clear file in C
  8186. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8187. system(str);
  8188. }
  8189. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8190. goto end;
  8191. }
  8192. else if(connectorIsNULL == TRUE)
  8193. {
  8194. for(int k=0; k < ChargeProfileCount; k++)
  8195. {
  8196. fptr1 = fopen(chargingProfiles[k], "r");
  8197. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8198. //Check Charging Profile Count
  8199. while(fscanf(fptr1, "%s", word) != EOF)
  8200. {
  8201. //DEBUG_INFO("word=%s\n",word);
  8202. if(strstr(word, "chargingProfileId")!= NULL)
  8203. {
  8204. //DEBUG_INFO("test chargingProfileId \n");
  8205. n_chargingProfile = n_chargingProfile + 1;
  8206. //DEBUG_INFO("chargingProfileId Found\n");
  8207. }
  8208. }
  8209. rewind(fptr1);
  8210. //search Charging Profile Element
  8211. //int i= 0;
  8212. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8213. {
  8214. json_object *tmpProfilee;
  8215. tmpProfilee = json_tokener_parse(sLineWord);
  8216. if(!is_error(tmpProfilee))
  8217. {
  8218. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8219. {
  8220. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8221. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8222. }
  8223. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8224. {
  8225. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8226. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8227. }
  8228. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8229. {
  8230. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8231. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8232. }
  8233. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8234. {
  8235. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8236. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8237. }
  8238. }
  8239. json_object_put(tmpProfilee);
  8240. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8241. {
  8242. //------- not write to fptr2-------//
  8243. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8244. //clearflag = TRUE;
  8245. }
  8246. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8247. {
  8248. //------- not write to fptr2-------//
  8249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8250. }
  8251. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8252. {
  8253. //------- not write to fptr2-------//
  8254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8255. }
  8256. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8257. {
  8258. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8259. }
  8260. else
  8261. {
  8262. fprintf(fptr2, sLineWord);//writing data into file
  8263. }
  8264. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8265. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8266. if(clearflag == TRUE)
  8267. {
  8268. fclose(fptr1);
  8269. fclose(fptr2);
  8270. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8271. system(str);
  8272. // clear temp file
  8273. sprintf(str,"rm -f %s",temp);
  8274. system(str);
  8275. }
  8276. else
  8277. {
  8278. fclose(fptr1);
  8279. fclose(fptr2);
  8280. memset(str, 0, ARRAY_SIZE(str));
  8281. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8282. system(str);
  8283. resultRename = rename(temp, chargingProfiles[k]);
  8284. if(resultRename == 0)
  8285. {
  8286. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8287. }
  8288. else
  8289. {
  8290. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8291. }
  8292. if(comfirmstr[0]== 0)
  8293. {
  8294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8295. }
  8296. //Check chargingProfile is empty file
  8297. /*------ Read the file ----------------*/
  8298. fptr1=fopen(chargingProfiles[k],"r");
  8299. ch=fgetc(fptr1);
  8300. rewind(fptr1);
  8301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8302. if(ch!=EOF)
  8303. {
  8304. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8305. {
  8306. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8307. if(sLineWord[0]=='\0')
  8308. {
  8309. isEmptyFile = TRUE;
  8310. break;
  8311. }
  8312. else
  8313. {
  8314. isEmptyFile = FALSE;
  8315. break;
  8316. }
  8317. }
  8318. }
  8319. else
  8320. isEmptyFile = TRUE;
  8321. fclose(fptr1);
  8322. if(isEmptyFile == TRUE)
  8323. {
  8324. memset(str, 0, ARRAY_SIZE(str));
  8325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8326. system(str);
  8327. }
  8328. }
  8329. }// End of while(int k=0; k < ChargePointCount; k++)
  8330. }
  8331. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8332. {
  8333. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8334. for(int k=0; k < ChargeProfileCount; k++)
  8335. {
  8336. fptr1 = fopen(chargingProfiles[k], "r");
  8337. fptr2 = fopen(temp, "w+");
  8338. //Check Charging Profile Count
  8339. while(fscanf(fptr1, "%s", word) != EOF)
  8340. {
  8341. //DEBUG_INFO("word=%s\n",word);
  8342. if(strstr(word, "chargingProfileId")!= NULL)
  8343. {
  8344. n_chargingProfile = n_chargingProfile + 1;
  8345. }
  8346. }
  8347. rewind(fptr1);
  8348. //search Charging Profile Element
  8349. //int i= 0;
  8350. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8351. {
  8352. json_object *tmpProfilee;
  8353. tmpProfilee = json_tokener_parse(sLineWord);
  8354. if(!is_error(tmpProfilee))
  8355. {
  8356. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8357. {
  8358. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8359. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8360. }
  8361. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8362. {
  8363. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8364. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8365. }
  8366. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8367. {
  8368. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8369. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8370. }
  8371. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8372. {
  8373. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8374. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8375. }
  8376. }
  8377. json_object_put(tmpProfilee);
  8378. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8379. {
  8380. //------- not write to fptr2-------//
  8381. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8382. //clearflag = TRUE;
  8383. }
  8384. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8385. {
  8386. //------- not write to fptr2-------//
  8387. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8388. }
  8389. else if(stackLevelIsNULL == TRUE)
  8390. {
  8391. //Clear Whole File
  8392. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8393. clearflag = TRUE;
  8394. break;
  8395. }
  8396. else
  8397. {
  8398. fprintf(fptr2, sLineWord);//writing data into file
  8399. }
  8400. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8401. }
  8402. if(clearflag == TRUE)
  8403. {
  8404. fclose(fptr1);
  8405. fclose(fptr2);
  8406. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8407. system(str);
  8408. // clear temp file
  8409. sprintf(str,"rm -f %s",temp);
  8410. system(str);
  8411. }
  8412. else
  8413. {
  8414. fclose(fptr1);
  8415. fclose(fptr2);
  8416. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8417. system(str);
  8418. resultRename = rename(temp, chargingProfiles[k]);
  8419. if(resultRename == 0)
  8420. {
  8421. DEBUG_INFO("File ChargingProfile renamed successfully");
  8422. }
  8423. else
  8424. {
  8425. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8426. }
  8427. if(comfirmstr[0]== 0)
  8428. {
  8429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8430. }
  8431. //Check chargingProfile is empty file
  8432. /*------ Read the file ----------------*/
  8433. fptr1=fopen(chargingProfiles[k],"r");
  8434. ch=fgetc(fptr1);
  8435. rewind(fptr1);
  8436. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8437. if(ch!=EOF)
  8438. {
  8439. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8440. {
  8441. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8442. if(sLineWord[0]=='\0')
  8443. {
  8444. isEmptyFile = TRUE;
  8445. break;
  8446. }
  8447. else
  8448. {
  8449. isEmptyFile = FALSE;
  8450. break;
  8451. }
  8452. }
  8453. }
  8454. else
  8455. isEmptyFile = TRUE;
  8456. fclose(fptr1);
  8457. if(isEmptyFile == TRUE)
  8458. {
  8459. memset(str, 0, ARRAY_SIZE(str));
  8460. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8461. system(str);
  8462. }
  8463. /*------- End of reading ---------------*/
  8464. }
  8465. } // while(int k=0; k < ChargeProfileCount; k++)
  8466. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8467. end:
  8468. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8469. {
  8470. if(connectorIdInt == 0)
  8471. {
  8472. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8473. {
  8474. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8475. }
  8476. }
  8477. else
  8478. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8479. }
  8480. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8481. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8482. return result;
  8483. }
  8484. void createFirmwareVersionByDataTransfer(void)
  8485. {
  8486. json_object *FirmwareDataTransfer = json_object_new_object();
  8487. // AC & DC model
  8488. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8489. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8490. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8491. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8492. // DC model
  8493. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8494. {
  8495. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8496. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8497. (gunType[3] != GUN_TYPE_UNKNOWN))
  8498. {
  8499. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8500. }
  8501. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8502. {
  8503. // DS DM DW
  8504. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8505. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8506. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8507. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8508. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8509. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8510. }
  8511. else
  8512. {
  8513. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8514. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8515. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8516. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8517. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8518. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8519. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8520. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8521. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8522. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8523. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8524. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8525. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8526. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8527. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8528. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8529. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8530. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8531. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8532. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8533. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8534. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8535. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8536. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8537. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8538. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8539. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8540. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8541. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8542. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8543. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8544. }
  8545. }
  8546. // 4G model
  8547. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8548. {
  8549. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8550. }
  8551. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8552. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8553. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8554. json_object_put(FirmwareDataTransfer);
  8555. }
  8556. int handleDataTransferRequest(char *uuid, char *payload)
  8557. {
  8558. mtrace();
  8559. json_object *response = json_object_new_object();
  8560. int result = FAIL;
  8561. char tempvendorId[255]={0};
  8562. char tempmessageId[50]={0};
  8563. char tempdata[512]={0};
  8564. char message[2048]={0};
  8565. DEBUG_INFO("handleDataTransferRequest...\n");
  8566. if((uuid != NULL) && (payload != NULL))
  8567. {
  8568. json_object *DataTransfer;
  8569. DataTransfer = json_tokener_parse(payload);
  8570. if(!is_error(DataTransfer))
  8571. {
  8572. // Required data
  8573. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8574. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8575. // Optional data
  8576. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8577. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8578. if(json_object_object_get(DataTransfer, "data") != NULL)
  8579. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8580. result = PASS;
  8581. }
  8582. json_object_put(DataTransfer);
  8583. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8584. {
  8585. // Send all moudle firmware version on EVSE
  8586. createFirmwareVersionByDataTransfer();
  8587. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8588. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8589. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8590. json_object_put(response);
  8591. }
  8592. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8593. {
  8594. system("/usr/bin/run_tmate_restart.sh &");
  8595. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8596. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8597. json_object_put(response);
  8598. }
  8599. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8600. {
  8601. json_object *data;
  8602. data = json_tokener_parse(tempdata);
  8603. if(!is_error(data))
  8604. {
  8605. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8606. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8607. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8608. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8609. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8610. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8611. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8612. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8613. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8614. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8615. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8616. }
  8617. else
  8618. {
  8619. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8620. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8621. }
  8622. json_object_put(data);
  8623. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8624. json_object_put(response);
  8625. }
  8626. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8627. {
  8628. json_object *data;
  8629. data = json_tokener_parse(tempdata);
  8630. if(!is_error(data))
  8631. {
  8632. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8633. if(json_object_object_get(data, "idToken") != NULL)
  8634. {
  8635. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8636. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8637. }
  8638. if(json_object_object_get(data, "price") != NULL)
  8639. {
  8640. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8641. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8642. }
  8643. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8644. }
  8645. else
  8646. {
  8647. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8648. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8649. }
  8650. json_object_put(data);
  8651. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8652. json_object_put(response);
  8653. }
  8654. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8655. {
  8656. json_object *data;
  8657. data = json_tokener_parse(tempdata);
  8658. if(!is_error(data))
  8659. {
  8660. if(json_object_object_get(data, "txId") != NULL)
  8661. {
  8662. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8663. for(int idx = 0;idx<gunTotalNumber;idx++)
  8664. {
  8665. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8666. {
  8667. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8668. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8669. if(json_object_object_get(data, "description") != NULL)
  8670. {
  8671. // California pricing V1.0
  8672. DEBUG_INFO("California pricing V1.0\n");
  8673. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8674. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8675. }
  8676. else
  8677. {
  8678. // California pricing V1.1
  8679. DEBUG_INFO("California pricing V1.1\n");
  8680. if(json_object_object_get(data, "timestamp") != NULL)
  8681. {
  8682. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8683. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8684. }
  8685. if(json_object_object_get(data, "meterValue") != NULL)
  8686. {
  8687. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8688. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8689. }
  8690. if(json_object_object_get(data, "cost") != NULL)
  8691. {
  8692. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8693. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8694. }
  8695. if(json_object_object_get(data, "state") != NULL)
  8696. {
  8697. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8698. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8699. }
  8700. if(json_object_object_get(data, "chargingPrice") != NULL)
  8701. {
  8702. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8703. {
  8704. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8705. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8706. }
  8707. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8708. {
  8709. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8710. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8711. }
  8712. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8713. {
  8714. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8715. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8716. }
  8717. }
  8718. if(json_object_object_get(data, "idlePrice") != NULL)
  8719. {
  8720. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8721. {
  8722. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8723. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8724. }
  8725. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8726. {
  8727. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8728. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8729. }
  8730. }
  8731. if(json_object_object_get(data, "nextPeriod") != NULL)
  8732. {
  8733. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8734. {
  8735. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8736. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8737. }
  8738. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8739. {
  8740. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8741. {
  8742. 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")));
  8743. 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"));
  8744. }
  8745. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8746. {
  8747. 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")));
  8748. 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"));
  8749. }
  8750. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8751. {
  8752. 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")));
  8753. 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"));
  8754. }
  8755. }
  8756. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8757. {
  8758. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8759. {
  8760. 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")));
  8761. 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"));
  8762. }
  8763. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8764. {
  8765. 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")));
  8766. 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"));
  8767. }
  8768. }
  8769. }
  8770. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8771. {
  8772. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8773. {
  8774. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8775. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8776. }
  8777. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8778. {
  8779. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8780. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8781. }
  8782. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8783. {
  8784. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8785. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8786. }
  8787. }
  8788. }
  8789. }
  8790. }
  8791. }
  8792. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8793. }
  8794. else
  8795. {
  8796. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8797. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8798. }
  8799. json_object_put(data);
  8800. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8801. json_object_put(response);
  8802. }
  8803. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8804. {
  8805. json_object *data;
  8806. data = json_tokener_parse(tempdata);
  8807. if(!is_error(data))
  8808. {
  8809. if(json_object_object_get(data, "txId") != NULL)
  8810. {
  8811. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8812. for(int idx = 0;idx<gunTotalNumber;idx++)
  8813. {
  8814. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8815. {
  8816. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8817. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8818. if(json_object_object_get(data, "description") != NULL)
  8819. {
  8820. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8821. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8822. }
  8823. }
  8824. }
  8825. }
  8826. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8827. }
  8828. else
  8829. {
  8830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8831. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8832. }
  8833. json_object_put(data);
  8834. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8835. json_object_put(response);
  8836. }
  8837. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8838. {
  8839. json_object *data;
  8840. data = json_tokener_parse(tempdata);
  8841. if(!is_error(data))
  8842. {
  8843. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8844. if(json_object_object_get(data, "Content_Type") != NULL)
  8845. {
  8846. 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))
  8847. {
  8848. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8849. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8850. {
  8851. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8852. }
  8853. }
  8854. else
  8855. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8856. }
  8857. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8858. }
  8859. else
  8860. {
  8861. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8862. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8863. }
  8864. json_object_put(data);
  8865. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8866. json_object_put(response);
  8867. }
  8868. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8869. {
  8870. json_object *data;
  8871. data = json_tokener_parse(tempdata);
  8872. if(!is_error(data))
  8873. {
  8874. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8875. if(json_object_object_get(data, "Page_Index") != NULL)
  8876. {
  8877. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8878. }
  8879. if(json_object_object_get(data, "Duration") != NULL)
  8880. {
  8881. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8882. }
  8883. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8884. }
  8885. else
  8886. {
  8887. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8888. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8889. }
  8890. json_object_put(data);
  8891. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8892. json_object_put(response);
  8893. }
  8894. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8895. {
  8896. json_object *data;
  8897. data = json_tokener_parse(tempdata);
  8898. if(!is_error(data))
  8899. {
  8900. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8901. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8902. {
  8903. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8904. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8905. else
  8906. {
  8907. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8908. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8909. }
  8910. }
  8911. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8912. {
  8913. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8914. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8915. else
  8916. {
  8917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8918. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8919. }
  8920. }
  8921. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8922. {
  8923. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8924. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8925. else
  8926. {
  8927. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8928. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8929. }
  8930. }
  8931. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8932. {
  8933. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8934. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8935. else
  8936. {
  8937. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8938. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8939. }
  8940. }
  8941. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8942. {
  8943. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8944. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8945. else
  8946. {
  8947. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8948. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8949. }
  8950. }
  8951. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8952. {
  8953. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8954. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8955. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8956. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8957. else
  8958. {
  8959. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8960. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8961. }
  8962. }
  8963. if(json_object_object_get(data, "isAuthentication") != NULL)
  8964. {
  8965. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8966. {
  8967. case 0:
  8968. case 1:
  8969. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8970. break;
  8971. default:
  8972. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8973. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8974. break;
  8975. }
  8976. }
  8977. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8978. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8979. }
  8980. else
  8981. {
  8982. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8983. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8984. }
  8985. json_object_put(data);
  8986. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8987. json_object_put(response);
  8988. }
  8989. else
  8990. {
  8991. // Can not find valid message id
  8992. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8993. }
  8994. }
  8995. else
  8996. {
  8997. // Payload is null
  8998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8999. }
  9000. LWS_Send(message);
  9001. return result;
  9002. }
  9003. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9004. {
  9005. mtrace();
  9006. int result = FAIL;
  9007. int connectorIdInt, durationInt;
  9008. char chargingRateUnitStr[4]={0};
  9009. char comfirmstr[20];
  9010. int confirmPeriods = 0;
  9011. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9012. json_object *GetCompositeSchedule;
  9013. GetCompositeSchedule = json_tokener_parse(payload);
  9014. if(!is_error(GetCompositeSchedule))
  9015. {
  9016. // Required data
  9017. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9018. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9019. else
  9020. connectorIdInt = -1;
  9021. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9022. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9023. else
  9024. durationInt = 86400;
  9025. // Optional data
  9026. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9027. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9028. }
  9029. json_object_put(GetCompositeSchedule);
  9030. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9031. if((connectorIdInt == 0) ||
  9032. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9033. {
  9034. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9035. struct StructChargingProfile tmpProfile[1];
  9036. if(strstr(chargingRateUnitStr, "W") != NULL)
  9037. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9038. else
  9039. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9040. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9041. {
  9042. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9043. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9044. }
  9045. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9046. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9047. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9048. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9049. {
  9050. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9051. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9052. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9053. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9054. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9055. {
  9056. confirmPeriods = idx;
  9057. break;
  9058. }
  9059. }
  9060. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9061. {
  9062. confirmPeriods += 1;
  9063. }
  9064. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9065. }
  9066. else
  9067. {
  9068. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9069. }
  9070. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9071. return result;
  9072. }
  9073. int handleGetConfigurationRequest(char *uuid, char *payload)
  9074. {
  9075. mtrace();
  9076. int result = FAIL;
  9077. int MaxKeySupported = 0;
  9078. int n_keys = 0;
  9079. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9080. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9081. json_object *GetConfiguration;
  9082. GetConfiguration = json_tokener_parse(payload);
  9083. if(!is_error(GetConfiguration))
  9084. {
  9085. // Optional data
  9086. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9087. {
  9088. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9089. {
  9090. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9091. n_keys = idx + 1;
  9092. }
  9093. }
  9094. }
  9095. json_object_put(GetConfiguration);
  9096. UnknownKeynum = 0;
  9097. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9098. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9099. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9100. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9101. if(n_keys != 0)
  9102. {
  9103. for(int i=0;i<n_keys;i++)
  9104. {
  9105. getKeyValue(requestKey[i]);
  9106. }
  9107. }
  9108. else
  9109. {
  9110. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9111. getKeyValue("");
  9112. }
  9113. processUnkownKey();
  9114. sendGetConfigurationConfirmation(uuid);
  9115. return result;
  9116. }
  9117. static char fnamePlusPath[100]={0};
  9118. static char fnamePWithNoPath[60]={0};
  9119. void checkUploadLog(void)
  9120. {
  9121. FILE *fp;
  9122. /* Open the command for reading. */
  9123. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9124. if (fp == NULL) {
  9125. DEBUG_WARN("Failed to run command\n" );
  9126. exit(1);
  9127. }
  9128. int ftppathlen = 0;
  9129. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9130. int i = 0;
  9131. /* Read the output a line at a time - output it. */
  9132. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9133. if(i==0)
  9134. {
  9135. ftppathlen = strlen(fnamePlusPath);
  9136. DEBUG_INFO("%s\n", fnamePlusPath);
  9137. fnamePlusPath[ftppathlen]='\0';
  9138. break;
  9139. }
  9140. i= i+1;
  9141. }
  9142. /* close */
  9143. pclose(fp);
  9144. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9145. {
  9146. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9147. {
  9148. fnamePlusPath[k]='\0';
  9149. }
  9150. }
  9151. i=1;
  9152. //char fname[60]={0};
  9153. while(i < ftppathlen)
  9154. {
  9155. int len=ftppathlen-i;
  9156. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9157. {
  9158. DEBUG_INFO("compare '/' all right\n");
  9159. break;
  9160. }
  9161. i=i+1;
  9162. }
  9163. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9164. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9165. fnamePWithNoPath[i+1] = '\0';
  9166. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9167. {
  9168. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9169. {
  9170. fnamePWithNoPath[j]='\0';
  9171. }
  9172. }
  9173. FILE* fp1 = fopen(fnamePlusPath, "r");
  9174. if (fp1)
  9175. {
  9176. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9177. // file exists
  9178. fclose(fp1);
  9179. }
  9180. else
  9181. {
  9182. // file doesn't exist
  9183. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9184. }
  9185. }
  9186. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9187. {
  9188. mtrace();
  9189. int result = FAIL;
  9190. time_t CurrentTime;
  9191. struct tm *tm;
  9192. pthread_t th_Status;
  9193. CurrentTime = time(NULL);
  9194. tm = localtime(&CurrentTime);
  9195. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9196. 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);
  9197. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9198. if(!interLock.isGetDiagnosticGoing)
  9199. {
  9200. interLock.isGetDiagnosticGoing = 1;
  9201. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9202. sleep(1);
  9203. }
  9204. else
  9205. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9206. return result;
  9207. }
  9208. void* GetDiagnosticsProcess(void* data)
  9209. {
  9210. pthread_detach(pthread_self());
  9211. mtrace();
  9212. int retriesInt=0, retryIntervalInt=0;
  9213. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9214. 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};
  9215. int port=0;
  9216. int isSuccess = FALSE;
  9217. char cmdBuf[2048];
  9218. struct tm *tmNow;
  9219. time_t CurrentTime;
  9220. struct tm tmStart;
  9221. struct tm tmStop;
  9222. CurrentTime = time(NULL);
  9223. tmNow=localtime(&CurrentTime);
  9224. uint16_t targetYear, targetMonth;
  9225. json_object *GetDiagnostics;
  9226. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9227. GetDiagnostics = json_tokener_parse(data);
  9228. if(!is_error(GetDiagnostics))
  9229. {
  9230. // Required data
  9231. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9232. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9233. // Optional data
  9234. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9235. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9236. else
  9237. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9238. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9239. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9240. else
  9241. retryIntervalInt = 30;
  9242. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9243. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9244. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9245. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9246. }
  9247. json_object_put(GetDiagnostics);
  9248. // Pack log to compress file
  9249. 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) &&
  9250. (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))
  9251. {
  9252. // Pack system log
  9253. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9254. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9255. targetYear = tmStart.tm_year;
  9256. targetMonth = tmStart.tm_mon;
  9257. do
  9258. {
  9259. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9260. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9261. if(targetMonth+1>=13)
  9262. {
  9263. targetYear += 1;
  9264. targetMonth = 1;
  9265. }
  9266. else
  9267. {
  9268. targetMonth += 1;
  9269. }
  9270. }while((targetYear < (tmNow->tm_year+1900)) ||
  9271. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9272. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9273. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9274. system(cmdBuf);
  9275. // Pack charging & event log
  9276. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9277. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9278. targetYear = tmStart.tm_year;
  9279. targetMonth = tmStart.tm_mon;
  9280. do
  9281. {
  9282. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9283. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9284. if(targetMonth+1>=13)
  9285. {
  9286. targetYear += 1;
  9287. targetMonth = 1;
  9288. }
  9289. else
  9290. {
  9291. targetMonth += 1;
  9292. }
  9293. }while((targetYear < (tmNow->tm_year+1900)) ||
  9294. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9295. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9296. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9297. system(cmdBuf);
  9298. // Combine log file
  9299. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9300. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9301. }
  9302. else
  9303. {
  9304. system("exec /root/logPackTools 'log' 6");
  9305. }
  9306. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9307. system(cmdBuf);
  9308. checkUploadLog();
  9309. //****************location*******************/
  9310. if(strcmp(locationstr,"")==0)
  9311. {
  9312. DEBUG_INFO("location is <Empty>!\n");
  9313. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9314. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9315. goto end;
  9316. }
  9317. memset(protocol, 0, ARRAY_SIZE(protocol));
  9318. memset(user, 0, ARRAY_SIZE(user) );
  9319. memset(password, 0, ARRAY_SIZE(password));
  9320. memset(host, 0, ARRAY_SIZE(host));
  9321. memset(path, 0, ARRAY_SIZE(path));
  9322. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9323. memset(host1, 0, ARRAY_SIZE(host1));
  9324. memset(path1, 0, ARRAY_SIZE(path1));
  9325. /*location: ftp://user:password@host:port/path*/
  9326. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9327. if((access(fnamePlusPath,F_OK))!=-1)
  9328. {
  9329. DEBUG_INFO("fnamePlusPath exist.\n");
  9330. }
  9331. else
  9332. {
  9333. DEBUG_INFO("fnamePlusPath not exist!\n");
  9334. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9335. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9336. goto end;
  9337. }
  9338. if(strchr(locationstr,'@')==NULL)
  9339. {
  9340. sscanf(locationstr,
  9341. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9342. protocol, host, &port, path);
  9343. strcpy(user,"anonymous");
  9344. strcpy(password,"");
  9345. }
  9346. else
  9347. {
  9348. //DEBUG_INFO("pch=%s\n", pch);
  9349. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9350. protocol, user, password, host, &port, path);
  9351. }
  9352. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9353. {
  9354. DEBUG_INFO("protocol is not ftp/http ! \n");
  9355. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9356. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9357. goto end;
  9358. }
  9359. if(strncmp(locationstr,"http", 4) == 0)
  9360. {
  9361. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9362. sprintf(ftppath,"/%s", path);
  9363. do
  9364. {
  9365. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9366. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9367. sleep(3);
  9368. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9369. if(!isSuccess)
  9370. {
  9371. DEBUG_INFO("Diagnostics fail.\n");
  9372. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9373. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9374. sleep(retryIntervalInt);
  9375. }
  9376. else
  9377. {
  9378. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9379. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9380. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9381. }
  9382. retriesInt--;
  9383. }while((isSuccess == 0)&&(retriesInt >= 0));
  9384. }
  9385. else
  9386. {
  9387. sscanf(host,"%[^/]%s",host1, path1);
  9388. if(strlen(path) > 0)
  9389. sprintf(ftppath,"/%s", path);
  9390. else
  9391. sprintf(ftppath,"/%s", path1);
  9392. int ftppathlen=strlen(ftppath);
  9393. int i=1;
  9394. char filenametemp[50];
  9395. while(i < ftppathlen)
  9396. {
  9397. int len=ftppathlen-i;
  9398. if(ftppath[len]== 47) // '/' ascll code: 47
  9399. {
  9400. DEBUG_INFO("find '/' all right\n");
  9401. break;
  9402. }
  9403. i=i+1;
  9404. }
  9405. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9406. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9407. filenametemp[i+1] = 0;
  9408. if(port == 0)
  9409. port = 21;
  9410. do
  9411. {
  9412. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9413. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9414. sleep(3);
  9415. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9416. if(!isSuccess)
  9417. {
  9418. DEBUG_INFO("Diagnostics fail.\n");
  9419. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9420. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9421. sleep(retryIntervalInt);
  9422. }
  9423. else
  9424. {
  9425. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9426. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9427. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9428. }
  9429. retriesInt--;
  9430. }while((!isSuccess)&&(retriesInt >= 0));
  9431. }
  9432. end:
  9433. system("rm -f /mnt/*");
  9434. sleep(5);
  9435. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9436. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9437. interLock.isGetDiagnosticGoing = 0;
  9438. pthread_exit(NULL);
  9439. }
  9440. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9441. {
  9442. mtrace();
  9443. int result = FAIL;
  9444. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9445. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9446. {
  9447. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9448. locallistVersion = -1;
  9449. }
  9450. else
  9451. {
  9452. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9453. OCPP_getListVerion();
  9454. }
  9455. //from db.OCPP_getListVerion
  9456. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9457. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9458. sendGetLocalListVersionConfirmation(uuid,"");
  9459. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9460. return result;
  9461. }
  9462. int handleRemoteStartRequest(char *uuid, char *payload)
  9463. {
  9464. mtrace();
  9465. int result = FAIL;
  9466. int connectorIdInt=-1;
  9467. int tempIndex = 0;
  9468. int connectorIdIsNULL, chargingProfileIsNULL;
  9469. char comfirmstr[20]={0};
  9470. char cmdBuf[512];
  9471. json_object *RemoteStartTransaction;
  9472. FILE *fp;
  9473. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9474. if(server_pending == TRUE)
  9475. {
  9476. return 0;
  9477. }
  9478. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9479. RemoteStartTransaction = json_tokener_parse(payload);
  9480. if(!is_error(RemoteStartTransaction))
  9481. {
  9482. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9483. {
  9484. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9485. }
  9486. else
  9487. {
  9488. connectorIdIsNULL = TRUE;
  9489. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9490. {
  9491. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9492. {
  9493. connectorIdIsNULL = FALSE;
  9494. connectorIdInt = (gun_index+1);
  9495. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9496. break;
  9497. }
  9498. }
  9499. }
  9500. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9501. {
  9502. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9503. // Required data
  9504. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9505. // Optional data
  9506. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9507. {
  9508. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9509. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9510. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9511. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9512. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9513. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9514. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9515. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9516. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9517. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9518. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9519. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9520. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9521. {
  9522. 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")));
  9523. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9524. 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"));
  9525. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9526. 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"));
  9527. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9528. 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")));
  9529. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9530. {
  9531. 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++)
  9532. {
  9533. 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"));
  9534. 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"));
  9535. 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)
  9536. 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"));
  9537. }
  9538. }
  9539. }
  9540. }
  9541. else
  9542. {
  9543. chargingProfileIsNULL = TRUE;
  9544. }
  9545. }
  9546. }
  9547. else
  9548. {
  9549. connectorIdIsNULL = TRUE;
  9550. }
  9551. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9552. {
  9553. DEBUG_WARN("Connector id is NULL\n.");
  9554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9555. goto end;
  9556. }
  9557. /*
  9558. enum _SYSTEM_STATUS
  9559. {
  9560. S_BOOTING = 0,
  9561. S_IDLE, = 1
  9562. S_AUTHORIZING, = 2
  9563. S_REASSIGN_CHECK, = 3
  9564. S_REASSIGN, = 4
  9565. S_PRECHARGE, = 5
  9566. S_PREPARING_FOR_EV, = 6
  9567. S_PREPARING_FOR_EVSE, = 7
  9568. S_CHARGING, = 8
  9569. S_TERMINATING, = 9
  9570. S_COMPLETE, = 10
  9571. S_ALARM, = 11
  9572. S_FAULT = 12
  9573. }
  9574. */
  9575. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9576. {
  9577. //check Transaction active
  9578. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9579. {
  9580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9581. {
  9582. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9583. }
  9584. else
  9585. {
  9586. tempIndex = connectorIdInt -1;
  9587. }
  9588. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9589. {
  9590. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9591. {
  9592. 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))
  9593. {
  9594. //Reserved
  9595. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9596. }
  9597. 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))
  9598. {
  9599. //Reserved
  9600. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9601. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9602. goto end;
  9603. }
  9604. else
  9605. {
  9606. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9607. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9608. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9609. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9610. {
  9611. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9613. goto end;
  9614. }
  9615. }//END FOR ELSE
  9616. }
  9617. }// END FOR CHAdeMO_QUANTITY
  9618. }
  9619. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9620. {
  9621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9622. {
  9623. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9624. }
  9625. else
  9626. {
  9627. tempIndex = connectorIdInt -1;
  9628. }
  9629. for (int index = 0; index < CCS_QUANTITY; index++)
  9630. {
  9631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9632. {
  9633. 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))
  9634. {
  9635. //Reserved
  9636. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9637. }
  9638. 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))
  9639. {
  9640. //Reserved
  9641. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9642. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9643. goto end;
  9644. }
  9645. else
  9646. {
  9647. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9648. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9649. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9650. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9651. {
  9652. DEBUG_WARN("CCS connector not allow start\n.");
  9653. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9654. goto end;
  9655. }
  9656. }// END FOR ELSE
  9657. }
  9658. }// END FOR CCS_QUANTITY
  9659. }
  9660. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9661. {
  9662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9663. {
  9664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9665. }
  9666. else
  9667. {
  9668. tempIndex = connectorIdInt -1;
  9669. }
  9670. for (int index = 0; index < GB_QUANTITY; index++)
  9671. {
  9672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9673. {
  9674. 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))
  9675. {
  9676. //Reserved
  9677. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9678. }
  9679. 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))
  9680. {
  9681. //Reserved
  9682. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9684. goto end;
  9685. }
  9686. else
  9687. {
  9688. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9689. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9690. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9691. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9692. {
  9693. DEBUG_WARN("GB connector not allow start\n.");
  9694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9695. goto end;
  9696. }
  9697. }// END FOR ELSE
  9698. }
  9699. } // END FOR GB_QUANTITY
  9700. }
  9701. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9702. {
  9703. tempIndex = connectorIdInt -1;
  9704. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9705. {
  9706. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9707. {
  9708. 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))
  9709. {
  9710. //Reserved
  9711. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9712. }
  9713. 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))
  9714. {
  9715. //Reserved
  9716. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9718. goto end;
  9719. }
  9720. else
  9721. {
  9722. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9723. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9724. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9725. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9726. {
  9727. DEBUG_WARN("GB connector not allow start\n.");
  9728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9729. goto end;
  9730. }
  9731. }// END FOR ELSE
  9732. }
  9733. } // END FOR GB_QUANTITY
  9734. }
  9735. else
  9736. {
  9737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9738. {
  9739. tempIndex = 2;
  9740. }
  9741. else
  9742. {
  9743. tempIndex = connectorIdInt -1;
  9744. }
  9745. for (int index = 0; index < AC_QUANTITY; index++)
  9746. {
  9747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9748. {
  9749. 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))
  9750. {
  9751. //Reserved
  9752. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9753. }
  9754. 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))
  9755. {
  9756. //Reserved
  9757. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9758. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9759. goto end;
  9760. }
  9761. else
  9762. {
  9763. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9764. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9765. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9766. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9767. {
  9768. DEBUG_WARN("AC connector not allow start\n.");
  9769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9770. goto end;
  9771. }
  9772. }//END FOR ELSE
  9773. }
  9774. }// END FOR AC_QUANTITY
  9775. }
  9776. if(chargingProfileIsNULL == FALSE)
  9777. {
  9778. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9779. {
  9780. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9782. //memset idTag
  9783. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9784. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9785. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9786. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9787. // Save profile to file
  9788. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9789. system(cmdBuf);
  9790. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9791. fp = fopen(cmdBuf, "w");
  9792. 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));
  9793. fclose(fp);
  9794. }
  9795. else
  9796. {
  9797. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9798. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9799. }
  9800. }
  9801. else
  9802. {
  9803. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9804. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9805. //memset idTag
  9806. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9807. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9808. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9809. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9810. }
  9811. }
  9812. else
  9813. {
  9814. DEBUG_WARN("Connector id over\n.");
  9815. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9816. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9817. }
  9818. end:
  9819. json_object_put(RemoteStartTransaction);
  9820. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9821. {
  9822. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9823. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9824. }
  9825. //OCPP send RemoteStartConfirmation by first.
  9826. sendRemoteStartConfirmation(uuid, comfirmstr);
  9827. return result;
  9828. }
  9829. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9830. {
  9831. mtrace();
  9832. int result = FAIL;
  9833. int match = FALSE;
  9834. int GunNO = 0;
  9835. int tempIndex = 0;
  9836. int transactionIdInt=0;
  9837. int transactionIdIsNULL= TRUE;
  9838. char comfirmstr[20];
  9839. json_object *RemoteStopTransaction;
  9840. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9841. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9842. if(server_pending == TRUE)
  9843. {
  9844. return 0;
  9845. }
  9846. RemoteStopTransaction = json_tokener_parse(payload);
  9847. if(!is_error(RemoteStopTransaction))
  9848. {
  9849. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9850. {
  9851. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9852. transactionIdIsNULL = FALSE;
  9853. }
  9854. }
  9855. json_object_put(RemoteStopTransaction);
  9856. if(transactionIdIsNULL == FALSE)
  9857. {
  9858. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9859. {
  9860. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9861. {
  9862. //check Transaction active
  9863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9864. {
  9865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9866. {
  9867. tempIndex = ((gun_index==2) ? 1: 0);
  9868. }
  9869. else
  9870. {
  9871. tempIndex = gun_index;
  9872. }
  9873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9874. {
  9875. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9876. {
  9877. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9878. {
  9879. match = TRUE;
  9880. GunNO = gun_index;
  9881. }
  9882. }
  9883. }// END FOR CHAdeMO_QUANTITY
  9884. }
  9885. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9886. {
  9887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9888. {
  9889. tempIndex = ((gun_index==2) ? 1: 0);
  9890. }
  9891. else
  9892. {
  9893. tempIndex = gun_index;
  9894. }
  9895. for (int index = 0; index < CCS_QUANTITY; index++)
  9896. {
  9897. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9898. {
  9899. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9900. {
  9901. match = TRUE;
  9902. GunNO = gun_index;
  9903. }
  9904. }
  9905. }// END FOR CCS_QUANTITY
  9906. }
  9907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9908. {
  9909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9910. {
  9911. tempIndex = ((gun_index==2) ? 1: 0);
  9912. }
  9913. else
  9914. {
  9915. tempIndex = gun_index;
  9916. }
  9917. for (int index = 0; index < GB_QUANTITY; index++)
  9918. {
  9919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9920. {
  9921. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9922. {
  9923. match = TRUE;
  9924. GunNO = gun_index;
  9925. }
  9926. }
  9927. }// END FOR GB_QUANTITY
  9928. }
  9929. else if(gunType[gun_index] == GUN_TYPE_DO)
  9930. {
  9931. tempIndex = gun_index;
  9932. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9933. {
  9934. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9935. {
  9936. 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
  9937. {
  9938. match = TRUE;
  9939. GunNO = gun_index;
  9940. }
  9941. }
  9942. }// END FOR GB_QUANTITY
  9943. }
  9944. else
  9945. {
  9946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9947. {
  9948. tempIndex = 2;
  9949. }
  9950. else
  9951. {
  9952. tempIndex = gun_index;
  9953. }
  9954. for (int index = 0; index < AC_QUANTITY; index++)
  9955. {
  9956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9957. {
  9958. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9959. {
  9960. match = TRUE;
  9961. GunNO = gun_index;
  9962. }
  9963. }
  9964. }// END FOR CHAdeMO_QUANTITY
  9965. } // END FOR AC ELSE
  9966. }// CHECK IF ResponseTransactionId == transactionIdInt
  9967. }//END FOR
  9968. if( match == TRUE)
  9969. {
  9970. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9971. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9972. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9973. }
  9974. else
  9975. {
  9976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9977. }
  9978. }
  9979. else
  9980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9981. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9982. return result;
  9983. }
  9984. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9985. {
  9986. mtrace();
  9987. int result = FAIL;
  9988. int connectorIdInt=0, reservationIdInt=0;
  9989. int tempIndex = 0;
  9990. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9991. char comfirmstr[20]={0};
  9992. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9993. int c = 0;
  9994. char *loc;
  9995. //char *ptr;
  9996. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9997. strcpy(sstrtemp, stringtrimspace(payload));
  9998. //***(1)connectorId ****/
  9999. c=0;
  10000. loc = strstr(sstrtemp, "connectorId");
  10001. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10002. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10003. {
  10004. sstr[c] = loc[strlen("connectorId")+2+c];
  10005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10006. c++;
  10007. }
  10008. sstr[c] = '\0';
  10009. connectorIdInt = atoi(sstr);
  10010. //***(2)expiryDate ****/
  10011. loc = strstr(sstrtemp, "expiryDate");
  10012. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10013. c = 0;
  10014. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10015. {
  10016. sstr[c] = loc[3+strlen("expiryDate")+c];
  10017. c++;
  10018. }
  10019. sstr[c] = '\0';
  10020. strcpy(expiryDatestr, sstr);
  10021. //***(3)idTag ****/
  10022. loc = strstr(sstrtemp, "idTag");
  10023. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10024. c = 0;
  10025. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10026. {
  10027. sstr[c] = loc[3+strlen("idTag")+c];
  10028. c++;
  10029. }
  10030. sstr[c] = '\0';
  10031. strcpy(idTagstr, sstr);
  10032. //***(4)parentIdTag ****/
  10033. loc = strstr(sstrtemp, "parentIdTag");
  10034. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10035. c = 0;
  10036. if(loc == NULL)
  10037. {
  10038. strcpy(parentIdTagstr, "");
  10039. }
  10040. else
  10041. {
  10042. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10043. {
  10044. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10045. c++;
  10046. }
  10047. sstr[c] = '\0';
  10048. strcpy(parentIdTagstr, sstr);
  10049. }
  10050. //***(5)reservationId ****/
  10051. c=0;
  10052. loc = strstr(sstrtemp, "reservationId");
  10053. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10054. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10055. {
  10056. sstr[c] = loc[strlen("reservationId")+2+c];
  10057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10058. c++;
  10059. }
  10060. sstr[c] = '\0';
  10061. reservationIdInt = atoi(sstr);
  10062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10063. /*
  10064. enum SYSTEM_STATUS
  10065. {
  10066. SYS_MODE_BOOTING = 0,
  10067. SYS_MODE_IDLE = 1,
  10068. SYS_MODE_AUTHORIZING = 2,
  10069. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10070. SYS_MODE_REASSIGN = 4,
  10071. SYS_MODE_PREPARING = 5,
  10072. SYS_MODE_PREPARE_FOR_EV = 6,
  10073. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10074. SYS_MODE_CHARGING = 8,
  10075. SYS_MODE_TERMINATING = 9,
  10076. SYS_MODE_COMPLETE = 10,
  10077. SYS_MODE_ALARM = 11,
  10078. SYS_MODE_FAULT = 12,
  10079. SYS_MODE_RESERVATION = 13,
  10080. SYS_MODE_BOOKING = 14,
  10081. SYS_MODE_MAINTAIN = 15,
  10082. SYS_MODE_DEBUG = 16,
  10083. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10084. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10085. SYS_MODE_UPDATE = 19
  10086. };
  10087. */
  10088. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10089. {
  10090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10091. goto end;
  10092. }
  10093. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10094. {
  10095. //check Transaction active
  10096. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10097. {
  10098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10099. {
  10100. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10101. }
  10102. else
  10103. {
  10104. tempIndex = connectorIdInt -1;
  10105. }
  10106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10107. {
  10108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10109. {
  10110. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10111. {
  10112. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10113. {
  10114. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10115. {
  10116. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10118. }
  10119. 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'))
  10120. {
  10121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10122. }
  10123. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10124. {
  10125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10126. }
  10127. else
  10128. {
  10129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10130. }
  10131. }
  10132. 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
  10133. {
  10134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10135. }
  10136. }
  10137. else
  10138. {
  10139. //replace reservation
  10140. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10142. }
  10143. }
  10144. } // END FOR CHAdeMO_QUANTITY
  10145. }
  10146. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10147. {
  10148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10149. {
  10150. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10151. }
  10152. else
  10153. {
  10154. tempIndex = connectorIdInt -1;
  10155. }
  10156. for (int index = 0; index < CCS_QUANTITY; index++)
  10157. {
  10158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10159. {
  10160. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10161. {
  10162. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10163. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10164. {
  10165. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10166. {
  10167. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10169. }
  10170. 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'))
  10171. {
  10172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10173. }
  10174. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10175. {
  10176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10177. }
  10178. else
  10179. {
  10180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10181. }
  10182. }
  10183. 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
  10184. {
  10185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10186. }
  10187. }
  10188. else
  10189. {
  10190. //replace reservation
  10191. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10193. }
  10194. }
  10195. } // END FOR CCS_QUANTITY
  10196. }
  10197. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10198. {
  10199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10200. {
  10201. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10202. }
  10203. else
  10204. {
  10205. tempIndex = connectorIdInt -1;
  10206. }
  10207. for (int index = 0; index < GB_QUANTITY; index++)
  10208. {
  10209. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10210. {
  10211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10212. {
  10213. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10214. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10215. {
  10216. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10217. {
  10218. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10220. }
  10221. 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'))
  10222. {
  10223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10224. }
  10225. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10226. {
  10227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10228. }
  10229. else
  10230. {
  10231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10232. }
  10233. }
  10234. 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
  10235. {
  10236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10237. }
  10238. }
  10239. else
  10240. {
  10241. //replace reservation
  10242. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10244. }
  10245. }
  10246. }// END FOR GB_QUANTITY
  10247. }
  10248. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10249. {
  10250. tempIndex = connectorIdInt -1;
  10251. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10252. {
  10253. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10254. {
  10255. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10256. {
  10257. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10258. 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
  10259. {
  10260. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10261. {
  10262. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10264. }
  10265. 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'))
  10266. {
  10267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10268. }
  10269. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10270. {
  10271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10272. }
  10273. else
  10274. {
  10275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10276. }
  10277. }
  10278. 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
  10279. {
  10280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10281. }
  10282. }
  10283. else
  10284. {
  10285. //replace reservation
  10286. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10288. }
  10289. }
  10290. }// END FOR GB_QUANTITY
  10291. }
  10292. else
  10293. {
  10294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10295. {
  10296. tempIndex = 2;
  10297. }
  10298. else
  10299. {
  10300. tempIndex = (connectorIdInt -1);
  10301. }
  10302. for (int index = 0; index < AC_QUANTITY; index++)
  10303. {
  10304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10305. {
  10306. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10307. {
  10308. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10309. {
  10310. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10311. {
  10312. 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))
  10313. {
  10314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10315. }
  10316. else
  10317. {
  10318. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10320. }
  10321. }
  10322. 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'))
  10323. {
  10324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10325. }
  10326. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10327. {
  10328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10329. }
  10330. else
  10331. {
  10332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10333. }
  10334. }
  10335. 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
  10336. {
  10337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10338. }
  10339. }
  10340. else
  10341. {
  10342. //replace reservation
  10343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10345. }
  10346. }
  10347. } // END FOR AC_QUANTITY
  10348. }
  10349. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10350. }
  10351. else if(connectorIdInt == 0)
  10352. {
  10353. //check Transaction active
  10354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10355. {
  10356. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10357. {
  10358. 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'))
  10359. {
  10360. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10361. goto end;
  10362. }
  10363. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10364. {
  10365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10366. goto end;
  10367. }
  10368. 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
  10369. {
  10370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10371. goto end;
  10372. }
  10373. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10374. {
  10375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10376. goto end;
  10377. }
  10378. }
  10379. }// END FOR CHAdeMO_QUANTITY
  10380. for (int index = 0; index < CCS_QUANTITY; index++)
  10381. {
  10382. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10383. {
  10384. 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'))
  10385. {
  10386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10387. goto end;
  10388. }
  10389. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10390. {
  10391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10392. goto end;
  10393. }
  10394. 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
  10395. {
  10396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10397. goto end;
  10398. }
  10399. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10400. {
  10401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10402. goto end;
  10403. }
  10404. }
  10405. } // END FOR CCS_QUANTITY
  10406. for (int index = 0; index < GB_QUANTITY; index++)
  10407. {
  10408. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10409. {
  10410. 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'))
  10411. {
  10412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10413. goto end;
  10414. }
  10415. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10416. {
  10417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10418. goto end;
  10419. }
  10420. 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
  10421. {
  10422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10423. goto end;
  10424. }
  10425. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10426. {
  10427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10428. goto end;
  10429. }
  10430. }
  10431. } // END FOR GB_QUANTITY
  10432. for (int index = 0; index < AC_QUANTITY; index++)
  10433. {
  10434. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10435. {
  10436. 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'))
  10437. {
  10438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10439. goto end;
  10440. }
  10441. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10442. {
  10443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10444. goto end;
  10445. }
  10446. 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
  10447. {
  10448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10449. goto end;
  10450. }
  10451. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10452. {
  10453. 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))
  10454. {
  10455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10456. goto end;
  10457. }
  10458. }
  10459. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10460. {
  10461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10462. goto end;
  10463. }
  10464. }
  10465. }// END FOR AC_QUANTITY
  10466. //The connectorId is 0
  10467. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10469. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10470. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10471. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10472. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10473. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10474. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10475. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10476. result = TRUE;
  10477. return result;
  10478. }
  10479. else
  10480. {
  10481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10482. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10483. }
  10484. if(strcmp(comfirmstr,"Accepted") == 0)
  10485. {
  10486. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10487. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10488. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10489. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10490. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10491. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10492. result = TRUE;
  10493. return result;
  10494. }
  10495. end:
  10496. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10497. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10498. return result;
  10499. }
  10500. int handleResetRequest(char *uuid, char *payload)
  10501. {
  10502. mtrace();
  10503. int result = FAIL;
  10504. char sstr[10]={0},sstrtemp[30]={ 0 };
  10505. char typestr[10]={0};
  10506. char comfirmstr[20]={0};
  10507. int c = 0;
  10508. char *loc;
  10509. DEBUG_INFO("handleResetRequest...\n");
  10510. strcpy(sstrtemp, stringtrimspace(payload));
  10511. loc = strstr(sstrtemp, "type");
  10512. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10513. c = 0;
  10514. while (loc[3+strlen("type")+c] != '\"')
  10515. {
  10516. sstr[c] = loc[3+strlen("type")+c];
  10517. c++;
  10518. }
  10519. sstr[c] = '\0';
  10520. strcpy(typestr,sstr);
  10521. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10522. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10523. {
  10524. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10525. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10526. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10527. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10528. }
  10529. else
  10530. {
  10531. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10532. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10533. result = PASS;
  10534. }
  10535. sendResetConfirmation(uuid, comfirmstr);
  10536. return result;
  10537. }
  10538. int handleSendLocalListRequest(char *uuid, char *payload)
  10539. {
  10540. mtrace();
  10541. int result = FAIL;
  10542. char comfirmstr[20];
  10543. int checkState_Faulted = FALSE;
  10544. json_object *SendLocalList;
  10545. DEBUG_INFO("handleSendLocalListRequest...\n");
  10546. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10547. {
  10548. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10549. goto end;
  10550. }
  10551. //check Charge Point state
  10552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10553. {
  10554. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10555. {
  10556. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10557. }
  10558. }
  10559. for (int index = 0; index < CCS_QUANTITY; index++)
  10560. {
  10561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10562. {
  10563. checkState_Faulted = TRUE; //OCPP Status
  10564. }
  10565. }
  10566. for (int index = 0; index < GB_QUANTITY; index++)
  10567. {
  10568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10569. {
  10570. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10571. }
  10572. }
  10573. //check Charge Point state
  10574. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10575. {
  10576. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10577. {
  10578. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10579. }
  10580. }
  10581. //check Charge Point state
  10582. for (int index = 0; index < AC_QUANTITY; index++)
  10583. {
  10584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10585. {
  10586. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10587. }
  10588. }
  10589. if(checkState_Faulted == TRUE)
  10590. {
  10591. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10592. goto end;
  10593. }
  10594. // Parsing payload
  10595. SendLocalList = json_tokener_parse(payload);
  10596. if(!is_error(SendLocalList))
  10597. {
  10598. // Required data
  10599. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10600. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10601. // Optional data
  10602. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10603. {
  10604. //Check UpdateType
  10605. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10606. {
  10607. //Local list full update
  10608. DEBUG_INFO("Local list full update.\n");
  10609. OCPP_getListVerion();
  10610. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10611. {
  10612. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10613. goto end;
  10614. }
  10615. OCPP_cleanLocalList();
  10616. }
  10617. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10618. {
  10619. //Local list different update
  10620. DEBUG_INFO("Local list different update.\n");
  10621. OCPP_getListVerion();
  10622. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10623. {
  10624. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10625. goto end;
  10626. }
  10627. }
  10628. else
  10629. {
  10630. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10631. goto end;
  10632. }
  10633. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10634. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10635. {
  10636. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10637. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10638. {
  10639. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10640. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10641. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10642. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10643. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10644. }
  10645. // Add to db
  10646. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10647. {
  10648. //Local list full update
  10649. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10650. idx,
  10651. ShmOCPP16Data->SendLocalList.ListVersion,
  10652. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10653. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10654. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10655. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10656. // update list
  10657. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10658. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10659. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10660. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10661. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10662. }
  10663. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10664. {
  10665. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10666. idx,
  10667. ShmOCPP16Data->SendLocalList.ListVersion,
  10668. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10669. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10670. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10671. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10672. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10673. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10674. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10675. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10676. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10677. }
  10678. }
  10679. }
  10680. else
  10681. {
  10682. //Check UpdateType
  10683. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10684. {
  10685. //Local list full update
  10686. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10687. OCPP_cleanLocalList();
  10688. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10689. goto end;
  10690. }
  10691. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10692. {
  10693. //Local list different update
  10694. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10696. goto end;
  10697. }
  10698. }
  10699. result = PASS;
  10700. }
  10701. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10702. end:
  10703. json_object_put(SendLocalList);
  10704. sendSendLocalListConfirmation(uuid, comfirmstr);
  10705. return result;
  10706. }
  10707. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10708. {
  10709. mtrace();
  10710. int result = FAIL;
  10711. struct StructSetChargingProfile SetProfileReq = {0};
  10712. int tempchargingProfileIdInt;
  10713. int chargingSchedulePeriodCount = 0;
  10714. char comfirmstr[20]={0};
  10715. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10716. char rmFileCmd[128]={0};
  10717. int profileQuantity = 0;
  10718. json_object *SetChargingProfile;
  10719. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10720. SetChargingProfile = json_tokener_parse(payload);
  10721. if(!is_error(SetChargingProfile))
  10722. {
  10723. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10724. {
  10725. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10726. }
  10727. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10728. {
  10729. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10730. {
  10731. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10732. }
  10733. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10734. {
  10735. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10736. }
  10737. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10738. {
  10739. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10740. }
  10741. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10742. {
  10743. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10744. }
  10745. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10746. {
  10747. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10748. }
  10749. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10750. {
  10751. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10752. }
  10753. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10754. {
  10755. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10756. }
  10757. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10758. {
  10759. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10760. }
  10761. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10762. {
  10763. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10764. {
  10765. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10766. }
  10767. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10768. {
  10769. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10770. }
  10771. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10772. {
  10773. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10774. }
  10775. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10776. {
  10777. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10778. }
  10779. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10780. {
  10781. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10782. if(chargingSchedulePeriodCount <= 10)
  10783. {
  10784. 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++)
  10785. {
  10786. 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)
  10787. {
  10788. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10789. }
  10790. 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)
  10791. {
  10792. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10793. }
  10794. 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)
  10795. {
  10796. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10797. }
  10798. }
  10799. }
  10800. }
  10801. }
  10802. }
  10803. }
  10804. // Profile periods quantity check
  10805. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10806. {
  10807. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10808. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10809. goto end;
  10810. }
  10811. // Profile purpose info check
  10812. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10813. {
  10814. FILE *fp;
  10815. char dataLine[4096]={0};
  10816. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10817. if(SetProfileReq.ConnectorId != 0)
  10818. {
  10819. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10820. DEBUG_WARN("Profile connector id is not 0.\n");
  10821. goto end;
  10822. }
  10823. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10824. if (!fp)
  10825. {
  10826. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10827. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10828. }
  10829. else
  10830. {
  10831. while(fscanf(fp, "%s", dataLine) != EOF)
  10832. {
  10833. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10834. {
  10835. profileQuantity += 1;
  10836. }
  10837. }
  10838. }
  10839. fclose(fp);
  10840. }
  10841. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10842. {
  10843. FILE *fp;
  10844. char dataLine[4096]={0};
  10845. char filename[128]={0};
  10846. int tmpProfileQuantity;
  10847. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10848. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10849. {
  10850. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10851. DEBUG_WARN("Profile connector id is over max gun number.\n");
  10852. goto end;
  10853. }
  10854. if(SetProfileReq.ConnectorId == 0)
  10855. {
  10856. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10857. {
  10858. tmpProfileQuantity = 0;
  10859. memset(filename, 0, ARRAY_SIZE(filename));
  10860. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10861. fp = fopen(filename, "r");
  10862. if (!fp)
  10863. {
  10864. DEBUG_INFO("%s does not create.\n", filename);
  10865. fp = fopen(filename, "w+");
  10866. }
  10867. else
  10868. {
  10869. while(fscanf(fp, "%s", dataLine) != EOF)
  10870. {
  10871. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10872. {
  10873. tmpProfileQuantity += 1;
  10874. }
  10875. }
  10876. }
  10877. fclose(fp);
  10878. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10879. }
  10880. }
  10881. else
  10882. {
  10883. memset(filename, 0, ARRAY_SIZE(filename));
  10884. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10885. fp = fopen(filename, "r");
  10886. if (!fp)
  10887. {
  10888. DEBUG_INFO("%s does not create.\n", filename);
  10889. fp = fopen(filename, "w+");
  10890. }
  10891. else
  10892. {
  10893. while(fscanf(fp, "%s", dataLine) != EOF)
  10894. {
  10895. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10896. {
  10897. profileQuantity += 1;
  10898. }
  10899. }
  10900. }
  10901. fclose(fp);
  10902. }
  10903. }
  10904. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10905. {
  10906. int isMatchTransactiodId= FALSE;
  10907. FILE *fp;
  10908. char dataLine[4096]={0};
  10909. char filename[128]={0};
  10910. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10911. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10912. if(SetProfileReq.ConnectorId == 0)
  10913. {
  10914. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10915. DEBUG_WARN("Profile connector id is 0.\n");
  10916. goto end;
  10917. }
  10918. int tempIndex = 0;
  10919. //check Transaction active
  10920. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10921. {
  10922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10923. {
  10924. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10925. }
  10926. else
  10927. {
  10928. tempIndex = SetProfileReq.ConnectorId -1;
  10929. }
  10930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10931. {
  10932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10933. {
  10934. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10935. {
  10936. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10937. {
  10938. isMatchTransactiodId = TRUE;
  10939. break;
  10940. }
  10941. }
  10942. }
  10943. }
  10944. }
  10945. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10946. {
  10947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10948. {
  10949. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10950. }
  10951. else
  10952. {
  10953. tempIndex = SetProfileReq.ConnectorId -1;
  10954. }
  10955. for (int index = 0; index < CCS_QUANTITY; index++)
  10956. {
  10957. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10958. {
  10959. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  10960. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10961. {
  10962. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10963. {
  10964. isMatchTransactiodId = TRUE;
  10965. break;
  10966. }
  10967. }
  10968. }
  10969. }
  10970. }
  10971. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10972. {
  10973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10974. {
  10975. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10976. }
  10977. else
  10978. {
  10979. tempIndex = SetProfileReq.ConnectorId -1;
  10980. }
  10981. for (int index = 0; index < GB_QUANTITY; index++)
  10982. {
  10983. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10984. {
  10985. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10986. {
  10987. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10988. {
  10989. isMatchTransactiodId = TRUE;
  10990. break;
  10991. }
  10992. }
  10993. }
  10994. }
  10995. }
  10996. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10997. {
  10998. tempIndex = SetProfileReq.ConnectorId -1;
  10999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11000. {
  11001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11002. {
  11003. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11004. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11005. {
  11006. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11007. {
  11008. isMatchTransactiodId = TRUE;
  11009. break;
  11010. }
  11011. }
  11012. }
  11013. }
  11014. }
  11015. else
  11016. {
  11017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11018. {
  11019. tempIndex = 2;
  11020. }
  11021. else
  11022. {
  11023. tempIndex = (SetProfileReq.ConnectorId -1);
  11024. }
  11025. for (int index = 0; index < AC_QUANTITY; index++)
  11026. {
  11027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11028. {
  11029. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11030. {
  11031. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11032. {
  11033. isMatchTransactiodId = TRUE;
  11034. break;
  11035. }
  11036. }
  11037. }
  11038. }
  11039. }
  11040. //check Transaction active
  11041. if(isMatchTransactiodId == FALSE)
  11042. {
  11043. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11044. DEBUG_WARN("Tx profile transaction id is not match.\n");
  11045. goto end;
  11046. }
  11047. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11048. {
  11049. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11050. DEBUG_WARN("Connector id is over max gun number.\n");
  11051. goto end;
  11052. }
  11053. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11054. fp = fopen(filename, "r");
  11055. if (!fp)
  11056. {
  11057. DEBUG_INFO("%s does not create.\n", filename);
  11058. fp = fopen(filename, "w+");
  11059. }
  11060. else
  11061. {
  11062. //Check Charging Profile Count
  11063. while(fscanf(fp, "%s", dataLine) != EOF)
  11064. {
  11065. //DEBUG_INFO("word=%s\n",word);
  11066. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11067. {
  11068. profileQuantity += 1;
  11069. }
  11070. }
  11071. }
  11072. fclose(fp);
  11073. }
  11074. // Check ChargeProfileMaxStackLevel
  11075. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11076. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11077. {
  11078. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11079. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11080. goto end;
  11081. }
  11082. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11083. {
  11084. FILE *fp;
  11085. char dataLine[4096]={0};
  11086. char fnametemp[128]={0};
  11087. int tmpProfileQuantity;
  11088. //Check ChargePointMaxProfile.json exit
  11089. profileQuantity = 0;
  11090. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11091. {
  11092. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11093. //Check Charging Profile Count
  11094. tmpProfileQuantity = 0;
  11095. while(fscanf(fp, "%s", dataLine) != EOF)
  11096. {
  11097. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11098. {
  11099. profileQuantity += 1;
  11100. tmpProfileQuantity += 1;
  11101. }
  11102. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11103. }
  11104. fclose(fp);
  11105. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11106. }
  11107. //Check TxDefaultProfile_%d.json
  11108. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11109. {
  11110. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11111. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11112. if((access(fnametemp,F_OK))!=-1)
  11113. {
  11114. fp = fopen(fnametemp, "r");
  11115. //Check Charging Profile Count
  11116. tmpProfileQuantity = 0;
  11117. while(fscanf(fp, "%s", dataLine) != EOF)
  11118. {
  11119. //DEBUG_INFO("word=%s\n",word);
  11120. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11121. {
  11122. profileQuantity += 1;
  11123. tmpProfileQuantity += 1;
  11124. }
  11125. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11126. }
  11127. fclose(fp);
  11128. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11129. }
  11130. }
  11131. //Check TxProfile_%d.json
  11132. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11133. {
  11134. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11135. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11136. if((access(fnametemp,F_OK))!=-1)
  11137. {
  11138. fp = fopen(fnametemp, "r");
  11139. //Check Charging Profile Count
  11140. tmpProfileQuantity = 0;
  11141. while(fscanf(fp, "%s", dataLine) != EOF)
  11142. {
  11143. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11144. {
  11145. profileQuantity += 1;
  11146. tmpProfileQuantity += 1;
  11147. }
  11148. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11149. }
  11150. fclose(fp);
  11151. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11152. }
  11153. }
  11154. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11155. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11156. {
  11157. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11158. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11159. goto end;
  11160. }
  11161. }
  11162. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11163. //**********************************Write to File********************************************************/
  11164. {
  11165. FILE *infile;
  11166. FILE *outfile;
  11167. char dataLine[4096]={0};
  11168. char filename[128]={0};
  11169. int chkChar=0;
  11170. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11171. {
  11172. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11173. {
  11174. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11175. }
  11176. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11177. {
  11178. if(SetProfileReq.ConnectorId==0)
  11179. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11180. else
  11181. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11182. }
  11183. else
  11184. {
  11185. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11186. }
  11187. infile = fopen (filename, "r");
  11188. outfile = fopen (tempfile, "w");
  11189. chkChar = fgetc(infile);
  11190. rewind(infile);
  11191. if(chkChar == EOF)
  11192. {
  11193. // Profile is empty
  11194. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11195. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11196. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11197. fclose(infile);
  11198. fclose(outfile);
  11199. sprintf(rmFileCmd,"rm -f %s",filename);
  11200. system(rmFileCmd);
  11201. rename(tempfile, filename);
  11202. }
  11203. else
  11204. {
  11205. // Profile is not empty
  11206. int ChargingProfileAdded = FALSE;
  11207. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11208. {
  11209. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11210. json_object *tmpChargingProfile;
  11211. tmpChargingProfile = json_tokener_parse(dataLine);
  11212. if(!is_error(SetChargingProfile))
  11213. {
  11214. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11215. {
  11216. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11217. {
  11218. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11219. }
  11220. }
  11221. }
  11222. json_object_put(tmpChargingProfile);
  11223. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11224. {
  11225. if(ChargingProfileAdded == FALSE)
  11226. {
  11227. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11228. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11229. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11230. ChargingProfileAdded = TRUE;
  11231. }
  11232. }
  11233. else
  11234. {
  11235. fprintf(outfile,"%s\n",dataLine);
  11236. if(ChargingProfileAdded == FALSE)
  11237. {
  11238. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11239. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11240. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11241. ChargingProfileAdded = TRUE;
  11242. }
  11243. }
  11244. } // end of while loop
  11245. fclose(infile);
  11246. fclose(outfile);
  11247. sprintf(rmFileCmd,"rm -f %s",filename);
  11248. system(rmFileCmd);
  11249. rename(tempfile, filename);
  11250. }
  11251. }
  11252. sleep(1);
  11253. result = TRUE;
  11254. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11255. }
  11256. end:
  11257. json_object_put(SetChargingProfile);
  11258. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11259. {
  11260. if(SetProfileReq.ConnectorId == 0)
  11261. {
  11262. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11263. {
  11264. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11265. }
  11266. }
  11267. else
  11268. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11269. }
  11270. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11271. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11272. return result;
  11273. }
  11274. int handleTriggerMessageRequest(char *uuid, char *payload)
  11275. {
  11276. mtrace();
  11277. int result = FAIL;
  11278. int connectorIdIsNULL = FALSE;
  11279. int connectorIdInt =0;
  11280. char sstr[40]={0},sstrtemp[100]={ 0 };
  11281. char requestedMessagestr[40]={0};
  11282. char comfirmstr[20]={0};
  11283. int c = 0;
  11284. char *loc;
  11285. DEBUG_INFO("handleTriggerMessageRequest\n");
  11286. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11287. strcpy(sstrtemp, stringtrimspace(payload));
  11288. c = 0;
  11289. loc = strstr(sstrtemp, "requestedMessage");
  11290. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11291. {
  11292. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11293. c++;
  11294. }
  11295. sstr[c] = '\0';
  11296. strcpy(requestedMessagestr, sstr);
  11297. c = 0;
  11298. loc = strstr(sstrtemp, "connectorId");
  11299. if(loc == NULL)
  11300. {
  11301. connectorIdIsNULL = TRUE;
  11302. }
  11303. else
  11304. {
  11305. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11306. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11307. {
  11308. sstr[c] = loc[strlen("connectorId")+2+c];
  11309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11310. c++;
  11311. }
  11312. sstr[c] = '\0';
  11313. connectorIdInt = atoi(sstr);
  11314. }
  11315. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11316. {
  11317. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11318. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11319. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11320. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11321. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11322. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11323. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11324. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11325. {
  11326. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11327. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11328. return TRUE;
  11329. }
  11330. else
  11331. {
  11332. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11333. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11334. }
  11335. }
  11336. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11337. {
  11338. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11339. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11340. return TRUE;
  11341. }
  11342. //==========================
  11343. // Trigger message
  11344. //==========================
  11345. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11346. {
  11347. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11348. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11349. {
  11350. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11351. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11352. }
  11353. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11354. }
  11355. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11356. {
  11357. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11358. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11359. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11360. }
  11361. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11362. {
  11363. //sendBootNotificationRequest();
  11364. server_sign = FALSE;
  11365. }
  11366. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11367. {
  11368. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11369. }
  11370. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11371. {
  11372. if(connectorIdIsNULL == FALSE)
  11373. {
  11374. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11375. {
  11376. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11377. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11378. }
  11379. }
  11380. else
  11381. {
  11382. for(int idx=0;idx< gunTotalNumber;idx++)
  11383. {
  11384. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11385. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11386. }
  11387. }
  11388. }
  11389. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11390. {
  11391. if(connectorIdIsNULL == FALSE)
  11392. {
  11393. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11394. {
  11395. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11396. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11397. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11398. }
  11399. }
  11400. else
  11401. {
  11402. for(int idx=0;idx< gunTotalNumber;idx++)
  11403. {
  11404. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11405. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11406. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11407. }
  11408. }
  11409. }
  11410. return result;
  11411. }
  11412. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11413. {
  11414. mtrace();
  11415. int result = FAIL;
  11416. int connectorIdInt =0;
  11417. char comfirmstr[20]={0};
  11418. int tempIndex = 0;
  11419. json_object *UnlockConnector;
  11420. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11421. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11422. UnlockConnector = json_tokener_parse(payload);
  11423. if(!is_error(UnlockConnector))
  11424. {
  11425. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11426. {
  11427. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11428. }
  11429. }
  11430. json_object_put(UnlockConnector);
  11431. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11432. if(gunTotalNumber == 0)
  11433. {
  11434. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11435. goto end;
  11436. }
  11437. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11438. {
  11439. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11440. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11441. goto end;
  11442. }
  11443. else
  11444. {
  11445. //check Transaction active
  11446. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11447. {
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11449. {
  11450. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11451. }
  11452. else
  11453. {
  11454. tempIndex = connectorIdInt -1;
  11455. }
  11456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11457. {
  11458. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11459. {
  11460. //stop Transaction
  11461. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11462. }
  11463. }
  11464. }
  11465. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11466. {
  11467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11468. {
  11469. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11470. }
  11471. else
  11472. {
  11473. tempIndex = connectorIdInt -1;
  11474. }
  11475. for (int index = 0; index < CCS_QUANTITY; index++)
  11476. {
  11477. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11478. {
  11479. //stop Transaction
  11480. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11481. }
  11482. }
  11483. }
  11484. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11485. {
  11486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11487. {
  11488. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11489. }
  11490. else
  11491. {
  11492. tempIndex = connectorIdInt -1;
  11493. }
  11494. for (int index = 0; index < GB_QUANTITY; index++)
  11495. {
  11496. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11497. {
  11498. //stop Transaction
  11499. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11500. }
  11501. }
  11502. }
  11503. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11504. {
  11505. tempIndex = connectorIdInt -1;
  11506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11507. {
  11508. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11509. {
  11510. //stop Transaction
  11511. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11512. }
  11513. }
  11514. }
  11515. else
  11516. {
  11517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11518. {
  11519. tempIndex = 2;
  11520. }
  11521. else
  11522. {
  11523. tempIndex = connectorIdInt-1;
  11524. }
  11525. for (int index = 0; index < AC_QUANTITY; index++)
  11526. {
  11527. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11528. {
  11529. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11530. }
  11531. }
  11532. }
  11533. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11534. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11535. result = TRUE;
  11536. return result;
  11537. }
  11538. end:
  11539. //json_object_put(obj); --- remove temporally
  11540. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11541. return result;
  11542. }
  11543. static char UpdateFirmwarepayloadData[300]={0};
  11544. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11545. {
  11546. mtrace();
  11547. int result = FAIL;
  11548. pthread_t t;
  11549. sendUpdateFirmwareConfirmation(uuid);
  11550. memset(UpdateFirmwarepayloadData, 0, 300);
  11551. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11552. if(!interLock.isUpdateFirmwareGoing)
  11553. {
  11554. interLock.isUpdateFirmwareGoing = 1;
  11555. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11556. sleep(1);
  11557. }
  11558. else
  11559. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11560. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11561. return result;
  11562. }
  11563. void *UpdateFirmwareProcess(void *data)
  11564. {
  11565. pthread_detach(pthread_self());
  11566. mtrace();
  11567. int retriesInt =0, retryIntervalInt=0;
  11568. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11569. int port=0;
  11570. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11571. int isSuccess = 0;
  11572. char ftpbuf[1024];
  11573. char temp[1024];
  11574. char * pch;
  11575. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11576. json_object *UpdateFirmware;
  11577. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11578. if(!is_error(UpdateFirmware))
  11579. {
  11580. // Required data
  11581. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11582. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11583. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11584. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11585. // Optional data
  11586. if(json_object_object_get(UpdateFirmware, "retries"))
  11587. {
  11588. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11589. }
  11590. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11591. {
  11592. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11593. }
  11594. }
  11595. json_object_put(UpdateFirmware);
  11596. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11597. memset(path, 0, ARRAY_SIZE(path));
  11598. // Wait retrieveData
  11599. if(strlen(retrieveDatestr) > 10)
  11600. {
  11601. do
  11602. {
  11603. sleep(1);
  11604. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11605. }
  11606. // Ready to download
  11607. system("rm -f /mnt/*");
  11608. if(strncmp(locationstr,"http", 4) == 0)
  11609. {
  11610. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11611. sprintf(ftppath,"/%s", path);
  11612. DEBUG_INFO("locationstr: %s\n", locationstr);
  11613. DEBUG_INFO("protocol: %s\n",protocol);
  11614. DEBUG_INFO("host: %s\n",host);
  11615. DEBUG_INFO("path: %s\n",path);
  11616. DEBUG_INFO("ftppath: %s\n",ftppath);
  11617. int ftppathlen=strlen(ftppath);
  11618. int i=1;
  11619. char filenametemp[50];
  11620. while(i < ftppathlen)
  11621. {
  11622. int len=ftppathlen-i;
  11623. if(ftppath[len]== 47) // '/' ascll code: 47
  11624. {
  11625. DEBUG_INFO("compare '/' all right\n");
  11626. break;
  11627. }
  11628. i=i+1;
  11629. }
  11630. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11631. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11632. filenametemp[i+1] = 0;
  11633. do
  11634. {
  11635. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11636. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11637. sleep(1);
  11638. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11639. if(!isSuccess)
  11640. {
  11641. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11642. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11643. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11644. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11645. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11646. }
  11647. else
  11648. {
  11649. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11650. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11651. }
  11652. retriesInt--;
  11653. }while((isSuccess == 0)&&(retriesInt >= 0));
  11654. }
  11655. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11656. {
  11657. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11658. memset(temp, 0, ARRAY_SIZE(temp));
  11659. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11660. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11661. int ftppathlen=strlen(ftpbuf);
  11662. int i=1;
  11663. char filenametemp[50];
  11664. while(i < ftppathlen)
  11665. {
  11666. int len=ftppathlen-i;
  11667. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11668. {
  11669. DEBUG_INFO(" compare '/' all right\n");
  11670. break;
  11671. }
  11672. i=i+1;
  11673. }
  11674. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11675. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11676. filenametemp[i+1] = 0;
  11677. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11678. pch=strchr(temp,'@');
  11679. if(pch==NULL)
  11680. {
  11681. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11682. protocol, host, &port, path);
  11683. strcpy(user,"anonymous");
  11684. strcpy(password,"");
  11685. }
  11686. else
  11687. {
  11688. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11689. protocol, user, password, host, &port, path);
  11690. }
  11691. sscanf(host,"%[^/]%s",host1, path1);
  11692. sprintf(ftppath,"%s", path1);
  11693. //DEBUG_INFO("protocol =%s\n",protocol);
  11694. //DEBUG_INFO("user =%s\n",user);
  11695. //DEBUG_INFO("password =%s\n",password);
  11696. //DEBUG_INFO("host1 =%s\n",host1);
  11697. //DEBUG_INFO("port =%d\n",port);
  11698. //DEBUG_INFO("path1 =%s\n",path1);
  11699. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11700. //ftpFile(host, user, password, port, ftppath, fname);
  11701. //download firmware pthred
  11702. if(port == 0)
  11703. {
  11704. port = 21;
  11705. }
  11706. do
  11707. {
  11708. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11709. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11710. sleep(1);
  11711. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11712. if(!isSuccess)
  11713. {
  11714. //BulldogUtil.sleepMs(interval*1000);
  11715. DEBUG_INFO("Update firmware request and download file fail.\n");
  11716. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11717. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11718. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11719. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11721. }
  11722. else
  11723. {
  11724. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11725. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11726. }
  11727. retriesInt--;
  11728. }while((!isSuccess)&&(retriesInt >= 0));
  11729. }
  11730. else
  11731. {
  11732. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11733. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11734. sleep(1);
  11735. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11736. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11737. }
  11738. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11739. interLock.isUpdateFirmwareGoing = 0;
  11740. pthread_exit(NULL);
  11741. }
  11742. int handleCertificateSignedRequest(char *uuid, char *payload)
  11743. {
  11744. mtrace();
  11745. int result = PASS;
  11746. json_object *CertificateSigned;
  11747. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11748. CertificateSigned = json_tokener_parse(payload);
  11749. if(!is_error(CertificateSigned))
  11750. {
  11751. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11752. }
  11753. json_object_put(CertificateSigned);
  11754. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11755. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11756. fclose(fp);
  11757. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11758. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11759. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11760. sendCertificateSignedConfirmation(uuid);
  11761. return result;
  11762. }
  11763. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11764. {
  11765. mtrace();
  11766. int result = PASS;
  11767. json_object *DeleteCertificate;
  11768. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11769. DeleteCertificate = json_tokener_parse(payload);
  11770. if(!is_error(DeleteCertificate))
  11771. {
  11772. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11773. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11774. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11775. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11776. }
  11777. json_object_put(DeleteCertificate);
  11778. /*
  11779. * TODO: Delete certificateSigned process
  11780. */
  11781. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11782. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11783. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11784. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11785. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11786. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11787. sendDeleteCertificateConfirmation(uuid);
  11788. return result;
  11789. }
  11790. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11791. {
  11792. mtrace();
  11793. int result = PASS;
  11794. json_object *ExtendedTriggerMessage;
  11795. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11796. ExtendedTriggerMessage = json_tokener_parse(payload);
  11797. if(!is_error(ExtendedTriggerMessage))
  11798. {
  11799. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11800. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11801. {
  11802. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11803. }
  11804. else
  11805. {
  11806. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11807. }
  11808. }
  11809. json_object_put(ExtendedTriggerMessage);
  11810. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11811. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11812. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11813. {
  11814. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11815. }
  11816. else
  11817. {
  11818. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11819. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11820. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11821. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11822. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11823. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11824. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11825. {
  11826. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11827. }
  11828. else
  11829. {
  11830. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11831. }
  11832. }
  11833. sendExtendedTriggerMessageConfirmation(uuid);
  11834. //==========================
  11835. // Trigger message
  11836. //==========================
  11837. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11838. {
  11839. //sendBootNotificationRequest();
  11840. server_sign = FALSE;
  11841. }
  11842. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11843. {
  11844. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11845. }
  11846. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11847. {
  11848. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11849. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11850. {
  11851. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11852. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11853. }
  11854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11855. }
  11856. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11857. {
  11858. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11859. }
  11860. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11861. {
  11862. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11863. {
  11864. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11865. }
  11866. else
  11867. {
  11868. for(int idx=0;idx< gunTotalNumber;idx++)
  11869. {
  11870. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11871. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11872. }
  11873. }
  11874. }
  11875. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11876. {
  11877. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11878. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11879. {
  11880. 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\" &");
  11881. }
  11882. }
  11883. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11884. {
  11885. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11886. {
  11887. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11888. }
  11889. else
  11890. {
  11891. for(int idx=0;idx< gunTotalNumber;idx++)
  11892. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11893. }
  11894. }
  11895. return result;
  11896. }
  11897. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11898. {
  11899. mtrace();
  11900. int result = PASS;
  11901. json_object *GetInstalledCertificateIds;
  11902. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11903. GetInstalledCertificateIds = json_tokener_parse(payload);
  11904. if(!is_error(GetInstalledCertificateIds))
  11905. {
  11906. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11907. }
  11908. json_object_put(GetInstalledCertificateIds);
  11909. /*
  11910. * TODO: Return installed certificate process
  11911. */
  11912. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11913. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11914. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11915. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11916. sendGetInstalledCertificateIdsConfirmation(uuid);
  11917. return result;
  11918. }
  11919. int handleGetLogRequest(char *uuid, char *payload)
  11920. {
  11921. mtrace();
  11922. int result = PASS;
  11923. json_object *GetLog;
  11924. DEBUG_INFO("handleGetLogRequest...\n");
  11925. GetLog = json_tokener_parse(payload);
  11926. if(!is_error(GetLog))
  11927. {
  11928. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11929. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11930. if(json_object_object_get(GetLog, "retries") != NULL)
  11931. {
  11932. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11933. }
  11934. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11935. {
  11936. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11937. }
  11938. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11939. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11940. {
  11941. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11942. }
  11943. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11944. {
  11945. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11946. }
  11947. }
  11948. json_object_put(GetLog);
  11949. /*
  11950. * TODO: Upload log process
  11951. */
  11952. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11953. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11954. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11955. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11956. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11957. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11958. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11959. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11960. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11961. sendGetLogConfirmation(uuid);
  11962. return result;
  11963. }
  11964. int handleInstallCertificateRequest(char *uuid, char *payload)
  11965. {
  11966. mtrace();
  11967. int result = PASS;
  11968. json_object *InstallCertificate;
  11969. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11970. InstallCertificate = json_tokener_parse(payload);
  11971. if(!is_error(InstallCertificate))
  11972. {
  11973. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11974. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11975. /*
  11976. * TODO: Install certificate process
  11977. */
  11978. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11979. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11980. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11981. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11982. sendInstallCertificateConfirmation(uuid);
  11983. }
  11984. json_object_put(InstallCertificate);
  11985. return result;
  11986. }
  11987. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11988. {
  11989. mtrace();
  11990. int result = PASS;
  11991. json_object *SignedUpdateFirmware;
  11992. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11993. SignedUpdateFirmware = json_tokener_parse(payload);
  11994. if(!is_error(SignedUpdateFirmware))
  11995. {
  11996. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11997. {
  11998. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11999. }
  12000. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12001. {
  12002. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12003. }
  12004. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12005. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12006. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12007. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12008. {
  12009. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12010. }
  12011. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12012. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12013. }
  12014. json_object_put(SignedUpdateFirmware);
  12015. /*
  12016. * TODO: Upgrade firmware process
  12017. */
  12018. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12019. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12020. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12021. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12022. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12023. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12024. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12025. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12026. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12027. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12028. sendInstallCertificateConfirmation(uuid);
  12029. return result;
  12030. }
  12031. int handleUnknownRequest(char *uuid, char *payload)
  12032. {
  12033. mtrace();
  12034. int result = PASS;
  12035. DEBUG_INFO("handleUnknownRequest...\n");
  12036. sendUnknownConfirmation(uuid);
  12037. result = PASS;
  12038. return result;
  12039. }
  12040. //==========================================
  12041. // Handle server response routine
  12042. //==========================================
  12043. void handleAuthorizeResponse(char *payload, int gun_index)
  12044. {
  12045. mtrace();
  12046. char expiryDatestr[30]={0};
  12047. char parentIdTagstr[20]={0};
  12048. char statusstr[20]={0};
  12049. int expiryDateISNULL=FALSE;
  12050. int parentIdTagISNULL=FALSE;
  12051. DEBUG_INFO("handleAuthorizeResponse...\n");
  12052. json_object *Authorize;
  12053. Authorize = json_tokener_parse(payload);
  12054. if(!is_error(Authorize))
  12055. {
  12056. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12057. {
  12058. // Required data
  12059. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12060. // Optional data
  12061. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12062. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12063. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12064. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12065. }
  12066. }
  12067. json_object_put(Authorize);
  12068. if(expiryDateISNULL == FALSE)
  12069. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12070. if(parentIdTagISNULL == FALSE)
  12071. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12072. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12073. //Update idTag information to authorization cache if supproted
  12074. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12075. {
  12076. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12077. }
  12078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12079. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12080. authorizeRetryTimes = 0;
  12081. }
  12082. void handleBootNotificationResponse(char *payload, int gun_index)
  12083. {
  12084. mtrace();
  12085. char statusStr[12]={0};
  12086. char currentTimeStr[30]={0};
  12087. int intervalInt = 0;
  12088. DEBUG_INFO("handleBootNotificationResponse...\n");
  12089. json_object *BootNotification;
  12090. BootNotification = json_tokener_parse(payload);
  12091. if(!is_error(BootNotification))
  12092. {
  12093. // Required data
  12094. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12095. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12096. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12097. }
  12098. json_object_put(BootNotification);
  12099. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12100. BootNotificationInterval = intervalInt;
  12101. HeartBeatWaitTime = intervalInt;
  12102. //write back to ShmOCPP16Data->BootNotification
  12103. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12104. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12105. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12106. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12107. {
  12108. server_sign = TRUE;
  12109. server_pending =FALSE;
  12110. }
  12111. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12112. {
  12113. server_pending = TRUE;
  12114. }
  12115. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12116. srand(time(NULL));
  12117. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12118. SetOcppConnStatus(TRUE);
  12119. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12120. }
  12121. void handleDataTransferResponse(char *payload, int gun_index)
  12122. {
  12123. char sstr[160]={0};//sstr[200]={ 0 };
  12124. int c = 0;
  12125. char *loc;
  12126. DEBUG_INFO("handleDataTransferResponse ...\n");
  12127. loc = strstr(payload, "status");
  12128. c = 0;
  12129. while (loc[3+strlen("status")+c] != '\"')
  12130. {
  12131. sstr[c] = loc[3+strlen("status")+c];
  12132. c++;
  12133. }
  12134. sstr[c] = '\0';
  12135. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12136. }
  12137. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12138. {
  12139. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12140. //struct json_object *obj;
  12141. // obj = json_tokener_parse(payload);
  12142. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12143. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12144. //No fields are defined.
  12145. }
  12146. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12147. {
  12148. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12149. //struct json_object *obj;
  12150. // obj = json_tokener_parse(payload);
  12151. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12152. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12153. //No fields are defined.
  12154. }
  12155. void handleHeartbeatResponse(char *payload, int gun_index)
  12156. {
  12157. mtrace();
  12158. DEBUG_INFO("handleHeartbeatResponse...\n");
  12159. json_object *Heartbeat;
  12160. Heartbeat = json_tokener_parse(payload);
  12161. if(!is_error(Heartbeat))
  12162. {
  12163. // Required data
  12164. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12165. }
  12166. json_object_put(Heartbeat);
  12167. if(FirstHeartBeat == 0)
  12168. {
  12169. FirstHeartBeat = 1;
  12170. DEBUG_INFO("FirstHeartBeat \n");
  12171. }
  12172. HeartBeatWithNOResponse = 0;
  12173. clientTime.Heartbeat=time((time_t*)NULL);
  12174. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12175. }
  12176. void handleMeterValuesResponse(char *payload, int gun_index)
  12177. {
  12178. mtrace();
  12179. DEBUG_INFO("handleMeterValuesResponse...\n");
  12180. }
  12181. void handleStartTransactionResponse(char *payload, int gun_index)
  12182. {
  12183. mtrace();
  12184. //int transactionIdInt = 0;
  12185. FILE *outfile;
  12186. char data[100]={0};
  12187. DEBUG_INFO("handleStartTransactionResponse...\n");
  12188. json_object *StartTransaction;
  12189. StartTransaction = json_tokener_parse(payload);
  12190. if(!is_error(StartTransaction))
  12191. {
  12192. // Required data
  12193. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12194. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12195. // Optional data
  12196. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12197. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12198. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12199. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12200. }
  12201. json_object_put(StartTransaction);
  12202. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12203. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12204. //-----------Start : write to the Queue TransactionId file -----------------//
  12205. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12206. {}
  12207. else
  12208. {
  12209. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12210. if(log == NULL)
  12211. {
  12212. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12213. return ;
  12214. }
  12215. else
  12216. {
  12217. fclose(log);
  12218. }
  12219. }
  12220. // open file for writing
  12221. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12222. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12223. {
  12224. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12225. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12226. fputs(data, outfile);
  12227. fclose (outfile);
  12228. }
  12229. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12230. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12231. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12232. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12233. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12234. }
  12235. void handleStatusNotificationResponse(char *payload, int gun_index)
  12236. {
  12237. mtrace();
  12238. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12239. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12240. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12241. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12242. }
  12243. void handleStopTransactionnResponse(char *payload, int gun_index)
  12244. {
  12245. mtrace();
  12246. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12247. json_object *StopTransaction;
  12248. StopTransaction = json_tokener_parse(payload);
  12249. if(!is_error(StopTransaction))
  12250. {
  12251. // Optional data
  12252. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12253. {
  12254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12255. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12257. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12259. }
  12260. }
  12261. json_object_put(StopTransaction);
  12262. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12263. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12264. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12265. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12266. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12267. }
  12268. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12269. {
  12270. mtrace();
  12271. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12272. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12273. }
  12274. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12275. {
  12276. mtrace();
  12277. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12278. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12279. }
  12280. void handleSignCertificateResponse(char *payload, int gun_index)
  12281. {
  12282. mtrace();
  12283. DEBUG_INFO("handleSignCertificateResponse...\n");
  12284. json_object *SignCertificate;
  12285. SignCertificate = json_tokener_parse(payload);
  12286. if(!is_error(SignCertificate))
  12287. {
  12288. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12289. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12290. }
  12291. json_object_put(SignCertificate);
  12292. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12293. }
  12294. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12295. {
  12296. mtrace();
  12297. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12298. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12299. }
  12300. //==========================================
  12301. // Handle Error routine
  12302. //==========================================
  12303. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12304. {
  12305. mtrace();
  12306. #ifdef SystemLogMessage
  12307. DEBUG_INFO("errorCode: %s\n", errorCode);
  12308. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12309. DEBUG_INFO("errorDetails: %s\n", payload);
  12310. #endif
  12311. }
  12312. //===============================================
  12313. // Common routine
  12314. //===============================================
  12315. int initialConfigurationTable(void)
  12316. {
  12317. //clock_t start_t, end_t, total_t;
  12318. FILE *fp;
  12319. FILE *outfile;
  12320. char str[512]={0};
  12321. char sstr[256]={0};
  12322. int c = 0;
  12323. char *loc;
  12324. int confVersion = 9;
  12325. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12326. //start_t = clock();
  12327. //printf("Starting of the program, start_t = %ld\n", start_t);
  12328. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12329. // Check configuration file size is correct
  12330. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12331. {
  12332. struct stat st;
  12333. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12334. if(st.st_size < 3100)
  12335. {
  12336. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12337. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12338. }
  12339. }
  12340. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12341. {
  12342. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12343. if(outfile == NULL)
  12344. {
  12345. DEBUG_INFO("Error opening file\n");
  12346. return FALSE;
  12347. }
  12348. /*Core Profile*/
  12349. //AllowOfflineTxForUnknownId
  12350. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12354. //AuthorizationCacheEnabled
  12355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12359. //AuthorizeRemoteTxRequests
  12360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12364. //BlinkRepeat
  12365. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12369. //ClockAlignedDataInterval
  12370. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12374. //ConnectionTimeOut
  12375. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12379. //GetConfigurationMaxKeys
  12380. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12384. // HeartbeatInterval
  12385. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12389. // LightIntensity
  12390. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12394. // LocalAuthorizeOffline
  12395. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12399. // LocalPreAuthorize
  12400. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12404. // MaxEnergyOnInvalidId
  12405. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12409. // MeterValuesAlignedData
  12410. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12413. 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" );
  12414. else
  12415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12417. // MeterValuesAlignedDataMaxLength
  12418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12420. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12422. else
  12423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12425. // MeterValuesSampledData
  12426. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12429. 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" );
  12430. else
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12433. // MeterValuesSampledDataMaxLength
  12434. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12438. else
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12441. // MeterValueSampleInterval
  12442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12446. // MinimumStatusDuration
  12447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12450. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12452. // NumberOfConnectors
  12453. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12456. {
  12457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12458. }
  12459. else
  12460. {
  12461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12462. }
  12463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12464. // ResetRetries
  12465. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12469. // ConnectorPhaseRotation
  12470. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12474. // ConnectorPhaseRotationMaxLength
  12475. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12479. // StopTransactionOnEVSideDisconnect
  12480. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12484. // StopTransactionOnInvalidId
  12485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12489. // StopTxnAlignedData
  12490. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12494. // StopTxnAlignedDataMaxLength
  12495. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12499. // StopTxnSampledData
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12504. else
  12505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12507. // StopTxnSampledDataMaxLength
  12508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12511. {
  12512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12513. }
  12514. else
  12515. {
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12517. }
  12518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12519. // SupportedFeatureProfiles
  12520. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12524. // SupportedFeatureProfilesMaxLength
  12525. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12529. // TransactionMessageAttempts
  12530. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12533. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12535. // TransactionMessageRetryInterval
  12536. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12539. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12541. // UnlockConnectorOnEVSideDisconnect
  12542. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12546. // WebSocketPingInterval
  12547. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12551. // QueueOffLineMeterValues
  12552. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12556. // AuthorizationKey
  12557. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12561. // SecurityProfile
  12562. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12566. // DefaultPrice
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12571. // CustomDisplayCostAndPrice
  12572. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12576. // CustomIdleFeeAfterStop
  12577. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12581. // TimeOffset
  12582. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12586. // NextTimeOffsetTransitionDateTime
  12587. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12591. // TimeOffsetNextTransition
  12592. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12596. // SystemUptimeSec
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  12598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  12599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  12601. // Configuration Version
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12606. //* Local Auth List Management Profile*/
  12607. #if 0
  12608. //For OCTT Test Case
  12609. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12612. #endif
  12613. #if 1
  12614. //LocalAuthListEnabled
  12615. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12619. #endif
  12620. //LocalAuthListMaxLength
  12621. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12625. //SendLocalListMaxLength
  12626. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12630. //ReserveConnectorZeroSupported
  12631. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12635. //* Smart Charging Profile */
  12636. //ChargeProfileMaxStackLevel
  12637. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12641. // ChargingScheduleAllowedChargingRateUnit
  12642. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12646. // ChargingScheduleMaxPeriods
  12647. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12651. // ConnectorSwitch3to1PhaseSupported
  12652. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12656. // MaxChargingProfilesInstalled
  12657. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12661. fclose(outfile);
  12662. }
  12663. else
  12664. {
  12665. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12666. char keystr[60]={0};
  12667. char readonlystr[10]={0};
  12668. char valuestr[256]={0};
  12669. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12670. if(fp == NULL) {
  12671. DEBUG_INFO("Error opening file");
  12672. return FALSE;
  12673. }
  12674. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12675. {
  12676. //DEBUG_INFO("Get Configuration \n");
  12677. if(strlen(str) > 0)
  12678. {
  12679. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12680. //*************************key*********************************/
  12681. if(strstr(str, "key") != NULL)
  12682. {
  12683. loc = strstr(str, "key");
  12684. c = 0;
  12685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12686. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12687. {
  12688. sstr[c] = loc[strlen("key")+3+c];
  12689. c++;
  12690. }
  12691. sstr[c] = '\0';
  12692. strcpy(keystr,sstr);
  12693. }
  12694. //*************************readonly*********************************/
  12695. if(strstr(str, "readonly") != NULL)
  12696. {
  12697. loc = strstr(str, "readonly");
  12698. c = 0;
  12699. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12700. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12701. {
  12702. sstr[c] = loc[strlen("readonly")+2+c];
  12703. c++;
  12704. }
  12705. sstr[c] = '\0';
  12706. strcpy(readonlystr,sstr);
  12707. }
  12708. //*************************value*********************************/
  12709. if(strstr(str, "value") != NULL)
  12710. {
  12711. loc = strstr(str, "value");
  12712. c = 0;
  12713. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12714. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12715. {
  12716. sstr[c] = loc[strlen("value")+3+c];
  12717. c++;
  12718. }
  12719. sstr[c] = '\0';
  12720. strcpy(valuestr,sstr);
  12721. }
  12722. // DEBUG_INFO("keystr=%s\n",keystr);
  12723. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12724. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12725. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12726. {
  12727. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12730. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12731. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12732. }
  12733. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12734. {
  12735. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12736. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12738. }
  12739. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12740. {
  12741. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12743. }
  12744. if(strcmp(keystr, "BlinkRepeat") == 0)
  12745. {
  12746. //Charger.BlinkRepeat = Integer.parseInt(value);
  12747. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12749. }
  12750. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12751. {
  12752. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12754. }
  12755. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12756. {
  12757. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12759. }
  12760. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12761. {
  12762. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12764. }
  12765. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12766. {
  12767. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12769. HeartBeatWaitTime = atoi(valuestr);
  12770. }
  12771. if(strcmp(keystr, "LightIntensity") == 0)
  12772. {
  12773. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12775. }
  12776. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12777. {
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12780. }
  12781. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12782. {
  12783. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12785. }
  12786. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12787. {
  12788. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12790. }
  12791. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12792. {
  12793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12795. }
  12796. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12797. {
  12798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12800. }
  12801. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12802. {
  12803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12805. }
  12806. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12807. {
  12808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12810. }
  12811. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12812. {
  12813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12815. }
  12816. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12817. {
  12818. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12820. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12821. }
  12822. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12823. {
  12824. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12826. }
  12827. if(strcmp(keystr, "ResetRetries") == 0)
  12828. {
  12829. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12831. }
  12832. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12833. {
  12834. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12836. }
  12837. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12838. {
  12839. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12841. }
  12842. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12843. {
  12844. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12846. }
  12847. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12848. {
  12849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12851. }
  12852. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12853. {
  12854. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12856. }
  12857. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12858. {
  12859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12861. }
  12862. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12863. {
  12864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12866. }
  12867. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12868. {
  12869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12871. }
  12872. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12873. {
  12874. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12876. }
  12877. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12878. {
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12881. }
  12882. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12883. {
  12884. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12886. TransactionMessageAttemptsValue = atoi(valuestr);
  12887. }
  12888. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12889. {
  12890. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12892. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12893. }
  12894. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12895. {
  12896. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12898. }
  12899. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12900. {
  12901. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12903. }
  12904. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12905. {
  12906. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12908. }
  12909. if(strcmp(keystr, "AuthorizationKey") == 0)
  12910. {
  12911. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12912. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12914. }
  12915. if(strcmp(keystr, "SecurityProfile") == 0)
  12916. {
  12917. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12919. }
  12920. if(strcmp(keystr, "DefaultPrice") == 0)
  12921. {
  12922. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12924. }
  12925. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12926. {
  12927. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12929. }
  12930. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12931. {
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12934. }
  12935. if(strcmp(keystr, "TimeOffset") == 0)
  12936. {
  12937. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12939. }
  12940. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12941. {
  12942. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12944. }
  12945. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12946. {
  12947. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12949. }
  12950. if(strcmp(keystr, "SystemUptimeSec") == 0)
  12951. {
  12952. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  12954. }
  12955. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12956. {
  12957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12959. }
  12960. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12961. {
  12962. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12964. }
  12965. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12966. {
  12967. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12969. }
  12970. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12971. {
  12972. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12974. }
  12975. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12976. {
  12977. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12979. }
  12980. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12981. {
  12982. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12984. }
  12985. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12986. {
  12987. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12989. }
  12990. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12991. {
  12992. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12994. }
  12995. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12996. {
  12997. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12999. }
  13000. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13001. {
  13002. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13004. }
  13005. }
  13006. }
  13007. fclose(fp);
  13008. }
  13009. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13010. {
  13011. return PASS;
  13012. }
  13013. else
  13014. {
  13015. return FAIL;
  13016. }
  13017. }
  13018. void StoreConfigurationTable(void)
  13019. {
  13020. FILE *outfile;
  13021. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13022. if(outfile == NULL)
  13023. {
  13024. DEBUG_INFO("Error opening file");
  13025. return ;
  13026. }
  13027. /*Core Profile*/
  13028. //AllowOfflineTxForUnknownId
  13029. /*
  13030. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13031. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13034. */
  13035. //DEBUG_INFO("data=%s\n",data);
  13036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13037. //AuthorizationCacheEnabled
  13038. /*
  13039. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13042. */
  13043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13044. //AuthorizeRemoteTxRequests
  13045. /*
  13046. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13049. */
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13051. //BlinkRepeat
  13052. /*
  13053. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13056. */
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13058. //ClockAlignedDataInterval
  13059. /*
  13060. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13065. //ConnectionTimeOut
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13072. //GetConfigurationMaxKeys
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13079. // HeartbeatInterval
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13086. // LightIntensity
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13093. // LocalAuthorizeOffline
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13100. // LocalPreAuthorize
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13107. // MaxEnergyOnInvalidId
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13112. */
  13113. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13115. // MeterValuesAlignedData
  13116. /*
  13117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13120. */
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13122. // MeterValuesAlignedDataMaxLength
  13123. /*
  13124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13127. */
  13128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13129. // MeterValuesSampledData
  13130. /*
  13131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13134. */
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13136. // MeterValuesSampledDataMaxLength
  13137. /*
  13138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13141. */
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13143. // MeterValueSampleInterval
  13144. /*
  13145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13150. // MinimumStatusDuration
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13157. // NumberOfConnectors
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13162. {
  13163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13164. }
  13165. else
  13166. {
  13167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13168. }
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13171. // ResetRetries
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13176. */
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13178. // ConnectorPhaseRotation
  13179. /*
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13183. */
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13185. // ConnectorPhaseRotationMaxLength
  13186. /*
  13187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13190. */
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13192. // StopTransactionOnEVSideDisconnect
  13193. /*
  13194. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13197. */
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13199. // StopTransactionOnInvalidId
  13200. /*
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13206. // StopTxnAlignedData
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13213. // StopTxnAlignedDataMaxLength
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13220. // StopTxnSampledData
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13227. // StopTxnSampledDataMaxLength
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13234. // SupportedFeatureProfiles
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13241. // SupportedFeatureProfilesMaxLength
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13248. // TransactionMessageAttempts
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13255. // TransactionMessageRetryInterval
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13262. // UnlockConnectorOnEVSideDisconnect
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13269. // WebSocketPingInterval
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13276. // QueueOffLineMeterValues
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13283. // AuthorizationKey
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13290. // SecurityProfile
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13297. // DefaultPrice
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13304. // CustomDisplayCostAndPrice
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13311. // CustomIdleFeeAfterStop
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13318. // TimeOffset
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13325. // NextTimeOffsetTransitionDateTime
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13332. // TimeOffsetNextTransition
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13339. // SystemUptimeSec
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13346. // ConfigurationVersion
  13347. /*
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13351. */
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13353. //* Local Auth List Management Profile*/
  13354. //LocalAuthListEnabled
  13355. /*
  13356. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13359. */
  13360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13361. //LocalAuthListMaxLength
  13362. /*
  13363. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13366. */
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13368. //SendLocalListMaxLength
  13369. /*
  13370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13373. */
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13375. //ReserveConnectorZeroSupported
  13376. /*
  13377. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13380. */
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13382. //* Smart Charging Profile */
  13383. //ChargeProfileMaxStackLevel
  13384. /*
  13385. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13388. */
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13390. // ChargingScheduleAllowedChargingRateUnit
  13391. /*
  13392. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13395. */
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13397. // ChargingScheduleMaxPeriods
  13398. /*
  13399. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13402. */
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13404. // ConnectorSwitch3to1PhaseSupported
  13405. /*
  13406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13409. */
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13411. // MaxChargingProfilesInstalled
  13412. /*
  13413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13416. */
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13418. fclose(outfile);
  13419. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13420. }
  13421. void getKeyValue(char *keyReq)
  13422. {
  13423. int isEmpty = FALSE;
  13424. int isKnowKey = FALSE;
  13425. DEBUG_INFO("keyReq = %s\n", keyReq);
  13426. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13427. isEmpty = TRUE;
  13428. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13429. {
  13430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13433. {
  13434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13435. }
  13436. else
  13437. {
  13438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13439. }
  13440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13441. isKnowKey = TRUE;
  13442. }
  13443. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13444. {
  13445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13448. {
  13449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13450. }
  13451. else
  13452. {
  13453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13454. }
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13456. isKnowKey = TRUE;
  13457. }
  13458. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13459. {
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13463. {
  13464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13465. }
  13466. else
  13467. {
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13469. }
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13471. isKnowKey = TRUE;
  13472. }
  13473. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13474. {
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13478. {
  13479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13480. }
  13481. else
  13482. {
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13484. }
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13486. isKnowKey = TRUE;
  13487. }
  13488. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13489. {
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13493. {
  13494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13495. }
  13496. else
  13497. {
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13499. }
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13501. isKnowKey = TRUE;
  13502. }
  13503. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13504. {
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13508. {
  13509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13510. }
  13511. else
  13512. {
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13514. }
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13516. isKnowKey = TRUE;
  13517. }
  13518. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13519. {
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13523. {
  13524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13525. }
  13526. else
  13527. {
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13529. }
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13531. isKnowKey = TRUE;
  13532. }
  13533. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13534. {
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13538. {
  13539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13540. }
  13541. else
  13542. {
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13544. }
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13546. isKnowKey = TRUE;
  13547. }
  13548. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13549. {
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13553. {
  13554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13555. }
  13556. else
  13557. {
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13559. }
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13561. isKnowKey = TRUE;
  13562. }
  13563. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13564. {
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13568. {
  13569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13570. }
  13571. else
  13572. {
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13574. }
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13576. isKnowKey = TRUE;
  13577. }
  13578. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13579. {
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13583. {
  13584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13585. }
  13586. else
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13589. }
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13591. isKnowKey = TRUE;
  13592. }
  13593. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13594. {
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13598. {
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13600. }
  13601. else
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13604. }
  13605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13606. isKnowKey = TRUE;
  13607. }
  13608. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13609. {
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13613. {
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13615. }
  13616. else
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13619. }
  13620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13621. isKnowKey = TRUE;
  13622. }
  13623. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13624. {
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13628. {
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13630. }
  13631. else
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13634. }
  13635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13636. isKnowKey = TRUE;
  13637. }
  13638. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13639. {
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13643. {
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13645. }
  13646. else
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13649. }
  13650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13651. isKnowKey = TRUE;
  13652. }
  13653. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13654. {
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13658. {
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13660. }
  13661. else
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13664. }
  13665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13666. isKnowKey = TRUE;
  13667. }
  13668. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13669. {
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13673. {
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13675. }
  13676. else
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13679. }
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13681. isKnowKey = TRUE;
  13682. }
  13683. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13684. {
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13688. {
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13690. }
  13691. else
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13694. }
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13696. isKnowKey = TRUE;
  13697. }
  13698. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13699. {
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13703. {
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13705. }
  13706. else
  13707. {
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13709. }
  13710. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13712. isKnowKey = TRUE;
  13713. }
  13714. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13715. {
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13719. {
  13720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13721. }
  13722. else
  13723. {
  13724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13725. }
  13726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13727. isKnowKey = TRUE;
  13728. }
  13729. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13730. {
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13734. {
  13735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13736. }
  13737. else
  13738. {
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13740. }
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13742. isKnowKey = TRUE;
  13743. }
  13744. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13745. {
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13749. {
  13750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13751. }
  13752. else
  13753. {
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13755. }
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13757. isKnowKey = TRUE;
  13758. }
  13759. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13760. {
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13764. {
  13765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13766. }
  13767. else
  13768. {
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13770. }
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13772. isKnowKey = TRUE;
  13773. }
  13774. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13775. {
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13779. {
  13780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13781. }
  13782. else
  13783. {
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13785. }
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13787. isKnowKey = TRUE;
  13788. }
  13789. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13790. {
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13794. {
  13795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13796. }
  13797. else
  13798. {
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13800. }
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13802. isKnowKey = TRUE;
  13803. }
  13804. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13805. {
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13809. {
  13810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13811. }
  13812. else
  13813. {
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13815. }
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13817. isKnowKey = TRUE;
  13818. }
  13819. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13820. {
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13824. {
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13826. }
  13827. else
  13828. {
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13830. }
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13832. isKnowKey = TRUE;
  13833. }
  13834. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13835. {
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13839. {
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13841. }
  13842. else
  13843. {
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13845. }
  13846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13847. isKnowKey = TRUE;
  13848. }
  13849. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13850. {
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13854. {
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13856. }
  13857. else
  13858. {
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13860. }
  13861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13862. isKnowKey = TRUE;
  13863. }
  13864. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13865. {
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13869. {
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13871. }
  13872. else
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13875. }
  13876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13877. isKnowKey = TRUE;
  13878. }
  13879. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13880. {
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13884. {
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13886. }
  13887. else
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13890. }
  13891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13892. isKnowKey = TRUE;
  13893. }
  13894. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13895. {
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13899. {
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13901. }
  13902. else
  13903. {
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13905. }
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13907. isKnowKey = TRUE;
  13908. }
  13909. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13910. {
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13914. {
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13916. }
  13917. else
  13918. {
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13920. }
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13922. isKnowKey = TRUE;
  13923. }
  13924. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13925. {
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13929. {
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13931. }
  13932. else
  13933. {
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13935. }
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13937. isKnowKey = TRUE;
  13938. }
  13939. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13940. {
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13944. {
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13946. }
  13947. else
  13948. {
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13950. }
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13952. isKnowKey = TRUE;
  13953. }
  13954. /*
  13955. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13956. {
  13957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13960. {
  13961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13962. }
  13963. else
  13964. {
  13965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13966. }
  13967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13968. isKnowKey = TRUE;
  13969. }*/
  13970. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13971. {
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13975. {
  13976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13977. }
  13978. else
  13979. {
  13980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13981. }
  13982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13983. isKnowKey = TRUE;
  13984. }
  13985. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13986. {
  13987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13990. {
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13992. }
  13993. else
  13994. {
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13996. }
  13997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13998. isKnowKey = TRUE;
  13999. }
  14000. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14001. {
  14002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14005. {
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14007. }
  14008. else
  14009. {
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14011. }
  14012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14013. isKnowKey = TRUE;
  14014. }
  14015. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14016. {
  14017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14020. {
  14021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14022. }
  14023. else
  14024. {
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14026. }
  14027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14028. isKnowKey = TRUE;
  14029. }
  14030. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14031. {
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14035. {
  14036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14037. }
  14038. else
  14039. {
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14041. }
  14042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14043. isKnowKey = TRUE;
  14044. }
  14045. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14046. {
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14050. {
  14051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14052. }
  14053. else
  14054. {
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14056. }
  14057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14058. isKnowKey = TRUE;
  14059. }
  14060. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14061. {
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14065. {
  14066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14067. }
  14068. else
  14069. {
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14071. }
  14072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14073. isKnowKey = TRUE;
  14074. }
  14075. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14076. {
  14077. struct sysinfo s_info;
  14078. int error = sysinfo(&s_info);
  14079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14082. {
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14084. }
  14085. else
  14086. {
  14087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14088. }
  14089. if(error != 0)
  14090. {
  14091. DEBUG_WARN("System uptime get error: %d\n", error);
  14092. }
  14093. else
  14094. {
  14095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14096. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14097. }
  14098. isKnowKey = TRUE;
  14099. }
  14100. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14101. {
  14102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14105. {
  14106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14107. }
  14108. else
  14109. {
  14110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14111. }
  14112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14113. isKnowKey = TRUE;
  14114. }
  14115. #if 1
  14116. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14117. {
  14118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14120. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14121. {
  14122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14123. }
  14124. else
  14125. {
  14126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14127. }
  14128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14129. isKnowKey = TRUE;
  14130. }
  14131. #endif
  14132. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14133. {
  14134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14136. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14137. {
  14138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14139. }
  14140. else
  14141. {
  14142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14143. }
  14144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14145. isKnowKey = TRUE;
  14146. }
  14147. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14148. {
  14149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14151. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14152. {
  14153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14154. }
  14155. else
  14156. {
  14157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14158. }
  14159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14160. isKnowKey = TRUE;
  14161. }
  14162. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14163. {
  14164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14166. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14167. {
  14168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14169. }
  14170. else
  14171. {
  14172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14173. }
  14174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14175. isKnowKey = TRUE;
  14176. }
  14177. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14178. {
  14179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14181. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14182. {
  14183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14184. }
  14185. else
  14186. {
  14187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14188. }
  14189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14190. isKnowKey = TRUE;
  14191. }
  14192. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14193. {
  14194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14196. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14197. {
  14198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14199. }
  14200. else
  14201. {
  14202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14203. }
  14204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14205. isKnowKey = TRUE;
  14206. }
  14207. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14208. {
  14209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14211. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14212. {
  14213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14214. }
  14215. else
  14216. {
  14217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14218. }
  14219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14220. isKnowKey = TRUE;
  14221. }
  14222. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14223. {
  14224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14226. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14227. {
  14228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14229. }
  14230. else
  14231. {
  14232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14233. }
  14234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14235. isKnowKey = TRUE;
  14236. }
  14237. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14238. {
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14241. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14242. {
  14243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14244. }
  14245. else
  14246. {
  14247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14248. }
  14249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14250. isKnowKey = TRUE;
  14251. }
  14252. //=========================================================
  14253. if(!isEmpty && !isKnowKey)
  14254. {
  14255. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14256. strcpy(unknownkey[UnknownKeynum], keyReq);
  14257. UnknownKeynum = UnknownKeynum + 1;
  14258. }
  14259. }
  14260. void processUnkownKey(void)
  14261. {
  14262. DEBUG_INFO("processUnkownKey...\n");
  14263. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14264. for(int index=0; index < UnknownKeynum; index++)
  14265. {
  14266. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14267. {
  14268. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14269. }
  14270. }
  14271. }
  14272. int setKeyValue(char *key, char *value)
  14273. {
  14274. int isSuccess = NotSupported;
  14275. int check_ascii=0;
  14276. char str[256]={0};
  14277. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14278. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14279. {
  14280. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14282. {
  14283. strcpy(str, (const char*)value);
  14284. for(int i = 0; str[i]; i++){
  14285. str[i] = tolower(str[i]);
  14286. }
  14287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14288. isSuccess = ConfigurationStatus_Accepted;
  14289. }
  14290. else
  14291. {
  14292. isSuccess = ConfigurationStatus_Rejected;
  14293. }
  14294. }
  14295. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14296. {
  14297. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14299. {
  14300. strcpy(str, (const char*)value);
  14301. for(int i = 0; str[i]; i++){
  14302. str[i] = tolower(str[i]);
  14303. }
  14304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14305. isSuccess = ConfigurationStatus_Accepted;
  14306. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14307. }
  14308. else
  14309. {
  14310. isSuccess = ConfigurationStatus_Rejected;
  14311. }
  14312. }
  14313. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14314. {
  14315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14316. {
  14317. strcpy(str, (const char*)value);
  14318. for(int i = 0; str[i]; i++)
  14319. {
  14320. str[i] = tolower(str[i]);
  14321. }
  14322. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14324. isSuccess = ConfigurationStatus_Accepted;
  14325. }
  14326. else
  14327. {
  14328. isSuccess = ConfigurationStatus_Rejected;
  14329. }
  14330. }
  14331. if(strcmp(key, "BlinkRepeat") == 0)
  14332. {
  14333. //Charger.BlinkRepeat = Integer.parseInt(value);
  14334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14335. {
  14336. check_ascii = value[0];
  14337. if( (check_ascii < 48) || (check_ascii > 57) )
  14338. {
  14339. isSuccess = ConfigurationStatus_Rejected;
  14340. }
  14341. else
  14342. {
  14343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14344. isSuccess = ConfigurationStatus_Accepted;
  14345. }
  14346. }
  14347. else
  14348. {
  14349. isSuccess = ConfigurationStatus_Rejected;
  14350. }
  14351. }
  14352. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14353. {
  14354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14355. {
  14356. check_ascii = value[0];
  14357. if( (check_ascii < 48) || (check_ascii > 57) )
  14358. {
  14359. isSuccess = ConfigurationStatus_Rejected;
  14360. }
  14361. else
  14362. {
  14363. if((atoi(value) == 0) || (atoi(value) >= 10))
  14364. {
  14365. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14367. isSuccess = ConfigurationStatus_Accepted;
  14368. }
  14369. else
  14370. isSuccess = ConfigurationStatus_Rejected;
  14371. }
  14372. }
  14373. else
  14374. {
  14375. isSuccess = ConfigurationStatus_Rejected;
  14376. }
  14377. }
  14378. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14379. {
  14380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14381. {
  14382. check_ascii = value[0];
  14383. if( (check_ascii < 48) || (check_ascii > 57) )
  14384. {
  14385. isSuccess = ConfigurationStatus_Rejected;
  14386. }
  14387. else
  14388. {
  14389. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14391. isSuccess = ConfigurationStatus_Accepted;
  14392. }
  14393. }
  14394. else
  14395. {
  14396. isSuccess = ConfigurationStatus_Rejected;
  14397. }
  14398. }
  14399. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14400. {
  14401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14402. {
  14403. check_ascii = value[0];
  14404. if( (check_ascii < 48) || (check_ascii > 57) )
  14405. {
  14406. isSuccess = ConfigurationStatus_Rejected;
  14407. }
  14408. else
  14409. {
  14410. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14412. isSuccess = ConfigurationStatus_Accepted;
  14413. }
  14414. }
  14415. else
  14416. {
  14417. isSuccess = ConfigurationStatus_Rejected;
  14418. }
  14419. }
  14420. if(strcmp(key, "HeartbeatInterval") == 0)
  14421. {
  14422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14423. {
  14424. check_ascii = value[0];
  14425. if( (check_ascii < 48) || (check_ascii > 57) )
  14426. {
  14427. isSuccess = ConfigurationStatus_Rejected;
  14428. }
  14429. else
  14430. {
  14431. if((atoi(value) == 0) || (atoi(value) >= 10))
  14432. {
  14433. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14435. HeartBeatWaitTime = atoi(value);
  14436. isSuccess = ConfigurationStatus_Accepted;
  14437. }
  14438. else
  14439. {
  14440. isSuccess = ConfigurationStatus_Rejected;
  14441. }
  14442. }
  14443. }
  14444. else
  14445. {
  14446. isSuccess = ConfigurationStatus_Rejected;
  14447. }
  14448. }
  14449. if(strcmp(key, "LightIntensity") == 0)
  14450. {
  14451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14452. {
  14453. check_ascii = value[0];
  14454. if( (check_ascii < 48) || (check_ascii > 57) )
  14455. {
  14456. isSuccess = ConfigurationStatus_Rejected;
  14457. }
  14458. else
  14459. {
  14460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14461. isSuccess = ConfigurationStatus_Accepted;
  14462. }
  14463. }
  14464. else
  14465. {
  14466. isSuccess = ConfigurationStatus_Rejected;
  14467. }
  14468. }
  14469. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14470. {
  14471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14472. {
  14473. strcpy(str, (const char*)value);
  14474. for(int i = 0; str[i]; i++)
  14475. {
  14476. str[i] = tolower(str[i]);
  14477. }
  14478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14479. isSuccess = ConfigurationStatus_Accepted;
  14480. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14481. }
  14482. else
  14483. {
  14484. isSuccess = ConfigurationStatus_Rejected;
  14485. }
  14486. }
  14487. if(strcmp(key, "LocalPreAuthorize") == 0)
  14488. {
  14489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14490. {
  14491. strcpy(str, (const char*)value);
  14492. for(int i = 0; str[i]; i++)
  14493. {
  14494. str[i] = tolower(str[i]);
  14495. }
  14496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14497. isSuccess = ConfigurationStatus_Accepted;
  14498. }
  14499. else
  14500. {
  14501. isSuccess = ConfigurationStatus_Rejected;
  14502. }
  14503. }
  14504. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14505. {
  14506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14507. {
  14508. check_ascii = value[0];
  14509. if( (check_ascii < 48) || (check_ascii > 57) )
  14510. {
  14511. isSuccess = ConfigurationStatus_Rejected;
  14512. }
  14513. else
  14514. {
  14515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14516. isSuccess = ConfigurationStatus_Accepted;
  14517. }
  14518. }
  14519. else
  14520. {
  14521. isSuccess = ConfigurationStatus_Rejected;
  14522. }
  14523. }
  14524. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14525. {
  14526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14527. {
  14528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14529. isSuccess = ConfigurationStatus_Accepted;
  14530. }
  14531. else
  14532. {
  14533. isSuccess = ConfigurationStatus_Rejected;
  14534. }
  14535. }
  14536. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14537. {
  14538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14539. {
  14540. check_ascii = value[0];
  14541. if( (check_ascii < 48) || (check_ascii > 57) )
  14542. {
  14543. isSuccess = ConfigurationStatus_Rejected;
  14544. }
  14545. else
  14546. {
  14547. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14549. isSuccess = ConfigurationStatus_Accepted;
  14550. }
  14551. }
  14552. else
  14553. {
  14554. isSuccess = ConfigurationStatus_Rejected;
  14555. }
  14556. }
  14557. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14558. {
  14559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14560. {
  14561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14562. isSuccess = ConfigurationStatus_Accepted;
  14563. }
  14564. else
  14565. {
  14566. isSuccess = ConfigurationStatus_Rejected;
  14567. }
  14568. }
  14569. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14570. {
  14571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14572. {
  14573. check_ascii = value[0];
  14574. if( (check_ascii < 48) || (check_ascii > 57) )
  14575. {
  14576. isSuccess = ConfigurationStatus_Rejected;
  14577. }
  14578. else
  14579. {
  14580. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14582. isSuccess = ConfigurationStatus_Accepted;
  14583. }
  14584. }
  14585. else
  14586. {
  14587. isSuccess = ConfigurationStatus_Rejected;
  14588. }
  14589. }
  14590. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14591. {
  14592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14593. {
  14594. check_ascii = value[0];
  14595. if( (check_ascii < 48) || (check_ascii > 57) )
  14596. {
  14597. isSuccess = ConfigurationStatus_Rejected;
  14598. }
  14599. else
  14600. {
  14601. if((atoi(value) == 0) || (atoi(value) >= 10))
  14602. {
  14603. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14605. isSuccess = ConfigurationStatus_Accepted;
  14606. }
  14607. else
  14608. {
  14609. isSuccess = ConfigurationStatus_Rejected;
  14610. }
  14611. }
  14612. }
  14613. else
  14614. {
  14615. isSuccess = ConfigurationStatus_Rejected;
  14616. }
  14617. }
  14618. if(strcmp(key, "MinimumStatusDuration") == 0)
  14619. {
  14620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14621. {
  14622. check_ascii = value[0];
  14623. if( (check_ascii < 48) || (check_ascii > 57) )
  14624. {
  14625. isSuccess = ConfigurationStatus_Rejected;
  14626. }
  14627. else
  14628. {
  14629. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14630. {
  14631. isSuccess = ConfigurationStatus_Rejected;
  14632. }
  14633. else
  14634. {
  14635. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14637. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14638. isSuccess = ConfigurationStatus_Accepted;
  14639. }
  14640. }
  14641. }
  14642. else
  14643. {
  14644. isSuccess = ConfigurationStatus_Rejected;
  14645. }
  14646. }
  14647. if(strcmp(key, "NumberOfConnectors") == 0)
  14648. {
  14649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14650. {
  14651. check_ascii = value[0];
  14652. if( (check_ascii < 48) || (check_ascii > 57) )
  14653. {
  14654. isSuccess = ConfigurationStatus_Rejected;
  14655. }
  14656. else
  14657. {
  14658. //Charger.ResetRetries = Integer.parseInt(value);
  14659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14660. isSuccess = ConfigurationStatus_Accepted;
  14661. }
  14662. }
  14663. else
  14664. {
  14665. isSuccess = ConfigurationStatus_Rejected;
  14666. }
  14667. }
  14668. if(strcmp(key, "ResetRetries") == 0)
  14669. {
  14670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14671. {
  14672. check_ascii = value[0];
  14673. if( (check_ascii < 48) || (check_ascii > 57) )
  14674. {
  14675. isSuccess = ConfigurationStatus_Rejected;
  14676. }
  14677. else
  14678. {
  14679. //Charger.ResetRetries = Integer.parseInt(value);
  14680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14681. isSuccess = ConfigurationStatus_Accepted;
  14682. }
  14683. }
  14684. else
  14685. {
  14686. isSuccess = ConfigurationStatus_Rejected;
  14687. }
  14688. }
  14689. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14690. {
  14691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14692. {
  14693. strcpy(str, (const char*)value);
  14694. for(int i = 0; str[i]; i++)
  14695. {
  14696. str[i] = tolower(str[i]);
  14697. }
  14698. if(strcmp(str, "notapplicable")== 0)
  14699. {
  14700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14701. isSuccess = ConfigurationStatus_Accepted;
  14702. }
  14703. else if(strcmp(str, "unknown")== 0)
  14704. {
  14705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14706. isSuccess = ConfigurationStatus_Accepted;
  14707. }
  14708. else if(strcmp(str, "rst")== 0)
  14709. {
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14711. isSuccess = ConfigurationStatus_Accepted;
  14712. }
  14713. else if(strcmp(str, "rts")== 0)
  14714. {
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14716. isSuccess = ConfigurationStatus_Accepted;
  14717. }
  14718. else if(strcmp(str, "srt")== 0)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14721. isSuccess = ConfigurationStatus_Accepted;
  14722. }
  14723. else if(strcmp(str, "str")== 0)
  14724. {
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14726. isSuccess = ConfigurationStatus_Accepted;
  14727. }
  14728. else if(strcmp(str, "trs")== 0)
  14729. {
  14730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14731. isSuccess = ConfigurationStatus_Accepted;
  14732. }
  14733. else if(strcmp(str, "tsr")== 0)
  14734. {
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14736. isSuccess = ConfigurationStatus_Accepted;
  14737. }
  14738. else
  14739. {
  14740. isSuccess = ConfigurationStatus_Rejected;
  14741. }
  14742. }
  14743. else
  14744. {
  14745. isSuccess = ConfigurationStatus_Rejected;
  14746. }
  14747. }
  14748. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14749. {
  14750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14751. {
  14752. check_ascii = value[0];
  14753. if( (check_ascii < 48) || (check_ascii > 57) )
  14754. {
  14755. isSuccess = ConfigurationStatus_Rejected;
  14756. }
  14757. else
  14758. {
  14759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14760. isSuccess = ConfigurationStatus_Accepted;
  14761. }
  14762. }
  14763. else
  14764. {
  14765. isSuccess = ConfigurationStatus_Rejected;
  14766. }
  14767. }
  14768. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14769. {
  14770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14771. {
  14772. strcpy(str, (const char*)value);
  14773. for(int i = 0; str[i]; i++)
  14774. {
  14775. str[i] = tolower(str[i]);
  14776. }
  14777. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14779. isSuccess = ConfigurationStatus_Accepted;
  14780. }
  14781. else
  14782. {
  14783. isSuccess = ConfigurationStatus_Rejected;
  14784. }
  14785. }
  14786. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14787. {
  14788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14789. {
  14790. strcpy(str, (const char*)value);
  14791. for(int i = 0; str[i]; i++)
  14792. {
  14793. str[i] = tolower(str[i]);
  14794. }
  14795. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14797. isSuccess = ConfigurationStatus_Accepted;
  14798. }
  14799. else
  14800. {
  14801. isSuccess = ConfigurationStatus_Rejected;
  14802. }
  14803. }
  14804. if(strcmp(key, "StopTxnAlignedData") == 0)
  14805. {
  14806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14807. {
  14808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14809. isSuccess = ConfigurationStatus_Accepted;
  14810. }
  14811. else
  14812. {
  14813. isSuccess = ConfigurationStatus_Rejected;
  14814. }
  14815. }
  14816. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14817. {
  14818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14819. {
  14820. check_ascii = value[0];
  14821. if( (check_ascii < 48) || (check_ascii > 57) )
  14822. {
  14823. isSuccess = ConfigurationStatus_Rejected;
  14824. }
  14825. else
  14826. {
  14827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14828. isSuccess = ConfigurationStatus_Accepted;
  14829. }
  14830. }
  14831. else
  14832. {
  14833. isSuccess = ConfigurationStatus_Rejected;
  14834. }
  14835. }
  14836. if(strcmp(key, "StopTxnSampledData") == 0)
  14837. {
  14838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14839. {
  14840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14841. isSuccess = ConfigurationStatus_Accepted;
  14842. }
  14843. else
  14844. {
  14845. isSuccess = ConfigurationStatus_Rejected;
  14846. }
  14847. }
  14848. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14849. {
  14850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14851. {
  14852. check_ascii = value[0];
  14853. if( (check_ascii < 48) || (check_ascii > 57) )
  14854. {
  14855. isSuccess = ConfigurationStatus_Rejected;
  14856. }
  14857. else
  14858. {
  14859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14860. isSuccess = ConfigurationStatus_Accepted;
  14861. }
  14862. }
  14863. else
  14864. {
  14865. isSuccess = ConfigurationStatus_Rejected;
  14866. }
  14867. }
  14868. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14869. {
  14870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14871. {
  14872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14873. isSuccess = ConfigurationStatus_Accepted;
  14874. }
  14875. else
  14876. {
  14877. isSuccess = ConfigurationStatus_Rejected;
  14878. }
  14879. }
  14880. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14881. {
  14882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14883. {
  14884. check_ascii = value[0];
  14885. if( (check_ascii < 48) || (check_ascii > 57) )
  14886. {
  14887. isSuccess = ConfigurationStatus_Rejected;
  14888. }
  14889. else
  14890. {
  14891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14892. isSuccess = ConfigurationStatus_Accepted;
  14893. }
  14894. }
  14895. else
  14896. {
  14897. isSuccess = ConfigurationStatus_Rejected;
  14898. }
  14899. }
  14900. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14901. {
  14902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14903. {
  14904. check_ascii = value[0];
  14905. if( (check_ascii < 48) || (check_ascii > 57) )
  14906. {
  14907. isSuccess = ConfigurationStatus_Rejected;
  14908. }
  14909. else
  14910. {
  14911. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14913. TransactionMessageAttemptsValue = atoi(value);
  14914. isSuccess = ConfigurationStatus_Accepted;
  14915. }
  14916. }
  14917. else
  14918. {
  14919. isSuccess = ConfigurationStatus_Rejected;
  14920. }
  14921. }
  14922. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14923. {
  14924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14925. {
  14926. check_ascii = value[0];
  14927. if( (check_ascii < 48) || (check_ascii > 57) )
  14928. {
  14929. isSuccess = ConfigurationStatus_Rejected;
  14930. }
  14931. else
  14932. {
  14933. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14935. TransactionMessageRetryIntervalValue = atoi(value);
  14936. isSuccess = ConfigurationStatus_Accepted;
  14937. }
  14938. }
  14939. else
  14940. {
  14941. isSuccess = ConfigurationStatus_Rejected;
  14942. }
  14943. }
  14944. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14945. {
  14946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14947. {
  14948. strcpy(str, (const char*)value);
  14949. for(int i = 0; str[i]; i++)
  14950. {
  14951. str[i] = tolower(str[i]);
  14952. }
  14953. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14955. isSuccess = ConfigurationStatus_Accepted;
  14956. }
  14957. else
  14958. {
  14959. isSuccess = ConfigurationStatus_Rejected;
  14960. }
  14961. }
  14962. if(strcmp(key, "WebSocketPingInterval") == 0)
  14963. {
  14964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14965. {
  14966. check_ascii = value[0];
  14967. if( (check_ascii < 48) || (check_ascii > 57) )
  14968. {
  14969. isSuccess = ConfigurationStatus_Rejected;
  14970. }
  14971. else
  14972. {
  14973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14974. isSuccess = ConfigurationStatus_Accepted;
  14975. }
  14976. }
  14977. else
  14978. {
  14979. isSuccess = ConfigurationStatus_Rejected;
  14980. }
  14981. }
  14982. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14983. {
  14984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14985. {
  14986. strcpy(str, (const char*)value);
  14987. for(int i = 0; str[i]; i++)
  14988. {
  14989. str[i] = tolower(str[i]);
  14990. }
  14991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14992. isSuccess = ConfigurationStatus_Accepted;
  14993. }
  14994. else
  14995. {
  14996. isSuccess = ConfigurationStatus_Rejected;
  14997. }
  14998. }
  14999. if(strcmp(key, "AuthorizationKey") == 0)
  15000. {
  15001. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15002. {
  15003. strcpy(str, (const char*)value);
  15004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15005. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15006. isSuccess = ConfigurationStatus_Accepted;
  15007. }
  15008. else
  15009. {
  15010. isSuccess = ConfigurationStatus_Rejected;
  15011. }
  15012. }
  15013. if(strcmp(key, "SecurityProfile") == 0)
  15014. {
  15015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15016. {
  15017. check_ascii = value[0];
  15018. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15019. {
  15020. isSuccess = ConfigurationStatus_Rejected;
  15021. }
  15022. else if(check_ascii == 0x33)
  15023. {
  15024. isSuccess = NotSupported;
  15025. }
  15026. else
  15027. {
  15028. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15029. {
  15030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15031. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15032. isSuccess = ConfigurationStatus_Accepted;
  15033. }
  15034. else
  15035. isSuccess = ConfigurationStatus_Rejected;
  15036. }
  15037. }
  15038. else
  15039. {
  15040. isSuccess = ConfigurationStatus_Rejected;
  15041. }
  15042. }
  15043. if(strcmp(key, "DefaultPrice") == 0)
  15044. {
  15045. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15046. {
  15047. strcpy(str, (const char*)value);
  15048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15049. isSuccess = ConfigurationStatus_Accepted;
  15050. }
  15051. else
  15052. {
  15053. isSuccess = ConfigurationStatus_Rejected;
  15054. }
  15055. }
  15056. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15057. {
  15058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15059. {
  15060. strcpy(str, (const char*)value);
  15061. for(int i = 0; str[i]; i++)
  15062. {
  15063. str[i] = tolower(str[i]);
  15064. }
  15065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15066. isSuccess = ConfigurationStatus_Accepted;
  15067. }
  15068. else
  15069. {
  15070. isSuccess = ConfigurationStatus_Rejected;
  15071. }
  15072. }
  15073. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15074. {
  15075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15076. {
  15077. strcpy(str, (const char*)value);
  15078. for(int i = 0; str[i]; i++)
  15079. {
  15080. str[i] = tolower(str[i]);
  15081. }
  15082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15083. isSuccess = ConfigurationStatus_Accepted;
  15084. }
  15085. else
  15086. {
  15087. isSuccess = ConfigurationStatus_Rejected;
  15088. }
  15089. }
  15090. if(strcmp(key, "TimeOffset") == 0)
  15091. {
  15092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15093. {
  15094. strcpy(str, (const char*)value);
  15095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15096. isSuccess = ConfigurationStatus_Accepted;
  15097. }
  15098. else
  15099. {
  15100. isSuccess = ConfigurationStatus_Rejected;
  15101. }
  15102. }
  15103. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15104. {
  15105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15106. {
  15107. strcpy(str, (const char*)value);
  15108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15109. isSuccess = ConfigurationStatus_Accepted;
  15110. }
  15111. else
  15112. {
  15113. isSuccess = ConfigurationStatus_Rejected;
  15114. }
  15115. }
  15116. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15117. {
  15118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15119. {
  15120. strcpy(str, (const char*)value);
  15121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15122. isSuccess = ConfigurationStatus_Accepted;
  15123. }
  15124. else
  15125. {
  15126. isSuccess = ConfigurationStatus_Rejected;
  15127. }
  15128. }
  15129. if(strcmp(key, "SystemUptimeSec") == 0)
  15130. {
  15131. isSuccess = NotSupported;
  15132. }
  15133. #if 0
  15134. //For OCPP Test Case
  15135. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15136. {
  15137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15138. {
  15139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15140. isSuccess = ConfigurationStatus_Accepted;
  15141. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15142. }
  15143. else
  15144. {
  15145. isSuccess = ConfigurationStatus_Rejected;
  15146. }
  15147. }
  15148. #endif
  15149. #if 1
  15150. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15151. {
  15152. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15153. {
  15154. strcpy(str, (const char*)value);
  15155. for(int i = 0; str[i]; i++)
  15156. {
  15157. str[i] = tolower(str[i]);
  15158. }
  15159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15160. isSuccess = ConfigurationStatus_Accepted;
  15161. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15162. }
  15163. else
  15164. {
  15165. isSuccess = ConfigurationStatus_Rejected;
  15166. }
  15167. }
  15168. #endif
  15169. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15170. {
  15171. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15172. {
  15173. check_ascii = value[0];
  15174. if( (check_ascii < 48) || (check_ascii > 57) )
  15175. {
  15176. isSuccess = ConfigurationStatus_Rejected;
  15177. }
  15178. else
  15179. {
  15180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15181. isSuccess = ConfigurationStatus_Accepted;
  15182. }
  15183. }
  15184. else
  15185. {
  15186. isSuccess = ConfigurationStatus_Rejected;
  15187. }
  15188. }
  15189. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15190. {
  15191. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15192. {
  15193. check_ascii = value[0];
  15194. if( (check_ascii < 48) || (check_ascii > 57) )
  15195. {
  15196. isSuccess = ConfigurationStatus_Rejected;
  15197. }
  15198. else
  15199. {
  15200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15201. isSuccess = ConfigurationStatus_Accepted;
  15202. }
  15203. }
  15204. else
  15205. {
  15206. isSuccess = ConfigurationStatus_Rejected;
  15207. }
  15208. }
  15209. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15210. {
  15211. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15212. {
  15213. strcpy(str, (const char*)value);
  15214. for(int i = 0; str[i]; i++)
  15215. {
  15216. str[i] = tolower(str[i]);
  15217. }
  15218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15219. isSuccess = ConfigurationStatus_Accepted;
  15220. }
  15221. else
  15222. {
  15223. isSuccess = ConfigurationStatus_Rejected;
  15224. }
  15225. }
  15226. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15227. {
  15228. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15229. {
  15230. check_ascii = value[0];
  15231. if( (check_ascii < 48) || (check_ascii > 57) )
  15232. {
  15233. isSuccess = ConfigurationStatus_Rejected;
  15234. }
  15235. else
  15236. {
  15237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15238. isSuccess = ConfigurationStatus_Accepted;
  15239. }
  15240. }
  15241. else
  15242. {
  15243. isSuccess = ConfigurationStatus_Rejected;
  15244. }
  15245. }
  15246. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15247. {
  15248. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15249. {
  15250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15251. isSuccess = ConfigurationStatus_Accepted;
  15252. }
  15253. else
  15254. {
  15255. isSuccess = ConfigurationStatus_Rejected;
  15256. }
  15257. }
  15258. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15259. {
  15260. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15261. {
  15262. check_ascii = value[0];
  15263. if( (check_ascii < 48) || (check_ascii > 57) )
  15264. {
  15265. isSuccess = ConfigurationStatus_Rejected;
  15266. }
  15267. else
  15268. {
  15269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15270. isSuccess = ConfigurationStatus_Accepted;
  15271. }
  15272. }
  15273. else
  15274. {
  15275. isSuccess = ConfigurationStatus_Rejected;
  15276. }
  15277. }
  15278. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15279. {
  15280. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15281. {
  15282. strcpy(str, (const char*)value);
  15283. for(int i = 0; str[i]; i++)
  15284. {
  15285. str[i] = tolower(str[i]);
  15286. }
  15287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15288. isSuccess = ConfigurationStatus_Accepted;
  15289. }
  15290. else
  15291. {
  15292. isSuccess = ConfigurationStatus_Rejected;
  15293. }
  15294. }
  15295. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15296. {
  15297. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15298. {
  15299. check_ascii = value[0];
  15300. if( (check_ascii < 48) || (check_ascii > 57) )
  15301. {
  15302. isSuccess = ConfigurationStatus_Rejected;
  15303. }
  15304. else
  15305. {
  15306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15307. isSuccess = ConfigurationStatus_Accepted;
  15308. }
  15309. }
  15310. else
  15311. {
  15312. isSuccess = ConfigurationStatus_Rejected;
  15313. }
  15314. }
  15315. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15316. return isSuccess;
  15317. }
  15318. int TransactionMessageAttemptsGet(void)
  15319. {
  15320. return TransactionMessageAttemptsValue;
  15321. }
  15322. int FirstHeartBeatResponse(void)
  15323. {
  15324. return FirstHeartBeat;
  15325. }
  15326. int TransactionMessageRetryIntervalGet(void)
  15327. {
  15328. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15329. }
  15330. int ReadHttpStatus(int sock)
  15331. {
  15332. //char c;
  15333. char buff[1024]="",*ptr=buff+1;
  15334. int bytes_received, status;
  15335. DEBUG_INFO("Begin Response ..\n");
  15336. while((bytes_received = recv(sock, ptr, 1, 0))){
  15337. if(bytes_received==-1){
  15338. perror("ReadHttpStatus");
  15339. exit(1);
  15340. }
  15341. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15342. ptr++;
  15343. }
  15344. *ptr=0;
  15345. ptr=buff+1;
  15346. sscanf(ptr,"%*s %d ", &status);
  15347. DEBUG_INFO("%s\n",ptr);
  15348. DEBUG_INFO("status=%d\n",status);
  15349. DEBUG_INFO("End Response ..\n");
  15350. return (bytes_received>0)?status:0;
  15351. }
  15352. //the only filed that it parsed is 'Content-Length'
  15353. int ParseHeader(int sock)
  15354. {
  15355. //char c;
  15356. char buff[1024]="",*ptr=buff+4;
  15357. int bytes_received;
  15358. DEBUG_INFO("Begin HEADER ..\n");
  15359. while((bytes_received = recv(sock, ptr, 1, 0))){
  15360. if(bytes_received==-1){
  15361. perror("Parse Header");
  15362. exit(1);
  15363. }
  15364. if(
  15365. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15366. (ptr[-1]=='\r') && (*ptr=='\n' )
  15367. ) break;
  15368. ptr++;
  15369. }
  15370. *ptr=0;
  15371. ptr=buff+4;
  15372. //printf("%s",ptr);
  15373. if(bytes_received){
  15374. ptr=strstr(ptr,"Content-Length:");
  15375. if(ptr){
  15376. sscanf(ptr,"%*s %d",&bytes_received);
  15377. }else
  15378. bytes_received=-1; //unknown size
  15379. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15380. }
  15381. DEBUG_INFO("End HEADER ..\n");
  15382. return bytes_received ;
  15383. }
  15384. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15385. {
  15386. int result = TRUE;
  15387. char rmFileCmd[100]={0};
  15388. char FilePath[100]={0};
  15389. char ftpbuf[200];
  15390. int systemresult;
  15391. sprintf(FilePath,"/mnt/%s",filename);
  15392. system("ping 8.8.8.8 &");
  15393. if((access(FilePath,F_OK))!=-1)
  15394. {
  15395. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15396. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15397. system(rmFileCmd);
  15398. }
  15399. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15400. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15401. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15402. systemresult = system(ftpbuf);
  15403. if(systemresult != 0)
  15404. {
  15405. DEBUG_INFO("http DownLoad error!\n");
  15406. result = FALSE;
  15407. }
  15408. system("pkill ping");
  15409. return result;
  15410. }
  15411. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15412. {
  15413. int result = TRUE;
  15414. char rmFileCmd[100]={0};
  15415. char FilePath[100]={0};
  15416. char ftpbuf[200];
  15417. int systemresult;
  15418. sprintf(FilePath,"/mnt/%s",filename);
  15419. system("ping 8.8.8.8 &");
  15420. if((access(FilePath,F_OK))!=-1)
  15421. {
  15422. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15423. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15424. system(rmFileCmd);
  15425. }
  15426. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15427. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15428. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15429. systemresult = system(ftpbuf);
  15430. if(systemresult != 0)
  15431. {
  15432. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15433. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15434. systemresult = system(ftpbuf);
  15435. if(systemresult != 0)
  15436. {
  15437. DEBUG_WARN("wget error!\n");
  15438. result = FALSE;
  15439. }
  15440. }
  15441. system("pkill ping");
  15442. return result;
  15443. }
  15444. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15445. {
  15446. char rmFileCmd[100]={0};
  15447. char FilePath[100]={0};
  15448. char buf[512];
  15449. int systemresult = 0;
  15450. //DEBUG_INFO("filename=%s\n",filename);
  15451. //DEBUG_INFO("url=%s\n",url);
  15452. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15453. if((access(FilePath,F_OK))!=-1)
  15454. {
  15455. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15456. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15457. system(rmFileCmd);
  15458. }
  15459. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15460. if(fp == NULL)
  15461. {
  15462. DEBUG_INFO("log is NULL\n");
  15463. return FALSE;
  15464. }
  15465. else
  15466. {
  15467. fprintf(fp, "%s\n", url);
  15468. fprintf(fp, "%s\n", filename);
  15469. fclose(fp);
  15470. }
  15471. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15472. if(phpFP == NULL)
  15473. {
  15474. DEBUG_INFO("PHP upload fail.\n");
  15475. return FALSE;
  15476. }
  15477. else
  15478. {
  15479. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15480. {
  15481. if(strstr(buf, "result") != NULL)
  15482. {
  15483. sscanf(buf, "result: %d", &systemresult);
  15484. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15485. }
  15486. }
  15487. pclose(phpFP);
  15488. }
  15489. if(systemresult != 1)
  15490. {
  15491. DEBUG_INFO("HTTP upload error!\n");
  15492. return FALSE;
  15493. }
  15494. return TRUE;
  15495. }
  15496. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15497. {
  15498. struct hostent* server;
  15499. char *IPbuffer;
  15500. char ftpbuf[200];
  15501. int systemresult;
  15502. // To retrieve host information
  15503. server = gethostbyname(location);
  15504. // To convert an Internet network
  15505. // address into ASCII string
  15506. IPbuffer = inet_ntoa(*((struct in_addr*)
  15507. server->h_addr_list[0]));
  15508. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15509. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15510. /* format : ftpput -u username -p passwd IP target source*/
  15511. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15512. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15513. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15514. systemresult = system(ftpbuf);
  15515. DEBUG_INFO("systemresult=%d\n",systemresult);
  15516. if(systemresult != 0)
  15517. {
  15518. DEBUG_INFO("ftpput error!\n");
  15519. return FALSE;
  15520. }
  15521. return TRUE;
  15522. }
  15523. int GetOcppServerURL()
  15524. {
  15525. int result = FALSE;
  15526. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15527. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15528. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15529. struct yuarel url;
  15530. char urlStr[512];
  15531. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15532. {
  15533. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15534. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15535. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15536. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15537. if(yuarel_parse(&url, urlStr) != -1)
  15538. {
  15539. sprintf(OcppProtocol, "%s", url.scheme);
  15540. sprintf(OcppHost, "%s", url.host);
  15541. if(url.path == NULL)
  15542. OcppTempPath[0] = '\0';
  15543. else
  15544. {
  15545. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15546. {
  15547. sprintf(OcppTempPath, "%s/", url.path);
  15548. }
  15549. else
  15550. {
  15551. sprintf(OcppTempPath, "%s", url.path);
  15552. }
  15553. }
  15554. if(url.port == 0)
  15555. {
  15556. if(strcmp(OcppProtocol, "wss") == 0)
  15557. OcppPort = 443;
  15558. else
  15559. OcppPort = 80;
  15560. }
  15561. else
  15562. OcppPort = url.port;
  15563. result = TRUE;
  15564. }
  15565. }
  15566. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15567. {
  15568. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15569. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15570. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15571. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15572. if(yuarel_parse(&url, urlStr) != -1)
  15573. {
  15574. sprintf(OcppProtocol, "%s", url.scheme);
  15575. sprintf(OcppHost, "%s", url.host);
  15576. if(url.path == NULL)
  15577. OcppTempPath[0] = '\0';
  15578. else
  15579. sprintf(OcppTempPath, "%s", url.path);
  15580. if(url.port == 0)
  15581. {
  15582. if(strcmp(OcppProtocol, "wss") == 0)
  15583. OcppPort = 443;
  15584. else
  15585. OcppPort = 80;
  15586. }
  15587. else
  15588. OcppPort = url.port;
  15589. result = TRUE;
  15590. }
  15591. }
  15592. else
  15593. {
  15594. strcpy(OcppHost,"");
  15595. }
  15596. return result;
  15597. }
  15598. int GetOcppPath()
  15599. {
  15600. int result = FALSE;
  15601. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15602. {
  15603. if(OcppTempPath == NULL)
  15604. {
  15605. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15606. }
  15607. else
  15608. {
  15609. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15610. }
  15611. result = TRUE;
  15612. goto End;
  15613. }
  15614. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15615. {
  15616. if(OcppTempPath == NULL)
  15617. {
  15618. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15619. }
  15620. else
  15621. {
  15622. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15623. }
  15624. result = TRUE;
  15625. goto End;
  15626. }
  15627. else
  15628. {
  15629. strcpy(OcppPath,"");
  15630. }
  15631. End:
  15632. return result;
  15633. }
  15634. int GetOcppPort()
  15635. {
  15636. return OcppPort;
  15637. }
  15638. int GetOcppConnStatus(void)
  15639. {
  15640. return ShmOCPP16Data->OcppConnStatus;
  15641. }
  15642. void SetOcppConnStatus(uint8_t status)
  15643. {
  15644. ShmOCPP16Data->OcppConnStatus = status;
  15645. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15646. }
  15647. int GetHeartBeatWithNOResponse(void)
  15648. {
  15649. return HeartBeatWithNOResponse;
  15650. }
  15651. void SetHeartBeatWithNOResponse(void)
  15652. {
  15653. HeartBeatWithNOResponse = 0;
  15654. }
  15655. void GetStartTransactionIdTag(int gun_index)
  15656. {
  15657. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15658. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15659. }
  15660. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15661. {
  15662. char ch;
  15663. FILE *fptr1;
  15664. int temptransactionId;
  15665. char str[100]={0};
  15666. temptransactionId = 0;
  15667. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15668. {
  15669. DEBUG_INFO("IdTag is empty.\n");
  15670. return temptransactionId;
  15671. }
  15672. /*------ Read the file ----------------*/
  15673. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15674. if (!fptr1)
  15675. {
  15676. DEBUG_INFO("QueueTransactionId file open error.\n");
  15677. //printf(" File not found or unable to open the input file!!\n");
  15678. return temptransactionId;
  15679. }
  15680. ch=fgetc(fptr1);
  15681. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15682. rewind(fptr1);
  15683. if(ch!=EOF)
  15684. {
  15685. // printf("%c",ch);
  15686. while (fgets(str, 100, fptr1) != NULL)
  15687. {
  15688. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15689. if(str[0]=='\0')
  15690. {
  15691. break;
  15692. }
  15693. char *revbuf[8] = {0}; // Variable store string split
  15694. int num = 0;// Quantity after string split
  15695. DEBUG_INFO("Transaction queue data= %s\n", str);
  15696. splitstring(str,",",revbuf,&num); // String split
  15697. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15698. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15699. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15700. DEBUG_INFO("------------------------------\n");
  15701. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15702. {
  15703. if(isStopTransaction)
  15704. {
  15705. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15706. {
  15707. temptransactionId = atoi(revbuf[2]);
  15708. //break;
  15709. }
  15710. }
  15711. else
  15712. {
  15713. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15714. {
  15715. temptransactionId = atoi(revbuf[2]);
  15716. //break;
  15717. }
  15718. }
  15719. }
  15720. }
  15721. }
  15722. else
  15723. DEBUG_INFO("EOF\n");
  15724. fclose(fptr1);
  15725. /*------- End of reading ---------------*/
  15726. return temptransactionId;
  15727. }
  15728. void SetTransactionIdZero(int transactionId)
  15729. {
  15730. char ch;
  15731. FILE *fptr1, *fptr2;
  15732. int temptransactionId = 0;
  15733. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15734. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15735. if (!fptr1)
  15736. {
  15737. //printf(" File not found or unable to open the input file!!\n");
  15738. return ;
  15739. }
  15740. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15741. if (!fptr2)
  15742. {
  15743. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15744. fclose(fptr1);
  15745. return ;
  15746. }
  15747. ch=fgetc(fptr1);
  15748. rewind(fptr1);
  15749. if(ch!=EOF)
  15750. {
  15751. // copy all contents to the temporary file except the specific line
  15752. while (fgets(str, 100, fptr1) != NULL)
  15753. {
  15754. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15755. if(str[0]=='\0')
  15756. {
  15757. break;
  15758. }
  15759. char *revbuf[8] = {0};
  15760. int num = 0;
  15761. strcpy(strtemp, str);
  15762. splitstring(str,",",revbuf,&num);
  15763. if(revbuf[2][0] != '\0')
  15764. {
  15765. temptransactionId = atoi(revbuf[2]);
  15766. if(transactionId != temptransactionId)
  15767. {
  15768. fprintf(fptr2, "%s\n", strtemp);
  15769. }
  15770. }
  15771. }
  15772. }
  15773. fclose(fptr1);
  15774. fclose(fptr2);
  15775. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15776. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15777. /*------ Read the file ----------------*/
  15778. }
  15779. int InternetDisconnect(void)
  15780. {
  15781. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15782. }
  15783. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15784. void storeTempStopTransaction(int gun_index)
  15785. {
  15786. char guid[37]={0};
  15787. int tempIndex = 0;
  15788. char TempStopTransaction[256];
  15789. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15790. DEBUG_INFO("storeTempStopTransaction...\n");
  15791. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15792. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15793. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15796. {
  15797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15798. {
  15799. tempIndex = ((gun_index==2) ? 1: 0);
  15800. }
  15801. else
  15802. {
  15803. tempIndex = gun_index;
  15804. }
  15805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15806. {
  15807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15808. {
  15809. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15810. }
  15811. }// END OF CHAdeMO_QUANTITY
  15812. }
  15813. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15814. {
  15815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15816. {
  15817. tempIndex = ((gun_index==2) ? 1: 0);
  15818. }
  15819. else
  15820. {
  15821. tempIndex = gun_index;
  15822. }
  15823. for (int index = 0; index < CCS_QUANTITY; index++)
  15824. {
  15825. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15826. {
  15827. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15828. }
  15829. }// END OF CCS_QUANTITY
  15830. }
  15831. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15832. {
  15833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15834. {
  15835. tempIndex = ((gun_index==2) ? 1: 0);
  15836. }
  15837. else
  15838. {
  15839. tempIndex = gun_index;
  15840. }
  15841. for (int index = 0; index < GB_QUANTITY; index++)
  15842. {
  15843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15844. {
  15845. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15846. }
  15847. }// END OF GB_QUANTITY
  15848. }
  15849. else if(gunType[gun_index] == GUN_TYPE_DO)
  15850. {
  15851. tempIndex = gun_index;
  15852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15853. {
  15854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15855. {
  15856. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15857. }
  15858. }
  15859. }
  15860. else
  15861. {
  15862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15863. {
  15864. tempIndex = 2;
  15865. }
  15866. else
  15867. {
  15868. tempIndex = gun_index;
  15869. }
  15870. for (int index = 0; index < AC_QUANTITY; index++)
  15871. {
  15872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15873. {
  15874. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15875. }
  15876. }// END OF AC_QUANTITY
  15877. }
  15878. //Stop Transaction Time
  15879. struct timeval tmnow;
  15880. struct tm *tm;
  15881. char buf[28];//, usec_buf[6];
  15882. gettimeofday(&tmnow, NULL);
  15883. time_t t;
  15884. t = time(NULL);
  15885. /*UTC time and date*/
  15886. tm = gmtime(&t);
  15887. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15889. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15891. random_uuid(guid);
  15892. /***********************************transactionData******************************************************/
  15893. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15895. //=================================
  15896. //1. Transaction_Begin
  15897. //=================================
  15898. //============================== Energy.Active.Import.Interval ===========================================
  15899. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15900. {
  15901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15904. 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*/]);
  15905. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15906. 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))
  15907. {
  15908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15909. }
  15910. else
  15911. {
  15912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15913. }
  15914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15916. }
  15917. //=================================
  15918. //2. Transaction_End
  15919. //=================================
  15920. //2.1====================================== Current.Import L1 ==============================================
  15921. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15922. {
  15923. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15924. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15925. {
  15926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15927. {
  15928. tempIndex = ((gun_index==2) ? 1: 0);
  15929. }
  15930. else
  15931. {
  15932. tempIndex = gun_index;
  15933. }
  15934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15935. {
  15936. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15937. {
  15938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15939. }
  15940. }// End of for CHAdeMO_QUANTITY
  15941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15942. }
  15943. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15944. {
  15945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15946. {
  15947. tempIndex = ((gun_index==2) ? 1: 0);
  15948. }
  15949. else
  15950. {
  15951. tempIndex = gun_index;
  15952. }
  15953. for (int index = 0; index < CCS_QUANTITY; index++)
  15954. {
  15955. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15956. {
  15957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15958. }
  15959. }// End of for CCS_QUANTITY
  15960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15961. }
  15962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15963. {
  15964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15965. {
  15966. tempIndex = ((gun_index==2) ? 1: 0);
  15967. }
  15968. else
  15969. {
  15970. tempIndex = gun_index;
  15971. }
  15972. for (int index = 0; index < GB_QUANTITY; index++)
  15973. {
  15974. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15975. {
  15976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15977. }
  15978. }// End of for GB_QUANTITY
  15979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15980. }
  15981. else if(gunType[gun_index] == GUN_TYPE_DO)
  15982. {
  15983. tempIndex = gun_index;
  15984. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15985. {
  15986. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15987. {
  15988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15989. }
  15990. }
  15991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15992. }
  15993. else
  15994. {
  15995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15996. {
  15997. tempIndex = 2;
  15998. }
  15999. else
  16000. {
  16001. tempIndex = gun_index;
  16002. }
  16003. for (int index = 0; index < AC_QUANTITY; index++)
  16004. {
  16005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16006. {
  16007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16008. }
  16009. }// End of for AC_QUANTITY
  16010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16011. }
  16012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16015. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16018. }
  16019. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16020. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16021. {
  16022. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16023. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16024. {
  16025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16026. {
  16027. tempIndex = ((gun_index==2) ? 1: 0);
  16028. }
  16029. else
  16030. {
  16031. tempIndex = gun_index;
  16032. }
  16033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16034. {
  16035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16036. {
  16037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16038. }
  16039. }// END OF CHAdeMO_QUANTITY
  16040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16041. }
  16042. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16043. {
  16044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16045. {
  16046. tempIndex = ((gun_index==2) ? 1: 0);
  16047. }
  16048. else
  16049. {
  16050. tempIndex = gun_index;
  16051. }
  16052. for (int index = 0; index < CCS_QUANTITY; index++)
  16053. {
  16054. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16055. {
  16056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16057. }
  16058. }// END OF CCS_QUANTITY
  16059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16060. }
  16061. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16062. {
  16063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16064. {
  16065. tempIndex = ((gun_index==2) ? 1: 0);
  16066. }
  16067. else
  16068. {
  16069. tempIndex = gun_index;
  16070. }
  16071. for (int index = 0; index < GB_QUANTITY; index++)
  16072. {
  16073. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16074. {
  16075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16076. }
  16077. }// END OF GB_QUANTITY
  16078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16079. }
  16080. else if(gunType[gun_index] == GUN_TYPE_DO)
  16081. {
  16082. tempIndex = gun_index;
  16083. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16084. {
  16085. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16086. {
  16087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16088. }
  16089. }
  16090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16091. }
  16092. else
  16093. {
  16094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16095. {
  16096. tempIndex = 2;
  16097. }
  16098. else
  16099. {
  16100. tempIndex = gun_index;
  16101. }
  16102. for (int index = 0; index < AC_QUANTITY; index++)
  16103. {
  16104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16105. {
  16106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16107. }
  16108. }// END OF AC_QUANTITY
  16109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16110. }
  16111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16114. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16117. }
  16118. //2.3====================================== Power.Active.Import =========================================
  16119. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16120. {
  16121. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16123. {
  16124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16125. {
  16126. tempIndex = ((gun_index==2) ? 1: 0);
  16127. }
  16128. else
  16129. {
  16130. tempIndex = gun_index;
  16131. }
  16132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16133. {
  16134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16135. {
  16136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16137. }
  16138. } // End for CHAdeMO_QUANTITY
  16139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16140. }
  16141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16142. {
  16143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16144. {
  16145. tempIndex = ((gun_index==2) ? 1: 0);
  16146. }
  16147. else
  16148. {
  16149. tempIndex = gun_index;
  16150. }
  16151. for (int index = 0; index < CCS_QUANTITY; index++)
  16152. {
  16153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16154. {
  16155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16156. }
  16157. } // END for CCS_QUANTITY
  16158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16159. }
  16160. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16161. {
  16162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16163. {
  16164. tempIndex = ((gun_index==2) ? 1: 0);
  16165. }
  16166. else
  16167. {
  16168. tempIndex = gun_index;
  16169. }
  16170. for (int index = 0; index < GB_QUANTITY; index++)
  16171. {
  16172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16173. {
  16174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16175. }
  16176. }// END for GB_QUANTITY
  16177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16178. }
  16179. else if(gunType[gun_index] == GUN_TYPE_DO)
  16180. {
  16181. tempIndex = gun_index;
  16182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16183. {
  16184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16185. {
  16186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16187. }
  16188. }
  16189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16190. }
  16191. else
  16192. {
  16193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16194. {
  16195. tempIndex = 2;
  16196. }
  16197. else
  16198. {
  16199. tempIndex = gun_index;
  16200. }
  16201. for (int index = 0; index < AC_QUANTITY; index++)
  16202. {
  16203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16204. {
  16205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16206. }
  16207. } // END for AC_QUANTITY
  16208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16209. }
  16210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16213. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16216. }
  16217. //2.4====================================== Voltage L1 ====================================================
  16218. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16219. {
  16220. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16222. {
  16223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16224. {
  16225. tempIndex = ((gun_index==2) ? 1: 0);
  16226. }
  16227. else
  16228. {
  16229. tempIndex = gun_index;
  16230. }
  16231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16232. {
  16233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16234. {
  16235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16236. }
  16237. } // END OF FOR CHAdeMO_QUANTITY
  16238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16239. }
  16240. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16241. {
  16242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16243. {
  16244. tempIndex = ((gun_index==2) ? 1: 0);
  16245. }
  16246. else
  16247. {
  16248. tempIndex = gun_index;
  16249. }
  16250. for (int index = 0; index < CCS_QUANTITY; index++)
  16251. {
  16252. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16253. {
  16254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16255. }
  16256. } // END OF FOR CCS_QUANTITY
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16258. }
  16259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16260. {
  16261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16262. {
  16263. tempIndex = ((gun_index==2) ? 1: 0);
  16264. }
  16265. else
  16266. {
  16267. tempIndex = gun_index;
  16268. }
  16269. for (int index = 0; index < GB_QUANTITY; index++)
  16270. {
  16271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16272. {
  16273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16274. }
  16275. } // END OF FOR GB_QUANTITY
  16276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16277. }
  16278. else if(gunType[gun_index] == GUN_TYPE_DO)
  16279. {
  16280. tempIndex = gun_index;
  16281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16282. {
  16283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16284. {
  16285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16286. }
  16287. }
  16288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16289. }
  16290. else
  16291. {
  16292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16293. {
  16294. tempIndex = 2;
  16295. }
  16296. else
  16297. {
  16298. tempIndex = gun_index;
  16299. }
  16300. for (int index = 0; index < AC_QUANTITY; index++)
  16301. {
  16302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16303. {
  16304. 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
  16305. }
  16306. } // END OF FOR AC_QUANTITY
  16307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16308. }
  16309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16312. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16315. }
  16316. //2.5============================================== End SoC =========================================================
  16317. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16318. {
  16319. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16320. 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))
  16321. {
  16322. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16323. {
  16324. tempIndex = ((gun_index==2) ? 1: 0);
  16325. }
  16326. else
  16327. {
  16328. tempIndex = gun_index;
  16329. }
  16330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16331. {
  16332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16333. {
  16334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16335. {
  16336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16337. }
  16338. }
  16339. }
  16340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16341. {
  16342. for (int index = 0; index < CCS_QUANTITY; index++)
  16343. {
  16344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16345. {
  16346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16347. }
  16348. }
  16349. }
  16350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16351. {
  16352. for (int index = 0; index < GB_QUANTITY; index++)
  16353. {
  16354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16355. {
  16356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16357. }
  16358. }
  16359. }
  16360. else if(gunType[gun_index] == GUN_TYPE_DO)
  16361. {
  16362. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16363. {
  16364. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16365. {
  16366. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16367. }
  16368. }
  16369. }
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16376. } // END FOR DC CASE
  16377. }
  16378. //2.6====================================== Current.Import L2 ==============================================
  16379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16380. {
  16381. // AC 3 phase L2 current
  16382. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16383. {
  16384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16385. {
  16386. tempIndex = 2;
  16387. }
  16388. else
  16389. {
  16390. tempIndex = gun_index;
  16391. }
  16392. for (int index = 0; index < AC_QUANTITY; index++)
  16393. {
  16394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16395. {
  16396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16397. }
  16398. }// End of for AC_QUANTITY
  16399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16400. }
  16401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16406. }
  16407. //2.7====================================== Current.Import L3 ==============================================
  16408. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16409. {
  16410. // AC 3 phase L3 current
  16411. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16412. {
  16413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16414. {
  16415. tempIndex = 2;
  16416. }
  16417. else
  16418. {
  16419. tempIndex = gun_index;
  16420. }
  16421. for (int index = 0; index < AC_QUANTITY; index++)
  16422. {
  16423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16424. {
  16425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16426. }
  16427. }// End of for AC_QUANTITY
  16428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16429. }
  16430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16435. }
  16436. //2.9====================================== Voltage L2 ====================================================
  16437. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16438. {
  16439. // AC 3 phase L2 volatge
  16440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16441. {
  16442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16443. {
  16444. tempIndex = 2;
  16445. }
  16446. else
  16447. {
  16448. tempIndex = gun_index;
  16449. }
  16450. for (int index = 0; index < AC_QUANTITY; index++)
  16451. {
  16452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16453. {
  16454. 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
  16455. }
  16456. } // END OF FOR AC_QUANTITY
  16457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16458. }
  16459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16464. }
  16465. //2.10====================================== Voltage L3 ====================================================
  16466. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16467. {
  16468. // AC 3 phase L3 volatge
  16469. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16470. {
  16471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16472. {
  16473. tempIndex = 2;
  16474. }
  16475. else
  16476. {
  16477. tempIndex = gun_index;
  16478. }
  16479. for (int index = 0; index < AC_QUANTITY; index++)
  16480. {
  16481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16482. {
  16483. 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
  16484. }
  16485. } // END OF FOR AC_QUANTITY
  16486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16487. }
  16488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16493. }
  16494. //====================== Start SoC ================================
  16495. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16496. {
  16497. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16498. 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))
  16499. {
  16500. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16501. {
  16502. tempIndex = ((gun_index==2) ? 1: 0);
  16503. }
  16504. else
  16505. {
  16506. tempIndex = gun_index;
  16507. }
  16508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16509. {
  16510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16511. {
  16512. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16513. {
  16514. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16515. }
  16516. }
  16517. }
  16518. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16519. {
  16520. for (int index = 0; index < CCS_QUANTITY; index++)
  16521. {
  16522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16523. {
  16524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16525. }
  16526. }
  16527. }
  16528. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16529. {
  16530. for (int index = 0; index < GB_QUANTITY; index++)
  16531. {
  16532. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16533. {
  16534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16535. }
  16536. }
  16537. }
  16538. else if(gunType[gun_index] == GUN_TYPE_DO)
  16539. {
  16540. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16541. {
  16542. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16543. {
  16544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16545. }
  16546. }
  16547. }
  16548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16554. } // END FOR DC CASE
  16555. }
  16556. //======================================== Message create ==============================================
  16557. json_object *StopTransaction = json_object_new_object();
  16558. json_object *transactionDatas = json_object_new_array();
  16559. json_object *sampledValues = json_object_new_array();
  16560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16561. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16562. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16563. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16564. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16565. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16566. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16567. {
  16568. json_object *transactionData = json_object_new_object();
  16569. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16570. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16571. {
  16572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16573. {
  16574. json_object *sampledValue = json_object_new_object();
  16575. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16576. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16577. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16578. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16579. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16580. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16581. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16582. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16583. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16584. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16585. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16586. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16587. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16588. json_object_array_add(sampledValues, sampledValue);
  16589. }
  16590. }
  16591. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16592. json_object_array_add(transactionDatas, transactionData);
  16593. }
  16594. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16595. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16596. ,MESSAGE_TYPE_CALL
  16597. ,guid
  16598. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16599. json_object_put(StopTransaction);
  16600. // Check File "TempStopTransaction" Exist
  16601. if((access(TempStopTransaction,F_OK))!=-1)
  16602. {
  16603. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16604. fclose(fopen(TempStopTransaction, "w"));
  16605. }
  16606. else
  16607. {
  16608. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16609. FILE *log = fopen(TempStopTransaction, "w+");
  16610. if(log == NULL)
  16611. {
  16612. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16613. return ;
  16614. }
  16615. else
  16616. {
  16617. fclose(log);
  16618. }
  16619. }
  16620. //Add TempStopTransaction | Update TempStopTransaction
  16621. // open file for writing
  16622. FILE *outfile;
  16623. outfile = fopen (TempStopTransaction, "a");
  16624. //DEBUG_INFO("data = %s\n", queuedata);
  16625. fputs(queuedata, outfile);
  16626. fputs("\n", outfile);
  16627. fclose (outfile);
  16628. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16629. }
  16630. void checkTempStopTransaction(int gun_index)
  16631. {
  16632. FILE *fptr1;
  16633. char ch;
  16634. char str[QUEUE_MESSAGE_LENGTH]={0};
  16635. char guid[37]={0};
  16636. char tempdata[65]={0};
  16637. char connectorStr[2]={0};
  16638. char TempStopTransaction[256];
  16639. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16640. fptr1 = fopen(TempStopTransaction, "r");
  16641. //TempStopTransaction格式: 槍號,StopTransaction封包
  16642. if (!fptr1)
  16643. {
  16644. //printf(" File not found or unable to open the input file!!\n");
  16645. return ;
  16646. }
  16647. ch=fgetc(fptr1);
  16648. //printf(" Now the content of the file %s is : \n",fname);
  16649. rewind(fptr1);
  16650. if(ch!=EOF)
  16651. {
  16652. // copy all contents to the temporary file except the specific line
  16653. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16654. {
  16655. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16656. if(str[0]=='\0')
  16657. {
  16658. break;
  16659. }
  16660. //TempStopTransaction格式: 槍號,StopTransaction封包
  16661. strncpy(connectorStr, str, 1);
  16662. if(atoi(connectorStr) != (gun_index+1))
  16663. {
  16664. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16665. fclose(fptr1);
  16666. return ;
  16667. }
  16668. //random_uuid(guid);
  16669. strncpy(guid, str+6, 36); //copy guid
  16670. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16671. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16672. {
  16673. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16674. }
  16675. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16676. OCPP_insert_transaction_msg(NO, str);
  16677. memset(str,0,ARRAY_SIZE(str));
  16678. }
  16679. }
  16680. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16681. fclose(fptr1);
  16682. remove(TempStopTransaction); // remove the original file
  16683. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16684. }
  16685. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16686. {
  16687. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16688. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16689. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16690. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16691. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16692. }
  16693. int GetWebSocketPingInterval(void)
  16694. {
  16695. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16696. }
  16697. int GetServerSign(void)
  16698. {
  16699. return server_sign;
  16700. }
  16701. uint8_t GetOcppSecurityProfile()
  16702. {
  16703. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16704. }
  16705. void GetOcppChargerBoxId(uint8_t *data)
  16706. {
  16707. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16708. }
  16709. void GetOcppSecurityPassword(uint8_t *data)
  16710. {
  16711. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16712. }
  16713. void SetOcppVersion(uint8_t *version)
  16714. {
  16715. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16716. DEBUG_INFO("ocpp version: %s\n", version);
  16717. if(strstr((char*)version, "ocpp1.6") != NULL)
  16718. {
  16719. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16720. }
  16721. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16722. {
  16723. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16724. system("pkill OcppBackend");
  16725. }
  16726. }
  16727. void SetServerSign(int value)
  16728. {
  16729. server_sign = value;
  16730. }
  16731. int GetBootNotificationInterval(void)
  16732. {
  16733. return BootNotificationInterval;
  16734. }
  16735. int GetInternetConn(void)
  16736. {
  16737. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16738. }
  16739. int GetBackendConnectionTimeout(void)
  16740. {
  16741. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16742. }
  16743. int isConnectorInitMode(int gun_index)
  16744. {
  16745. int tempIndex = 0;
  16746. int result = TRUE;
  16747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16748. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16749. {
  16750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16751. {
  16752. tempIndex = ((gun_index==2) ? 1: 0);
  16753. }
  16754. else
  16755. {
  16756. tempIndex = gun_index;
  16757. }
  16758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16759. {
  16760. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16761. {
  16762. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16763. } //end of the same index
  16764. }//end of for CHAdeMO_QUANTITY
  16765. }
  16766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16767. {
  16768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16769. {
  16770. tempIndex = ((gun_index==2) ? 1: 0);
  16771. }
  16772. else
  16773. {
  16774. tempIndex = gun_index;
  16775. }
  16776. for (int index = 0; index < CCS_QUANTITY; index++)
  16777. {
  16778. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16779. {
  16780. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16781. } //end of the same index
  16782. } // end of for CCS_QUANTITY
  16783. }
  16784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16785. {
  16786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16787. {
  16788. tempIndex = ((gun_index==2) ? 1: 0);
  16789. }
  16790. else
  16791. {
  16792. tempIndex = gun_index;
  16793. }
  16794. for (int index = 0; index < GB_QUANTITY; index++)
  16795. {
  16796. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16797. {
  16798. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16799. } //end of the same index
  16800. } // end of for GB_QUANTITY
  16801. }
  16802. else if(gunType[gun_index] == GUN_TYPE_DO)
  16803. {
  16804. tempIndex = gun_index;
  16805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16806. {
  16807. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16808. {
  16809. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16810. } //end of the same index
  16811. }
  16812. }
  16813. else
  16814. {
  16815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16816. {
  16817. tempIndex = 2;
  16818. }
  16819. else
  16820. {
  16821. tempIndex = gun_index;
  16822. }
  16823. for (int index = 0; index < AC_QUANTITY; index++)
  16824. {
  16825. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16826. {
  16827. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16828. }//end of the same index
  16829. }//end of for AC_QUANTITY
  16830. }
  16831. return result;
  16832. }
  16833. void refreshProcDogTimer()
  16834. {
  16835. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16836. }
  16837. void InitialSystemValue(void)
  16838. {
  16839. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16840. gunTotalNumber=0;
  16841. SystemInitial = 0;
  16842. locallistVersion=0;
  16843. BootNotificationInterval = 0;
  16844. authorizeRetryTimes = 0;
  16845. GunStatusInterval = 10;
  16846. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16847. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16848. //Hear Beat
  16849. HeartBeatWithNOResponse = 0;
  16850. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16851. FirstHeartBeat = 0;
  16852. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16853. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16854. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16855. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16856. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16857. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16858. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16859. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16860. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16861. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16862. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16863. memset(gunType, 0, ARRAY_SIZE(gunType));
  16864. //Status && ConnectorPlugIn Setting
  16865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16866. {
  16867. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16868. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16869. }
  16870. for (int index = 0; index < CCS_QUANTITY; index++)
  16871. {
  16872. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16873. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16874. }
  16875. for (int index = 0; index < GB_QUANTITY; index++)
  16876. {
  16877. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16878. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16879. }
  16880. for (int index = 0; index < AC_QUANTITY; index++)
  16881. {
  16882. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16883. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16884. }
  16885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16886. {
  16887. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16888. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16889. }
  16890. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16891. {
  16892. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16893. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16894. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16895. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16896. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16897. }
  16898. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16899. clientTime.Heartbeat=time((time_t*)NULL);
  16900. sleep(1);
  16901. }
  16902. void LWS_Send(char *str)
  16903. {
  16904. //=====================================================
  16905. // Check InternetConn 0: disconnected, 1: connected
  16906. //====================================================
  16907. if(GetOcppConnStatus() == 0)
  16908. {
  16909. DEBUG_INFO("offline now !!!\n");
  16910. return;
  16911. }
  16912. // Only disable isWebsocketSendable operation initiated by charger
  16913. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16914. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16915. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16916. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16917. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16918. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16919. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16920. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16921. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16922. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16923. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16924. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16925. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16926. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16927. {
  16928. isWebsocketSendable = 0;
  16929. }
  16930. pthread_mutex_lock(&lock_send);
  16931. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16932. sprintf((char *)SendBuffer, "%s", str);
  16933. SendBufLen = strlen(str);
  16934. pthread_mutex_unlock(&lock_send);
  16935. lws_callback_on_writable(wsi_client);
  16936. //lws_service(context, 0);
  16937. //sleep(1);
  16938. }
  16939. void LWS_SendNow(char *str)
  16940. {
  16941. //=====================================================
  16942. // Check InternetConn 0: disconnected, 1: connected
  16943. //====================================================
  16944. if(GetOcppConnStatus() == 0)
  16945. {
  16946. DEBUG_INFO("offline now !!!\n");
  16947. return;
  16948. }
  16949. // Only disable isWebsocketSendable operation initiated by charger
  16950. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16951. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16952. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16953. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16954. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16955. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16956. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16957. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16958. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16959. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16960. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16961. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16962. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16963. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16964. {
  16965. isWebsocketSendable = 0;
  16966. }
  16967. pthread_mutex_lock(&lock_send);
  16968. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16969. sprintf((char *)SendBuffer, "%s", str);
  16970. SendBufLen = strlen(str);
  16971. pthread_mutex_unlock(&lock_send);
  16972. lws_callback_on_writable(wsi_client);
  16973. lws_service(context, 0);
  16974. //sleep(1);
  16975. }