MessageHandler.c 837 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  499. {
  500. tx_buf[64] = (tmStart.tm_year-2000);
  501. tx_buf[65] = tmStart.tm_mon;
  502. tx_buf[66] = tmStart.tm_mday;
  503. tx_buf[67] = tmStart.tm_hour;
  504. tx_buf[68] = tmStart.tm_min;
  505. tx_buf[69] = tmStart.tm_sec;
  506. }
  507. // Stop date time 6 bytes
  508. 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))
  509. {
  510. tx_buf[70] = (tmEnd.tm_year-2000);
  511. tx_buf[71] = tmEnd.tm_mon;
  512. tx_buf[72] = tmEnd.tm_mday;
  513. tx_buf[73] = tmEnd.tm_hour;
  514. tx_buf[74] = tmEnd.tm_min;
  515. tx_buf[75] = tmEnd.tm_sec;
  516. }
  517. // Session energy 2 bytes
  518. tx_buf[76] = PresentChargedEnergy & 0xff;
  519. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  520. // Start SOC 1 byte
  521. tx_buf[78] = socStart;
  522. // Stop SOC 1 byte
  523. tx_buf[79] = socEnd;
  524. // Open socket
  525. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  526. if(udp_socket_fd == -1)
  527. {
  528. DEBUG_ERROR("UDP socket create failed!\n");
  529. }
  530. else
  531. {
  532. // Get server DNS entry
  533. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  534. if (server == NULL)
  535. {
  536. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  537. }
  538. else
  539. {
  540. // Build the server's Internet address
  541. bzero((char *) &dest_addr, sizeof(dest_addr));
  542. dest_addr.sin_family = AF_INET;
  543. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  544. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  545. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  546. {
  547. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  548. {
  549. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  550. }
  551. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  552. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  553. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  554. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  556. DEBUG_TTIA_INFO("---------- Header ----------\n");
  557. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  558. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  559. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  560. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  561. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  562. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  563. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  564. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  565. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  566. DEBUG_TTIA_INFO("Len: 0x3C\n");
  567. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  568. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  569. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  570. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  571. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  572. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  573. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  574. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  575. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  576. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  577. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  578. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  579. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  580. DEBUG_TTIA_INFO("=========================================\n");
  581. sn++;
  582. result = PASS;
  583. }
  584. else
  585. {
  586. DEBUG_ERROR("UDP sent out fail.\n");
  587. }
  588. }
  589. }
  590. return result;
  591. }
  592. //=========================================
  593. // Save configuration
  594. //=========================================
  595. int runShellCmd(const char*cmd)
  596. {
  597. int result = FAIL;
  598. char buf[256];
  599. FILE *fp;
  600. fp = popen(cmd, "r");
  601. if(fp != NULL)
  602. {
  603. while(fgets(buf, sizeof(buf), fp) != NULL)
  604. {
  605. DEBUG_INFO("%s\n", buf);
  606. }
  607. result = PASS;
  608. }
  609. pclose(fp);
  610. return result;
  611. }
  612. int StoreUsrConfigData(struct SysConfigData *UsrData)
  613. {
  614. int result = PASS;
  615. int fd,wrd;
  616. unsigned int i,Chk;
  617. unsigned char *ptr, *BufTmp;
  618. int MtdBlockSize = 0x300000;
  619. Chk=0;
  620. ptr=(unsigned char *)UsrData;
  621. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  622. {
  623. memset(BufTmp,0,MtdBlockSize);
  624. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  625. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  626. Chk+=*(BufTmp+i);
  627. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  628. // Output configuration to file.
  629. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  630. if (fd < 0)
  631. {
  632. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  633. free(BufTmp);
  634. return 0;
  635. }
  636. wrd=write(fd, BufTmp, MtdBlockSize);
  637. close(fd);
  638. if(wrd<MtdBlockSize)
  639. {
  640. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  641. free(BufTmp);
  642. return 0;
  643. }
  644. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  645. DEBUG_INFO("Erase /dev/mtd10.\n");
  646. runShellCmd("flash_erase /dev/mtd10 0 0");
  647. DEBUG_INFO("Write /dev/mtd10.\n");
  648. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  649. DEBUG_INFO("Erase /dev/mtd11.\n");
  650. runShellCmd("flash_erase /dev/mtd11 0 0");
  651. DEBUG_INFO("Write /dev/mtd11.\n");
  652. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  653. system("rm -f /mnt/EvseConfig.bin");
  654. DEBUG_INFO("EvseConfig write to flash OK\n");
  655. }
  656. else
  657. {
  658. DEBUG_ERROR("alloc BlockSize NG\r\n");
  659. result = FAIL;
  660. }
  661. if(BufTmp!=NULL)
  662. free(BufTmp);
  663. return result;
  664. }
  665. //=========================================
  666. // Sqlite3 related function
  667. //=========================================
  668. static int selectSqlCount = 0;
  669. static int callback(void *data, int argc, char **argv, char **azColName){
  670. int i;
  671. //printf("%s: ", (const char*)data);
  672. selectSqlCount = argc;
  673. for(i = 0; i<argc; i++){
  674. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  675. }
  676. //printf("\n");
  677. return 0;
  678. }
  679. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  680. //int i;
  681. //printf("%s:\n", (const char*)data);
  682. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  683. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  684. return 0;
  685. }
  686. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  687. //printf("%s:\n", (const char*)data);
  688. //idTag
  689. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  690. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  691. //parentIdTag
  692. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  693. //expir_date
  694. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  695. //status
  696. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  697. //version
  698. if(columenCount > 5)
  699. idTagQuery.listVersionInt = atoi(columnValue[5]);
  700. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  701. return 0;
  702. }
  703. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  704. {
  705. // localversion = argv[5] ? atoi(argv[5]) : 0;
  706. // printf("localversion=%d\n", localversion);
  707. return 0;
  708. }
  709. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  710. {
  711. for (int i = 0; i < n_columns; i++)
  712. {
  713. DEBUG_INFO("%s\t", col_values[i]);
  714. }
  715. DEBUG_INFO("\n");
  716. return 0;
  717. }
  718. int OCPP_cleanLocalCache()
  719. {
  720. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  721. char *errMsg = 0;
  722. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  723. if (SQLITE_OK != rc)
  724. {
  725. DEBUG_INFO("SQL error: %s\n",errMsg);
  726. return FALSE;
  727. }
  728. return TRUE;
  729. }
  730. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  731. {
  732. int isSuccess = TRUE;
  733. int ret = 0;
  734. //const char* data = "Callback function called";
  735. char sql[300];
  736. char zErrMsg[200];
  737. memset(sql, 0, 300);
  738. memset(zErrMsg, 0, 200);
  739. 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);
  740. //* Execute SQL statement */
  741. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  742. if( ret != SQLITE_OK )
  743. {
  744. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  745. isSuccess = FALSE;
  746. }
  747. return isSuccess;
  748. }
  749. void OCPP_getIdTagFromLocalCache(char idTag[])
  750. {
  751. int rc = 0;
  752. char sql[100];
  753. char zErrMsg[100];
  754. memset(sql, 0, 100);
  755. memset(zErrMsg, 0, 100);
  756. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  757. memset(&idTagQuery, 0, sizeof(idTagQuery));
  758. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  759. /* Execute SQL statement */
  760. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  761. if( rc != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. }
  765. }
  766. void OCPP_getListVerion()
  767. {
  768. int rc = 0;
  769. // const char* data = "Callback function called";
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  775. /* Execute SQL statement */
  776. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  777. if( rc != SQLITE_OK )
  778. {
  779. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  780. }
  781. }
  782. void OCPP_get_TableAuthlocalAllData(void)
  783. {
  784. int rc = 0;
  785. char sql[100];
  786. char zErrMsg[100];
  787. memset(sql, 0, 100);
  788. memset(zErrMsg, 0, 100);
  789. sprintf(sql,"select * from ocpp_auth_local ");
  790. /* Execute SQL statement */
  791. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  792. if( rc != SQLITE_OK )
  793. {
  794. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  795. }
  796. //return ver;
  797. }
  798. int OCPP_cleanLocalList()
  799. {
  800. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  801. char *errMsg = 0;
  802. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  803. if (SQLITE_OK != rc)
  804. {
  805. DEBUG_INFO("%s\n",errMsg);
  806. return FALSE;
  807. }
  808. return TRUE;
  809. }
  810. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  811. {
  812. int isSuccess = FALSE;
  813. int ret = 0;
  814. //const char* data = "Callback function called";
  815. char sql[300];
  816. char zErrMsg[200];
  817. memset(sql, 0, 300);
  818. memset(zErrMsg, 0, 200);
  819. 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);
  820. //* Execute SQL statement */
  821. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  822. if( ret != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. return isSuccess;
  826. }
  827. memset(sql, 0, 300);
  828. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  829. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  830. if( ret != SQLITE_OK )
  831. {
  832. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  833. return isSuccess;
  834. }
  835. isSuccess = TRUE;
  836. return isSuccess;
  837. }
  838. void OCPP_getIdTagFromLocalList(char idTag[])
  839. {
  840. int rc = 0;
  841. // const char* data = "Callback function called";
  842. char sql[100];
  843. char zErrMsg[100];
  844. memset(sql, 0, 100);
  845. memset(zErrMsg, 0, 100);
  846. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  847. memset(&idTagQuery, 0, sizeof(idTagQuery));
  848. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  849. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  850. /* Execute SQL statement */
  851. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  852. if( rc != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. }
  856. //return ver;
  857. }
  858. void OCPP_deleteIdTagFromLocalList(char idTag[])
  859. {
  860. //int ver = 0;
  861. //int isSuccess = FALSE;
  862. int rc = 0;
  863. char sql[100];
  864. char zErrMsg[100];
  865. memset(sql, 0, 100);
  866. memset(zErrMsg, 0, 100);
  867. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  868. //* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. }
  875. int getCurrentYear()
  876. {
  877. int result = 0;
  878. time_t CurrentTime;
  879. struct tm *tm;
  880. CurrentTime = time(NULL);
  881. tm=localtime(&CurrentTime);
  882. result = (tm->tm_year + 1900);
  883. return result;
  884. }
  885. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  886. {
  887. int result = PASS;
  888. char* errMsg = NULL;
  889. char sqlStr[8192];
  890. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  891. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  892. {
  893. result = FAIL;
  894. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  895. }
  896. 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));
  897. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  898. {
  899. result = FAIL;
  900. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  901. }
  902. return result;
  903. }
  904. //==========================================
  905. // Check time passed since today
  906. //==========================================
  907. long long DiffTimebWithNow(struct timeb ST)
  908. {
  909. //return milli-second
  910. struct timeb ET;
  911. long long StartTime,StopTime;
  912. ftime(&ET);
  913. StartTime=(long long)ST.time;
  914. StopTime=(long long)ET.time;
  915. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  916. }
  917. int getTimePassSinceToday(uint8_t gun_index)
  918. {
  919. int result = -1;
  920. static time_t lastTime[4];
  921. time_t t;
  922. struct tm *tmStartToday;
  923. struct timeb tbStartToday;
  924. t=time(NULL);
  925. if(difftime(t, lastTime[gun_index])>0)
  926. {
  927. tmStartToday=localtime(&t);
  928. tmStartToday->tm_hour = 0;
  929. tmStartToday->tm_min = 0;
  930. tmStartToday->tm_sec = 0;
  931. tbStartToday.time = mktime(tmStartToday);
  932. tbStartToday.millitm = 0;
  933. result = DiffTimebWithNow(tbStartToday)/1000;
  934. lastTime[gun_index] = t;
  935. }
  936. return result;
  937. }
  938. void getNowDatetime(uint8_t *data)
  939. {
  940. time_t t = time(NULL);
  941. struct tm tm = *localtime(&t);
  942. 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);
  943. }
  944. int syncDateTimeRTC(uint8_t *data)
  945. {
  946. struct ParsingResult
  947. {
  948. int result;
  949. int scanedElement;
  950. int year;
  951. int month;
  952. int mday;
  953. int hour;
  954. int min;
  955. int sec;
  956. int tz_hour;
  957. int tz_min;
  958. float minSec;
  959. }result;
  960. struct tm tmOrg;
  961. struct tm *tmTarget;
  962. struct timeb tbTarget;
  963. char buf[128];
  964. memset(&result, 0x00, sizeof(struct ParsingResult));
  965. result.result = PASS;
  966. if(strstr((char*)data, ".") != NULL)
  967. {
  968. // Original data with mini second
  969. if(strstr((char*)data, "Z") != NULL)
  970. {
  971. // Original data with Z
  972. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  973. &result.year,
  974. &result.month,
  975. &result.mday,
  976. &result.hour,
  977. &result.min,
  978. &result.sec,
  979. &result.minSec);
  980. }
  981. else
  982. {
  983. // Original data without Z
  984. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  985. &result.year,
  986. &result.month,
  987. &result.mday,
  988. &result.hour,
  989. &result.min,
  990. &result.sec,
  991. &result.minSec,
  992. &result.tz_hour,
  993. &result.tz_min);
  994. }
  995. }
  996. else
  997. {
  998. // Original data without mini second
  999. if(strstr((char*)data, "Z") != NULL)
  1000. {
  1001. // Original data with Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec);
  1009. }
  1010. else
  1011. {
  1012. // Original data without Z
  1013. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1014. &result.year,
  1015. &result.month,
  1016. &result.mday,
  1017. &result.hour,
  1018. &result.min,
  1019. &result.sec,
  1020. &result.tz_hour,
  1021. &result.tz_min);
  1022. }
  1023. }
  1024. tmOrg.tm_year = result.year - 1900;
  1025. tmOrg.tm_mon = result.month - 1;
  1026. tmOrg.tm_mday = result.mday;
  1027. tmOrg.tm_hour = result.hour;
  1028. tmOrg.tm_min = result.min;
  1029. tmOrg.tm_sec = result.sec;
  1030. tmOrg.tm_gmtoff = 0;
  1031. tbTarget.time = mktime(&tmOrg);
  1032. tbTarget.timezone = 0;
  1033. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1034. tmTarget = gmtime(&tbTarget.time);
  1035. 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);
  1036. //DEBUG_INFO(" org date time: %s\n", data);
  1037. //DEBUG_INFO("parse date time: %s\n", buf);
  1038. system(buf);
  1039. system("/sbin/hwclock -w --systohc");
  1040. if(result.scanedElement < 6)
  1041. result.result = FAIL;
  1042. return result.result;
  1043. }
  1044. //==========================================
  1045. // GetCompositeSchedule logic related function
  1046. //==========================================
  1047. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1048. {
  1049. //return milli-second
  1050. unsigned int StartTime,StopTime;
  1051. StartTime=(unsigned int)ST.time;
  1052. StopTime=(unsigned int)ET.time;
  1053. return (StopTime-StartTime);
  1054. }
  1055. int DiffTimebWithNowSec(struct timeb ST)
  1056. {
  1057. //return milli-second
  1058. struct timeb ET;
  1059. unsigned int StartTime,StopTime;
  1060. ftime(&ET);
  1061. StartTime=(unsigned int)ST.time;
  1062. StopTime=(unsigned int)ET.time;
  1063. return (StopTime-StartTime);
  1064. }
  1065. int getStartStop(uint8_t *start, uint8_t *stop)
  1066. {
  1067. int result = -1;
  1068. struct tm tmStart;
  1069. struct timeb tbStart;
  1070. struct tm tmStop;
  1071. struct timeb tbStop;
  1072. 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) &&
  1073. (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))
  1074. {
  1075. //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);
  1076. //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);
  1077. tmStart.tm_year -= 1900;
  1078. tmStart.tm_mon -= 1;
  1079. tbStart.time = mktime(&tmStart);
  1080. tbStart.millitm = 0;
  1081. tmStop.tm_year -= 1900;
  1082. tmStop.tm_mon -= 1;
  1083. tbStop.time = mktime(&tmStop);
  1084. tbStop.millitm = 0;
  1085. result = DiffTimebSec(tbStart, tbStop);
  1086. //DEBUG_INFO("getStartStop(): %d\n", result);
  1087. }
  1088. else
  1089. {
  1090. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1091. }
  1092. return result;
  1093. }
  1094. int isOvertNow(uint8_t *start)
  1095. {
  1096. int result = NO;
  1097. struct tm tmStart;
  1098. struct timeb tbStart;
  1099. 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))
  1100. {
  1101. //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);
  1102. tmStart.tm_year -= 1900;
  1103. tmStart.tm_mon -= 1;
  1104. tbStart.time = mktime(&tmStart);
  1105. tbStart.millitm = 0;
  1106. if(DiffTimebWithNowSec(tbStart) <= 0)
  1107. result = NO;
  1108. else
  1109. result = YES;
  1110. }
  1111. else
  1112. {
  1113. DEBUG_WARN("Start date parsing error.\n");
  1114. }
  1115. return result;
  1116. }
  1117. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1118. {
  1119. int result = -1;
  1120. struct tm tmStart;
  1121. struct timeb tbStart;
  1122. struct tm tmStop;
  1123. struct timeb tbStop;
  1124. 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) &&
  1125. (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))
  1126. {
  1127. tmStart.tm_year -= 1900;
  1128. tmStart.tm_mon -= 1;
  1129. tbStart.time = mktime(&tmStart);
  1130. tbStart.millitm = 0;
  1131. tmStop.tm_year -= 1900;
  1132. tmStop.tm_mon -= 1;
  1133. tbStop.time = mktime(&tmStop);
  1134. tbStop.millitm = 0;
  1135. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1136. }
  1137. return result;
  1138. }
  1139. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1140. {
  1141. FILE *fp;
  1142. char profileFileName[128];
  1143. char *line = NULL;
  1144. size_t len = 0;
  1145. time_t CurrentTime;
  1146. struct tm *tmComposite;
  1147. struct StructChargingProfile maxProfile;
  1148. uint8_t limitMax=0;
  1149. int compositePeriodIdx = 0;
  1150. CurrentTime = time(NULL);
  1151. tmComposite=localtime(&CurrentTime);
  1152. 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);
  1153. if(isUnitA)
  1154. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1155. else
  1156. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1157. compositeProfile->ChargingSchedule.Duration = durationReq;
  1158. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1159. {
  1160. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1161. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1162. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1163. }
  1164. compositeProfile->ChargingProfileId = 0;
  1165. compositeProfile->StackLevel = 99 ;
  1166. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1167. maxProfile.ChargingProfileId = -1;
  1168. maxProfile.ChargingSchedule.Duration = -1;
  1169. system("rm -f /tmp/*.json");
  1170. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1171. // Search max profile
  1172. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1173. if((access(profileFileName, F_OK))!=-1)
  1174. {
  1175. fp = fopen(profileFileName, "r");
  1176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1177. {
  1178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1181. }
  1182. maxProfile.ChargingProfileId = -1;
  1183. maxProfile.StackLevel = -1;
  1184. while(getline(&line, &len, fp) != -1)
  1185. {
  1186. json_object *obj = NULL;
  1187. obj = json_tokener_parse(line);
  1188. if(is_error(obj))
  1189. {
  1190. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1191. }
  1192. else
  1193. {
  1194. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1195. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1196. )
  1197. {
  1198. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1199. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1200. )
  1201. {
  1202. struct tm tmFrom, tmTo;
  1203. struct timeb tbFrom, tbTo;
  1204. 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) &&
  1205. (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))
  1206. {
  1207. tmFrom.tm_year -= 1900;
  1208. tmFrom.tm_mon -= 1;
  1209. tbFrom.time = mktime(&tmFrom);
  1210. tmTo.tm_year -= 1900;
  1211. tmTo.tm_mon -= 1;
  1212. tbTo.time = mktime(&tmTo);
  1213. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1214. {
  1215. if(maxProfile.ChargingProfileId == -1)
  1216. DEBUG_INFO("MaxProfile found.\n");
  1217. else
  1218. DEBUG_INFO("MaxProfile updated.\n");
  1219. // Required item
  1220. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1221. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1222. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1223. if(isUnitA)
  1224. {
  1225. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1226. 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++)
  1227. {
  1228. 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"));
  1229. 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?
  1230. 3:
  1231. 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")));
  1232. 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")));
  1233. }
  1234. }
  1235. else
  1236. {
  1237. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1238. 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++)
  1239. {
  1240. 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"));
  1241. 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?
  1242. 3:
  1243. 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")));
  1244. 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));
  1245. }
  1246. }
  1247. // Optional item
  1248. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1249. {
  1250. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1251. }
  1252. else
  1253. {
  1254. sprintf((char*)maxProfile.ValidFrom, " ");
  1255. }
  1256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1257. {
  1258. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1259. }
  1260. else
  1261. {
  1262. sprintf((char*)maxProfile.ValidTo, " ");
  1263. }
  1264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1265. {
  1266. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1267. }
  1268. else
  1269. {
  1270. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1271. }
  1272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1273. {
  1274. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1275. }
  1276. else
  1277. {
  1278. maxProfile.TransactionId = -1;
  1279. }
  1280. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1281. {
  1282. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1283. }
  1284. else
  1285. {
  1286. maxProfile.ChargingSchedule.Duration = 86400;
  1287. }
  1288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1289. {
  1290. 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")));
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1295. }
  1296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1297. {
  1298. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1299. }
  1300. else
  1301. {
  1302. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1303. }
  1304. }
  1305. }
  1306. }
  1307. else
  1308. {
  1309. if(maxProfile.ChargingProfileId == -1)
  1310. DEBUG_INFO("MaxProfile found.\n");
  1311. else
  1312. DEBUG_INFO("MaxProfile updated.\n");
  1313. // Required item
  1314. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1315. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1316. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1317. if(isUnitA)
  1318. {
  1319. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1320. 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++)
  1321. {
  1322. 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"));
  1323. 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?
  1324. 3:
  1325. 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")));
  1326. 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")));
  1327. }
  1328. }
  1329. else
  1330. {
  1331. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1332. 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++)
  1333. {
  1334. 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"));
  1335. 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?
  1336. 3:
  1337. 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")));
  1338. 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));
  1339. }
  1340. }
  1341. // Optional item
  1342. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1343. {
  1344. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1345. }
  1346. else
  1347. {
  1348. sprintf((char*)maxProfile.ValidFrom, " ");
  1349. }
  1350. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1351. {
  1352. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1353. }
  1354. else
  1355. {
  1356. sprintf((char*)maxProfile.ValidTo, " ");
  1357. }
  1358. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1359. {
  1360. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1361. }
  1362. else
  1363. {
  1364. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1365. }
  1366. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1367. {
  1368. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1369. }
  1370. else
  1371. {
  1372. maxProfile.TransactionId = -1;
  1373. }
  1374. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1375. {
  1376. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1377. }
  1378. else
  1379. {
  1380. maxProfile.ChargingSchedule.Duration = 86400;
  1381. }
  1382. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1383. {
  1384. 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")));
  1385. }
  1386. else
  1387. {
  1388. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1389. }
  1390. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1391. {
  1392. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1393. }
  1394. else
  1395. {
  1396. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1397. }
  1398. }
  1399. }
  1400. }
  1401. json_object_put(obj);
  1402. }
  1403. fclose(fp);
  1404. /*
  1405. if(maxProfile.ChargingProfileId !=-1)
  1406. {
  1407. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1408. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1409. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1410. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1411. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1412. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1413. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1414. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1415. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1416. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1417. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1419. {
  1420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1421. {
  1422. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1423. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1424. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1425. }
  1426. }
  1427. }
  1428. else
  1429. DEBUG_INFO("MaxProfile not found.\n");
  1430. DEBUG_INFO("------------------------------------\n");*/
  1431. }
  1432. if(maxProfile.ChargingProfileId != -1)
  1433. {
  1434. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1435. {
  1436. if(maxProfile.ChargingSchedule.Duration != -1)
  1437. {
  1438. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1439. 0:
  1440. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1441. }
  1442. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1443. {
  1444. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1445. {
  1446. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1447. 0:
  1448. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1449. if(idxPeriod > 0)
  1450. {
  1451. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1452. {
  1453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1460. {
  1461. if(maxProfile.ChargingSchedule.Duration != -1)
  1462. {
  1463. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1464. }
  1465. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1466. {
  1467. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1468. {
  1469. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. else
  1481. {
  1482. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1483. {
  1484. if(maxProfile.ChargingSchedule.Duration != -1)
  1485. {
  1486. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1487. 0:
  1488. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1489. }
  1490. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1491. {
  1492. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1493. {
  1494. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1495. 0:
  1496. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1497. if(idxPeriod > 0)
  1498. {
  1499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1500. {
  1501. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1502. }
  1503. }
  1504. }
  1505. }
  1506. }
  1507. else
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. /*
  1534. DEBUG_INFO("MaxProfile after align.\n");
  1535. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1536. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1537. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1538. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1539. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1540. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1541. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1542. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1543. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1544. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1545. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1549. {
  1550. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1551. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1552. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1553. }
  1554. }
  1555. DEBUG_INFO("------------------------------------\n");*/
  1556. }
  1557. // Find each profile period quantity
  1558. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1559. {
  1560. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1561. limitMax = idx+1;
  1562. }
  1563. if(maxProfile.ChargingProfileId != -1)
  1564. {
  1565. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1566. {
  1567. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1568. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1569. (maxProfile.ChargingSchedule.Duration > 0))
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1572. {
  1573. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1574. compositePeriodIdx++;
  1575. }
  1576. else
  1577. {
  1578. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1579. }
  1580. }
  1581. }
  1582. }
  1583. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1584. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1585. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1586. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1590. {
  1591. compositeProfile->ChargingProfileId = 1;
  1592. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1593. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1594. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1595. }
  1596. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1597. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1598. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1599. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1600. }
  1601. if(line)
  1602. free(line);
  1603. }
  1604. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1605. {
  1606. FILE *fp;
  1607. char profileFileName[128];
  1608. char *line = NULL;
  1609. size_t len = 0;
  1610. time_t CurrentTime;
  1611. struct tm *tmComposite;
  1612. struct StructChargingProfile maxProfile;
  1613. struct StructChargingProfile defaultTxProfile;
  1614. struct StructChargingProfile txProfile;
  1615. struct StructChargingSchedulePeriod tmpPeriod;
  1616. uint8_t limitMax=0;
  1617. uint8_t limitDef=0;
  1618. uint8_t limitTx=0;
  1619. int compositePeriodIdx = 0;
  1620. CurrentTime = time(NULL);
  1621. tmComposite=localtime(&CurrentTime);
  1622. 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);
  1623. if(isUnitA)
  1624. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1625. else
  1626. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1627. compositeProfile->ChargingSchedule.Duration = durationReq;
  1628. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1629. {
  1630. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1631. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1632. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1633. }
  1634. compositeProfile->ChargingProfileId = 0;
  1635. compositeProfile->StackLevel = 99 ;
  1636. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1637. maxProfile.ChargingProfileId = -1;
  1638. defaultTxProfile.ChargingProfileId = -1;
  1639. txProfile.ChargingProfileId = -1;
  1640. maxProfile.ChargingSchedule.Duration = -1;
  1641. defaultTxProfile.ChargingSchedule.Duration = -1;
  1642. txProfile.ChargingSchedule.Duration = -1;
  1643. system("rm -f /tmp/*.json");
  1644. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1645. /*
  1646. * Search valid charging profile
  1647. */
  1648. //DEBUG_INFO("====================================\n");
  1649. // Search tx profile
  1650. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1651. if((access(profileFileName, F_OK))!=-1)
  1652. {
  1653. fp = fopen(profileFileName, "r");
  1654. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1655. {
  1656. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1657. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1658. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1659. }
  1660. txProfile.ChargingProfileId = -1;
  1661. txProfile.StackLevel = -1;
  1662. while(getline(&line, &len, fp) != -1)
  1663. {
  1664. json_object *obj = NULL;
  1665. obj = json_tokener_parse(line);
  1666. if(is_error(obj))
  1667. {
  1668. DEBUG_ERROR("Parse txProfile from file error.\n");
  1669. }
  1670. else
  1671. {
  1672. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1673. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1674. )
  1675. {
  1676. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1677. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1678. )
  1679. {
  1680. struct tm tmFrom, tmTo;
  1681. struct timeb tbFrom, tbTo;
  1682. 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) &&
  1683. (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))
  1684. {
  1685. tmFrom.tm_year -= 1900;
  1686. tmFrom.tm_mon -= 1;
  1687. tbFrom.time = mktime(&tmFrom);
  1688. tmTo.tm_year -= 1900;
  1689. tmTo.tm_mon -= 1;
  1690. tbTo.time = mktime(&tmTo);
  1691. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1692. {
  1693. if(txProfile.ChargingProfileId == -1)
  1694. DEBUG_INFO("TxProfile found.\n");
  1695. else
  1696. DEBUG_INFO("TxProfile updated.\n");
  1697. // Required item
  1698. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1699. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1700. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1701. if(isUnitA)
  1702. {
  1703. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1704. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1705. {
  1706. 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"));
  1707. 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?
  1708. 3:
  1709. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1710. 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")));
  1711. }
  1712. }
  1713. else
  1714. {
  1715. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1716. 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++)
  1717. {
  1718. 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"));
  1719. 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?
  1720. 3:
  1721. 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")));
  1722. 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));
  1723. }
  1724. }
  1725. // Optional item
  1726. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1727. {
  1728. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1729. }
  1730. else
  1731. {
  1732. sprintf((char*)txProfile.ValidFrom, " ");
  1733. }
  1734. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1735. {
  1736. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1737. }
  1738. else
  1739. {
  1740. sprintf((char*)txProfile.ValidTo, " ");
  1741. }
  1742. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1743. {
  1744. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1745. }
  1746. else
  1747. {
  1748. sprintf((char*)txProfile.RecurrencyKind, " ");
  1749. }
  1750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1751. {
  1752. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1753. }
  1754. else
  1755. {
  1756. txProfile.TransactionId = -1;
  1757. }
  1758. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1759. {
  1760. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1761. }
  1762. else
  1763. {
  1764. txProfile.ChargingSchedule.Duration = 86400;
  1765. }
  1766. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1767. {
  1768. 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")));
  1769. }
  1770. else
  1771. {
  1772. 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));
  1773. }
  1774. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1775. {
  1776. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1777. }
  1778. else
  1779. {
  1780. txProfile.ChargingSchedule.MinChargingRate = -1;
  1781. }
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. if(txProfile.ChargingProfileId == -1)
  1788. DEBUG_INFO("TxProfile found.\n");
  1789. else
  1790. DEBUG_INFO("TxProfile updated.\n");
  1791. // Required item
  1792. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1793. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1794. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1795. if(isUnitA)
  1796. {
  1797. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1798. 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++)
  1799. {
  1800. 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"));
  1801. 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?
  1802. 3:
  1803. 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")));
  1804. 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")));
  1805. }
  1806. }
  1807. else
  1808. {
  1809. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1810. 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++)
  1811. {
  1812. 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"));
  1813. 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?
  1814. 3:
  1815. 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")));
  1816. 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));
  1817. }
  1818. }
  1819. // Optional item
  1820. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1821. {
  1822. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1823. }
  1824. else
  1825. {
  1826. sprintf((char*)txProfile.ValidFrom, " ");
  1827. }
  1828. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1829. {
  1830. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1831. }
  1832. else
  1833. {
  1834. sprintf((char*)txProfile.ValidTo, " ");
  1835. }
  1836. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1837. {
  1838. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1839. }
  1840. else
  1841. {
  1842. sprintf((char*)txProfile.RecurrencyKind, " ");
  1843. }
  1844. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1845. {
  1846. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1847. }
  1848. else
  1849. {
  1850. txProfile.TransactionId = -1;
  1851. }
  1852. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1853. {
  1854. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1855. }
  1856. else
  1857. {
  1858. txProfile.ChargingSchedule.Duration = 86400;
  1859. }
  1860. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1861. {
  1862. 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")));
  1863. }
  1864. else
  1865. {
  1866. 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));
  1867. }
  1868. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1869. {
  1870. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1871. }
  1872. else
  1873. {
  1874. txProfile.ChargingSchedule.MinChargingRate = -1;
  1875. }
  1876. }
  1877. }
  1878. }
  1879. json_object_put(obj);
  1880. }
  1881. fclose(fp);
  1882. /*
  1883. if(txProfile.ChargingProfileId != -1)
  1884. {
  1885. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1886. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1887. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1888. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1889. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1890. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1891. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1892. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1893. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1894. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1895. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1896. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1897. {
  1898. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1899. {
  1900. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1901. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1902. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1903. }
  1904. }
  1905. }
  1906. else
  1907. DEBUG_INFO("TxProfile not found.\n");*/
  1908. }
  1909. // Search default tx profile
  1910. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1911. if((access(profileFileName, F_OK))==-1)
  1912. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1913. if((access(profileFileName, F_OK))!=-1)
  1914. {
  1915. fp = fopen(profileFileName, "r");
  1916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1917. {
  1918. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1919. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1921. }
  1922. defaultTxProfile.ChargingProfileId = -1;
  1923. defaultTxProfile.StackLevel = -1;
  1924. while(getline(&line, &len, fp) != -1)
  1925. {
  1926. json_object *obj = NULL;
  1927. obj = json_tokener_parse(line);
  1928. if(is_error(obj))
  1929. {
  1930. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1931. }
  1932. else
  1933. {
  1934. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1935. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1936. )
  1937. {
  1938. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1939. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1940. )
  1941. {
  1942. struct tm tmFrom, tmTo;
  1943. struct timeb tbFrom, tbTo;
  1944. 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) &&
  1945. (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))
  1946. {
  1947. tmFrom.tm_year -= 1900;
  1948. tmFrom.tm_mon -= 1;
  1949. tbFrom.time = mktime(&tmFrom);
  1950. tmTo.tm_year -= 1900;
  1951. tmTo.tm_mon -= 1;
  1952. tbTo.time = mktime(&tmTo);
  1953. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1954. {
  1955. if(defaultTxProfile.ChargingProfileId == -1)
  1956. DEBUG_INFO("TxDefaultProfile found.\n");
  1957. else
  1958. DEBUG_INFO("TxDefaultProfile updated.\n");
  1959. // Required item
  1960. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1961. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1962. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1963. if(isUnitA)
  1964. {
  1965. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1966. 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++)
  1967. {
  1968. 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"));
  1969. 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?
  1970. 3:
  1971. 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")));
  1972. 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")));
  1973. }
  1974. }
  1975. else
  1976. {
  1977. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1978. 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++)
  1979. {
  1980. 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"));
  1981. 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?
  1982. 3:
  1983. 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")));
  1984. 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));
  1985. }
  1986. }
  1987. // Optional item
  1988. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1989. {
  1990. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1991. }
  1992. else
  1993. {
  1994. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1995. }
  1996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1997. {
  1998. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1999. }
  2000. else
  2001. {
  2002. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2003. }
  2004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2005. {
  2006. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2007. }
  2008. else
  2009. {
  2010. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2011. }
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2013. {
  2014. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2015. }
  2016. else
  2017. {
  2018. defaultTxProfile.TransactionId = -1;
  2019. }
  2020. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2021. {
  2022. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2023. }
  2024. else
  2025. {
  2026. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2027. }
  2028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2029. {
  2030. 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")));
  2031. }
  2032. else
  2033. {
  2034. 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));
  2035. }
  2036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2037. {
  2038. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2039. }
  2040. else
  2041. {
  2042. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2043. }
  2044. }
  2045. }
  2046. }
  2047. else
  2048. {
  2049. if(defaultTxProfile.ChargingProfileId == -1)
  2050. DEBUG_INFO("TxDefaultProfile found.\n");
  2051. else
  2052. DEBUG_INFO("TxDefaultProfile updated.\n");
  2053. // Required item
  2054. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2055. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2056. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2057. if(isUnitA)
  2058. {
  2059. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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")));
  2067. }
  2068. }
  2069. else
  2070. {
  2071. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2072. 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++)
  2073. {
  2074. 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"));
  2075. 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?
  2076. 3:
  2077. 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")));
  2078. 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));
  2079. }
  2080. }
  2081. // Optional item
  2082. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2083. {
  2084. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2085. }
  2086. else
  2087. {
  2088. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2089. }
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2091. {
  2092. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2093. }
  2094. else
  2095. {
  2096. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2097. }
  2098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2099. {
  2100. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2105. }
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2107. {
  2108. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2109. }
  2110. else
  2111. {
  2112. defaultTxProfile.TransactionId = -1;
  2113. }
  2114. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2115. {
  2116. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2117. }
  2118. else
  2119. {
  2120. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2121. }
  2122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2123. {
  2124. 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")));
  2125. }
  2126. else
  2127. {
  2128. 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));
  2129. }
  2130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2131. {
  2132. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2133. }
  2134. else
  2135. {
  2136. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2137. }
  2138. }
  2139. }
  2140. }
  2141. json_object_put(obj);
  2142. }
  2143. fclose(fp);
  2144. /*
  2145. if(defaultTxProfile.ChargingProfileId != -1)
  2146. {
  2147. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2148. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2149. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2150. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2151. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2152. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2153. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2154. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2155. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2156. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2157. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2158. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2161. {
  2162. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2163. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2164. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2165. }
  2166. }
  2167. }
  2168. else
  2169. DEBUG_INFO("TxDefaultProfile not found.\n");
  2170. DEBUG_INFO("------------------------------------\n");*/
  2171. }
  2172. // Search max profile
  2173. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2174. if((access(profileFileName, F_OK))!=-1)
  2175. {
  2176. fp = fopen(profileFileName, "r");
  2177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2178. {
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2182. }
  2183. maxProfile.ChargingProfileId = -1;
  2184. maxProfile.StackLevel = -1;
  2185. while(getline(&line, &len, fp) != -1)
  2186. {
  2187. json_object *obj = NULL;
  2188. obj = json_tokener_parse(line);
  2189. if(is_error(obj))
  2190. {
  2191. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2192. }
  2193. else
  2194. {
  2195. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2196. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2197. )
  2198. {
  2199. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2200. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2201. )
  2202. {
  2203. struct tm tmFrom, tmTo;
  2204. struct timeb tbFrom, tbTo;
  2205. 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) &&
  2206. (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))
  2207. {
  2208. tmFrom.tm_year -= 1900;
  2209. tmFrom.tm_mon -= 1;
  2210. tbFrom.time = mktime(&tmFrom);
  2211. tmTo.tm_year -= 1900;
  2212. tmTo.tm_mon -= 1;
  2213. tbTo.time = mktime(&tmTo);
  2214. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2215. {
  2216. if(maxProfile.ChargingProfileId == -1)
  2217. DEBUG_INFO("MaxProfile found.\n");
  2218. else
  2219. DEBUG_INFO("MaxProfile updated.\n");
  2220. // Required item
  2221. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2222. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2223. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2224. if(isUnitA)
  2225. {
  2226. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2227. 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++)
  2228. {
  2229. 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"));
  2230. 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?
  2231. 3:
  2232. 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")));
  2233. 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")));
  2234. }
  2235. }
  2236. else
  2237. {
  2238. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2239. 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++)
  2240. {
  2241. 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"));
  2242. 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?
  2243. 3:
  2244. 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")));
  2245. 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));
  2246. }
  2247. }
  2248. // Optional item
  2249. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2250. {
  2251. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2252. }
  2253. else
  2254. {
  2255. sprintf((char*)maxProfile.ValidFrom, " ");
  2256. }
  2257. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2258. {
  2259. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2260. }
  2261. else
  2262. {
  2263. sprintf((char*)maxProfile.ValidTo, " ");
  2264. }
  2265. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2266. {
  2267. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2268. }
  2269. else
  2270. {
  2271. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2272. }
  2273. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2274. {
  2275. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2276. }
  2277. else
  2278. {
  2279. maxProfile.TransactionId = -1;
  2280. }
  2281. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2282. {
  2283. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2284. }
  2285. else
  2286. {
  2287. maxProfile.ChargingSchedule.Duration = 86400;
  2288. }
  2289. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2290. {
  2291. 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")));
  2292. }
  2293. else
  2294. {
  2295. 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));
  2296. }
  2297. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2298. {
  2299. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2300. }
  2301. else
  2302. {
  2303. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2304. }
  2305. }
  2306. }
  2307. }
  2308. else
  2309. {
  2310. if(maxProfile.ChargingProfileId == -1)
  2311. DEBUG_INFO("MaxProfile found.\n");
  2312. else
  2313. DEBUG_INFO("MaxProfile updated.\n");
  2314. // Required item
  2315. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2316. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2317. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2318. if(isUnitA)
  2319. {
  2320. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2321. 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++)
  2322. {
  2323. 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"));
  2324. 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?
  2325. 3:
  2326. 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")));
  2327. 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")));
  2328. }
  2329. }
  2330. else
  2331. {
  2332. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2333. 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++)
  2334. {
  2335. 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"));
  2336. 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?
  2337. 3:
  2338. 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")));
  2339. 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));
  2340. }
  2341. }
  2342. // Optional item
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2344. {
  2345. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)maxProfile.ValidFrom, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. {
  2353. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2354. }
  2355. else
  2356. {
  2357. sprintf((char*)maxProfile.ValidTo, " ");
  2358. }
  2359. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2360. {
  2361. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2362. }
  2363. else
  2364. {
  2365. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2366. }
  2367. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2368. {
  2369. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2370. }
  2371. else
  2372. {
  2373. maxProfile.TransactionId = -1;
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2376. {
  2377. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2378. }
  2379. else
  2380. {
  2381. maxProfile.ChargingSchedule.Duration = 86400;
  2382. }
  2383. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2384. {
  2385. 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")));
  2386. }
  2387. else
  2388. {
  2389. 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));
  2390. }
  2391. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2392. {
  2393. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2394. }
  2395. else
  2396. {
  2397. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2398. }
  2399. }
  2400. }
  2401. }
  2402. json_object_put(obj);
  2403. }
  2404. fclose(fp);
  2405. /*
  2406. if(maxProfile.ChargingProfileId !=-1)
  2407. {
  2408. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2409. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2410. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2411. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2412. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2413. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2414. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2415. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2416. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2417. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2418. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2420. {
  2421. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2422. {
  2423. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2424. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2425. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2426. }
  2427. }
  2428. }
  2429. else
  2430. DEBUG_INFO("MaxProfile not found.\n");
  2431. DEBUG_INFO("------------------------------------\n");*/
  2432. }
  2433. /*
  2434. * Align found profile start schedule & periods
  2435. */
  2436. //DEBUG_INFO("====================================\n");
  2437. /*
  2438. // For local test usage, force modify found profile start schedule info
  2439. 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);
  2440. 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);
  2441. 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);
  2442. */
  2443. if(txProfile.ChargingProfileId != -1)
  2444. {
  2445. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2446. {
  2447. if(txProfile.ChargingSchedule.Duration != -1)
  2448. {
  2449. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2450. 0:
  2451. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2452. }
  2453. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2454. {
  2455. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2456. {
  2457. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2458. 0:
  2459. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2460. if(idxPeriod > 0)
  2461. {
  2462. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2463. {
  2464. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2465. }
  2466. }
  2467. }
  2468. }
  2469. }
  2470. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2471. {
  2472. if(txProfile.ChargingSchedule.Duration != -1)
  2473. {
  2474. 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?
  2475. 0:
  2476. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2477. }
  2478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2479. {
  2480. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2481. {
  2482. 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?
  2483. 0:
  2484. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2485. if(idxPeriod > 0)
  2486. {
  2487. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2488. {
  2489. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2490. }
  2491. }
  2492. }
  2493. }
  2494. }
  2495. else
  2496. {
  2497. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2498. {
  2499. if(txProfile.ChargingSchedule.Duration != -1)
  2500. {
  2501. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2502. 0:
  2503. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2504. }
  2505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2506. {
  2507. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2508. {
  2509. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2510. 0:
  2511. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2512. if(idxPeriod > 0)
  2513. {
  2514. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2515. {
  2516. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else
  2523. {
  2524. if(txProfile.ChargingSchedule.Duration != -1)
  2525. {
  2526. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2527. 0:
  2528. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2529. }
  2530. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2531. {
  2532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2533. {
  2534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2535. 0:
  2536. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2537. if(idxPeriod > 0)
  2538. {
  2539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2540. {
  2541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2542. }
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. /*
  2549. DEBUG_INFO("txProfile after align.\n");
  2550. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2551. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2552. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2553. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2554. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2555. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2556. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2557. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2558. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2559. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2560. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2562. {
  2563. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2564. {
  2565. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2566. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2567. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2568. }
  2569. }*/
  2570. }
  2571. if(defaultTxProfile.ChargingProfileId != -1)
  2572. {
  2573. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2574. {
  2575. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2576. {
  2577. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2578. 0:
  2579. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2580. }
  2581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2582. {
  2583. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2584. {
  2585. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2586. 0:
  2587. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2588. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2589. {
  2590. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2591. }
  2592. if(idxPeriod > 0)
  2593. {
  2594. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2595. {
  2596. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2603. {
  2604. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2605. {
  2606. 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?
  2607. 0:
  2608. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2609. }
  2610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2611. {
  2612. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2613. {
  2614. 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?
  2615. 0:
  2616. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2618. {
  2619. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2620. }
  2621. if(idxPeriod > 0)
  2622. {
  2623. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2624. {
  2625. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2626. }
  2627. }
  2628. }
  2629. }
  2630. }
  2631. else
  2632. {
  2633. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2634. {
  2635. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2636. {
  2637. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2638. 0:
  2639. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2640. }
  2641. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2642. {
  2643. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2644. {
  2645. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2646. 0:
  2647. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2649. {
  2650. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2651. }
  2652. if(idxPeriod > 0)
  2653. {
  2654. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2655. {
  2656. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. else
  2663. {
  2664. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2665. {
  2666. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2667. 0:
  2668. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2669. }
  2670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2675. 0:
  2676. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2677. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2678. {
  2679. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2680. }
  2681. if(idxPeriod > 0)
  2682. {
  2683. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2684. {
  2685. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. /*
  2693. DEBUG_INFO("defaultTxProfile after align.\n");
  2694. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2695. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2696. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2697. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2698. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2699. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2700. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2701. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2702. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2703. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2704. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2705. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2706. {
  2707. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2708. {
  2709. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2710. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2711. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2712. }
  2713. }
  2714. DEBUG_INFO("------------------------------------\n");*/
  2715. }
  2716. if(maxProfile.ChargingProfileId != -1)
  2717. {
  2718. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2719. {
  2720. if(maxProfile.ChargingSchedule.Duration != -1)
  2721. {
  2722. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2723. 0:
  2724. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2725. }
  2726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2727. {
  2728. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2729. {
  2730. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2731. 0:
  2732. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2733. if(idxPeriod > 0)
  2734. {
  2735. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2736. {
  2737. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2738. }
  2739. }
  2740. }
  2741. }
  2742. }
  2743. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2744. {
  2745. if(maxProfile.ChargingSchedule.Duration != -1)
  2746. {
  2747. 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?
  2748. 0:
  2749. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2750. }
  2751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2752. {
  2753. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2754. {
  2755. 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?
  2756. 0:
  2757. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2758. if(idxPeriod > 0)
  2759. {
  2760. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2761. {
  2762. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. else
  2769. {
  2770. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2771. {
  2772. if(maxProfile.ChargingSchedule.Duration != -1)
  2773. {
  2774. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2777. }
  2778. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2779. {
  2780. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2781. {
  2782. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2783. 0:
  2784. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2785. if(idxPeriod > 0)
  2786. {
  2787. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2788. {
  2789. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2790. }
  2791. }
  2792. }
  2793. }
  2794. }
  2795. else
  2796. {
  2797. if(maxProfile.ChargingSchedule.Duration != -1)
  2798. {
  2799. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2800. 0:
  2801. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2802. }
  2803. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2804. {
  2805. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2806. {
  2807. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2808. 0:
  2809. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2810. if(idxPeriod > 0)
  2811. {
  2812. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2813. {
  2814. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. /*
  2822. DEBUG_INFO("MaxProfile after align.\n");
  2823. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2824. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2825. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2826. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2827. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2828. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2829. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2830. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2831. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2832. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2833. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2834. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2835. {
  2836. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2837. {
  2838. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2839. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2840. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2841. }
  2842. }
  2843. DEBUG_INFO("------------------------------------\n");*/
  2844. }
  2845. /*
  2846. * Merge to conposite schedule
  2847. */
  2848. //DEBUG_INFO("====================================\n");
  2849. // Find each profile period quantity
  2850. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2851. {
  2852. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2853. limitMax = idx+1;
  2854. }
  2855. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2856. {
  2857. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2858. limitDef = idx+1;
  2859. }
  2860. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2861. {
  2862. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2863. limitTx = idx+1;
  2864. }
  2865. // TxProfile found, composite schedule based on it
  2866. if(txProfile.ChargingProfileId != -1)
  2867. {
  2868. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2869. {
  2870. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2871. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2872. (txProfile.ChargingSchedule.Duration > 0))
  2873. {
  2874. if(maxProfile.ChargingProfileId != -1)
  2875. {
  2876. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2877. {
  2878. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2879. {
  2880. if((maxProfile.ChargingSchedule.Duration > 0))
  2881. {
  2882. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2883. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2884. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2885. }
  2886. else
  2887. {
  2888. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2889. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2890. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2891. }
  2892. }
  2893. if(idxMaxPeriod == (limitMax-1))
  2894. {
  2895. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2896. {
  2897. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2898. {
  2899. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2900. compositePeriodIdx++;
  2901. }
  2902. else
  2903. {
  2904. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. else
  2911. {
  2912. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2913. {
  2914. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2915. compositePeriodIdx++;
  2916. }
  2917. else
  2918. {
  2919. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2920. }
  2921. }
  2922. }
  2923. if(idxTxPeriod == (limitTx-1))
  2924. {
  2925. if(defaultTxProfile.ChargingProfileId != -1)
  2926. {
  2927. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2928. {
  2929. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2930. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2931. (defaultTxProfile.ChargingSchedule.Duration>0))
  2932. {
  2933. if(maxProfile.ChargingProfileId != -1)
  2934. {
  2935. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2936. {
  2937. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2938. {
  2939. if((maxProfile.ChargingSchedule.Duration > 0))
  2940. {
  2941. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2942. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2943. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2944. }
  2945. else
  2946. {
  2947. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2948. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2949. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2950. }
  2951. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2952. {
  2953. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2954. {
  2955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2956. compositePeriodIdx++;
  2957. }
  2958. else
  2959. {
  2960. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2961. }
  2962. }
  2963. // Delete duplicate period
  2964. if(compositePeriodIdx > 1)
  2965. {
  2966. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2967. {
  2968. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2969. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2970. compositePeriodIdx -= 1;
  2971. }
  2972. }
  2973. }
  2974. else
  2975. break;
  2976. }
  2977. }
  2978. else
  2979. {
  2980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2983. compositePeriodIdx++;
  2984. }
  2985. else
  2986. {
  2987. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. }
  2995. }
  2996. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2997. else if(defaultTxProfile.ChargingProfileId != -1)
  2998. {
  2999. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3000. {
  3001. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3002. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3003. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3004. {
  3005. if(maxProfile.ChargingProfileId != -1)
  3006. {
  3007. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3008. {
  3009. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3010. {
  3011. if((maxProfile.ChargingSchedule.Duration > 0))
  3012. {
  3013. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3014. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3015. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3016. }
  3017. else
  3018. {
  3019. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3020. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3021. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3022. }
  3023. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3024. {
  3025. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3026. {
  3027. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3028. compositePeriodIdx++;
  3029. }
  3030. else
  3031. {
  3032. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3033. }
  3034. }
  3035. // Delete duplicate period
  3036. if(compositePeriodIdx > 1)
  3037. {
  3038. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3039. {
  3040. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3041. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3042. compositePeriodIdx -= 1;
  3043. }
  3044. }
  3045. }
  3046. else
  3047. break;
  3048. }
  3049. }
  3050. else
  3051. {
  3052. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3053. {
  3054. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3055. compositePeriodIdx++;
  3056. }
  3057. else
  3058. {
  3059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3060. }
  3061. }
  3062. }
  3063. }
  3064. }
  3065. // Fill other period by MaxProfile
  3066. if(maxProfile.ChargingProfileId != -1)
  3067. {
  3068. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3069. {
  3070. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3071. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3072. (maxProfile.ChargingSchedule.Duration > 0))
  3073. {
  3074. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3075. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3076. {
  3077. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3078. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3079. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3080. }
  3081. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3082. {
  3083. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3084. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3085. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3086. }
  3087. if(tmpPeriod.Limit != -1)
  3088. {
  3089. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3090. {
  3091. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3092. {
  3093. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3094. compositePeriodIdx++;
  3095. }
  3096. else
  3097. {
  3098. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3099. }
  3100. }
  3101. // Delete duplicate period
  3102. if(compositePeriodIdx > 1)
  3103. {
  3104. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3105. {
  3106. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3107. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3108. compositePeriodIdx -= 1;
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }
  3114. }
  3115. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3116. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3117. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3118. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3120. {
  3121. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3122. {
  3123. compositeProfile->ChargingProfileId = 1;
  3124. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3125. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3126. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3127. }
  3128. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3129. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3130. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3131. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3132. }
  3133. if(line)
  3134. free(line);
  3135. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3136. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3137. }
  3138. //==========================================
  3139. // Init all share memory
  3140. //==========================================
  3141. int InitShareMemory()
  3142. {
  3143. int result = PASS;
  3144. int MeterSMId;
  3145. //creat ShmSysConfigAndInfo
  3146. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3147. {
  3148. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3149. result = FAIL;
  3150. }
  3151. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3152. {
  3153. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3154. result = FAIL;
  3155. }
  3156. else
  3157. {}
  3158. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3159. {
  3160. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3161. result = FAIL;
  3162. }
  3163. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3164. {
  3165. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3166. result = FAIL;
  3167. }
  3168. else
  3169. {}
  3170. //creat ShmPsuData
  3171. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3172. {
  3173. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3174. result = FAIL;
  3175. }
  3176. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3177. {
  3178. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3179. result = FAIL;
  3180. }
  3181. else
  3182. {}
  3183. //creat ShmOCPP16Data
  3184. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3185. {
  3186. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3187. result = FAIL;
  3188. }
  3189. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3190. {
  3191. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3192. result = FAIL;
  3193. }
  3194. else
  3195. {}
  3196. /****************************** For Initial Settings************************************************/
  3197. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3198. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3199. // allocate Configuration memory address
  3200. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3201. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3202. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3203. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3204. //offline MeterValue Interval
  3205. TempMeterValueInterval = 0;
  3206. return result;
  3207. }
  3208. int ProcessShareMemory()
  3209. {
  3210. if(InitShareMemory() == FAIL)
  3211. {
  3212. DEBUG_ERROR("InitShareMemory NG\n");
  3213. if(ShmStatusCodeData!=NULL)
  3214. {
  3215. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3216. }
  3217. sleep(5);
  3218. return FAIL;
  3219. }
  3220. return PASS;
  3221. }
  3222. void CheckSystemValue(void)
  3223. {
  3224. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3225. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3226. char filenmae[100]={0};
  3227. char str[100]={0};
  3228. int tempIndex = 0;
  3229. //===============================
  3230. // send Heartbeat
  3231. //===============================
  3232. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3233. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3234. {
  3235. clientTime.Heartbeat=time((time_t*)NULL);
  3236. if(server_sign == TRUE)
  3237. {
  3238. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3239. }
  3240. else
  3241. {
  3242. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3243. }
  3244. }
  3245. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3246. {
  3247. //parameter for test
  3248. sendHeartbeatRequest(0);
  3249. //==============================================
  3250. // Reset Waiting Time
  3251. //==============================================
  3252. HeartBeatWithNOResponse += 1;
  3253. }
  3254. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3255. {
  3256. //==========================================
  3257. // csu trigger DataTransferReq
  3258. //==========================================
  3259. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3260. {
  3261. sendDataTransferRequest(gun_index);
  3262. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3263. }
  3264. //===============================
  3265. // CSU Trigger Authorize Request
  3266. //===============================
  3267. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3268. {
  3269. sendAuthorizeRequest(0);
  3270. authorizeRetryTimes = authorizeRetryTimes + 1;
  3271. if(authorizeRetryTimes < 3)
  3272. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3273. }
  3274. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3275. {
  3276. authorizeRetryTimes = 0;
  3277. SetOcppConnStatus(FALSE);
  3278. server_sign = FALSE;
  3279. }
  3280. 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))
  3281. {
  3282. sendAuthorizeRequest(0);
  3283. }
  3284. //==============================================
  3285. // Charger start transaction
  3286. //==============================================
  3287. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3288. {
  3289. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3290. sendStartTransactionRequest(gun_index);
  3291. clientTime.StartTransaction = time((time_t*)NULL);
  3292. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3293. storeTempStopTransaction(gun_index);
  3294. }
  3295. //==============================================
  3296. // Charger stop transaction
  3297. //==============================================
  3298. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3299. {
  3300. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3301. sendStopTransactionRequest(gun_index);
  3302. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3303. clientTime.StopTransaction = time((time_t*)NULL);
  3304. }
  3305. //==============================================
  3306. // Charger status report
  3307. //==============================================
  3308. //--- Check Mode Change ---//
  3309. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3310. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3311. {
  3312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3313. {
  3314. tempIndex = ((gun_index==2) ? 1: 0);
  3315. }
  3316. else
  3317. {
  3318. tempIndex = gun_index;
  3319. }
  3320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3321. {
  3322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3323. {
  3324. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3325. {
  3326. // Sent unplug message for California pricing logic
  3327. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3328. {
  3329. uint8_t ts[20];
  3330. getNowDatetime(ts);
  3331. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3332. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3333. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3334. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3335. }
  3336. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3337. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3338. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3339. }
  3340. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3341. {
  3342. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3343. if((access(filenmae,F_OK))!=-1)
  3344. {
  3345. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3346. sprintf(str,"rm -f %s",filenmae);
  3347. system(str);
  3348. }
  3349. }
  3350. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3351. #if 1 // for TempStopTransaction
  3352. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3353. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3354. {
  3355. checkTempStopTransaction(gun_index);
  3356. }
  3357. #endif
  3358. }
  3359. }
  3360. }
  3361. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3362. {
  3363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3364. {
  3365. tempIndex = ((gun_index==2) ? 1: 0);
  3366. }
  3367. else
  3368. {
  3369. tempIndex = gun_index;
  3370. }
  3371. for (int index = 0; index < CCS_QUANTITY; index++)
  3372. {
  3373. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3374. {
  3375. 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]*/ )
  3376. {
  3377. // Sent unplug message for California pricing logic
  3378. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3379. {
  3380. uint8_t ts[20];
  3381. getNowDatetime(ts);
  3382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3384. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3385. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3386. }
  3387. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3388. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3389. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3390. }
  3391. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3392. {
  3393. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3394. if((access(filenmae,F_OK))!=-1)
  3395. {
  3396. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3397. sprintf(str,"rm -f %s",filenmae);
  3398. system(str);
  3399. }
  3400. }
  3401. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3402. #if 1 // for TempStopTransaction
  3403. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3404. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3405. {
  3406. checkTempStopTransaction(gun_index);
  3407. }
  3408. #endif
  3409. }
  3410. }
  3411. }
  3412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3413. {
  3414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3415. {
  3416. tempIndex = ((gun_index==2) ? 1: 0);
  3417. }
  3418. else
  3419. {
  3420. tempIndex = gun_index;
  3421. }
  3422. for (int index = 0; index < GB_QUANTITY; index++)
  3423. {
  3424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3425. {
  3426. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3427. {
  3428. // Sent unplug message for California pricing logic
  3429. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3430. {
  3431. uint8_t ts[20];
  3432. getNowDatetime(ts);
  3433. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3434. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3435. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3436. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3437. }
  3438. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3439. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3440. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3441. }
  3442. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3443. {
  3444. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3445. if((access(filenmae,F_OK))!=-1)
  3446. {
  3447. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3448. sprintf(str,"rm -f %s",filenmae);
  3449. system(str);
  3450. }
  3451. }
  3452. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3453. #if 1 // for TempStopTransaction
  3454. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3455. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3456. {
  3457. checkTempStopTransaction(gun_index);
  3458. }
  3459. #endif
  3460. }
  3461. }
  3462. }
  3463. else if(gunType[gun_index] == GUN_TYPE_DO)
  3464. {
  3465. tempIndex = gun_index;
  3466. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3469. {
  3470. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3471. {
  3472. // Sent unplug message for California pricing logic
  3473. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3474. {
  3475. uint8_t ts[20];
  3476. getNowDatetime(ts);
  3477. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3478. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3480. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3481. }
  3482. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3483. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3484. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3485. }
  3486. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  3487. {
  3488. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3489. if((access(filenmae,F_OK))!=-1)
  3490. {
  3491. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3492. sprintf(str,"rm -f %s",filenmae);
  3493. system(str);
  3494. }
  3495. }
  3496. 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);
  3497. #if 1 // for TempStopTransaction
  3498. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3499. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3500. {
  3501. checkTempStopTransaction(gun_index);
  3502. }
  3503. #endif
  3504. }
  3505. }
  3506. }
  3507. else
  3508. {
  3509. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3510. {
  3511. tempIndex = 2;
  3512. }
  3513. else
  3514. {
  3515. tempIndex = gun_index;
  3516. }
  3517. for (int index = 0; index < AC_QUANTITY; index++)
  3518. {
  3519. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3520. {
  3521. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3522. {
  3523. // Sent unplug message for California pricing logic
  3524. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3525. {
  3526. uint8_t ts[20];
  3527. getNowDatetime(ts);
  3528. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3531. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3532. }
  3533. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3534. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3535. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3536. }
  3537. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3538. {
  3539. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3540. if((access(filenmae,F_OK))!=-1)
  3541. {
  3542. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3543. sprintf(str,"rm -f %s",filenmae);
  3544. system(str);
  3545. }
  3546. }
  3547. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3548. #if 1 // for TempStopTransaction
  3549. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3550. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3551. {
  3552. checkTempStopTransaction(gun_index);
  3553. }
  3554. #endif
  3555. }
  3556. }// END
  3557. }
  3558. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3559. (
  3560. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3561. )
  3562. )
  3563. {
  3564. if(SystemInitial > 0)
  3565. SystemInitial -= 1;
  3566. sendStatusNotificationRequest(gun_index);
  3567. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3568. }
  3569. //==============================================
  3570. // CSU Trigger Smart Charging Profilw
  3571. //==============================================
  3572. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3573. {
  3574. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3575. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3576. }
  3577. //==============================================
  3578. // Meter report
  3579. //==============================================
  3580. // Trigger MeterValue
  3581. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3582. {
  3583. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3584. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3585. }
  3586. // ClockAlign MeterValue
  3587. 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))
  3588. {
  3589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3600. {
  3601. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3603. {
  3604. reqClockAlignMeter[gun_index] = 1;
  3605. }
  3606. }// End for CHAdeMO
  3607. }
  3608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((gun_index==2) ? 1: 0);
  3613. }
  3614. else
  3615. {
  3616. tempIndex = gun_index;
  3617. }
  3618. for (int index = 0; index < CCS_QUANTITY; index++)
  3619. {
  3620. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3621. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3622. {
  3623. reqClockAlignMeter[gun_index] = 1;
  3624. }
  3625. } // End for CCS
  3626. }
  3627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3628. {
  3629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3630. {
  3631. tempIndex = ((gun_index==2) ? 1: 0);
  3632. }
  3633. else
  3634. {
  3635. tempIndex = gun_index;
  3636. }
  3637. for (int index = 0; index < GB_QUANTITY; index++)
  3638. {
  3639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3641. {
  3642. reqClockAlignMeter[gun_index] = 1;
  3643. }
  3644. }// End for GB
  3645. }
  3646. else if(gunType[gun_index] == GUN_TYPE_DO)
  3647. {
  3648. tempIndex = gun_index;
  3649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. }
  3657. }
  3658. else
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3661. {
  3662. tempIndex = 2;
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < AC_QUANTITY; index++)
  3669. {
  3670. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3671. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3672. {
  3673. reqClockAlignMeter[gun_index] = 1;
  3674. }
  3675. }//End for AC
  3676. }
  3677. if(reqClockAlignMeter[gun_index] == 1)
  3678. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3679. }
  3680. // Sample period MeterValue
  3681. 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))))
  3682. {
  3683. //check Transaction active
  3684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3695. {
  3696. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3697. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3698. {
  3699. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3700. {
  3701. reqSampleMeter[gun_index] = 1;
  3702. }
  3703. }
  3704. }// End for CHAdeMO
  3705. }
  3706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3707. {
  3708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3709. {
  3710. tempIndex = ((gun_index==2) ? 1: 0);
  3711. }
  3712. else
  3713. {
  3714. tempIndex = gun_index;
  3715. }
  3716. for (int index = 0; index < CCS_QUANTITY; index++)
  3717. {
  3718. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3719. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3722. {
  3723. reqSampleMeter[gun_index] = 1;
  3724. }
  3725. }
  3726. } // End for CCS
  3727. }
  3728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3729. {
  3730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3731. {
  3732. tempIndex = ((gun_index==2) ? 1: 0);
  3733. }
  3734. else
  3735. {
  3736. tempIndex = gun_index;
  3737. }
  3738. for (int index = 0; index < GB_QUANTITY; index++)
  3739. {
  3740. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3741. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3742. {
  3743. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3744. {
  3745. reqSampleMeter[gun_index] = 1;
  3746. }
  3747. }
  3748. }// End for GB
  3749. }
  3750. else if(gunType[gun_index] == GUN_TYPE_DO)
  3751. {
  3752. tempIndex = gun_index;
  3753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3754. {
  3755. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3756. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3757. {
  3758. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3759. {
  3760. reqSampleMeter[gun_index] = 1;
  3761. }
  3762. }
  3763. }
  3764. }
  3765. else
  3766. {
  3767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3768. {
  3769. tempIndex = 2;
  3770. }
  3771. else
  3772. {
  3773. tempIndex = gun_index;
  3774. }
  3775. for (int index = 0; index < AC_QUANTITY; index++)
  3776. {
  3777. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3778. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3779. {
  3780. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3781. {
  3782. reqSampleMeter[gun_index] = 1;
  3783. }
  3784. }
  3785. }//End for AC
  3786. }
  3787. if(reqSampleMeter[gun_index] == 1)
  3788. {
  3789. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3790. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3791. storeTempStopTransaction(gun_index);
  3792. }
  3793. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3794. }
  3795. //==============================================
  3796. // Check Connector reserved
  3797. //==============================================
  3798. //===============================
  3799. // Check if Reserve is expired
  3800. //===============================
  3801. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3802. {
  3803. double diff_t;
  3804. struct tm tp;
  3805. // current time
  3806. time_t t = time(NULL);
  3807. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3808. tp.tm_isdst = -1;
  3809. time_t utc = mktime(&tp);
  3810. diff_t = difftime(utc, t);
  3811. if(diff_t <= 0)
  3812. {
  3813. DEBUG_INFO("reserve expired.\n");
  3814. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3815. }
  3816. }//END OF Check if Reserve is expired
  3817. //==========================================
  3818. // csu trigger FirmwareStatusNotificationReq
  3819. //==========================================
  3820. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3821. {
  3822. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3823. }
  3824. //==========================================
  3825. // csu trigger DiagnosticsStatusNotificationReq
  3826. //==========================================
  3827. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3828. {
  3829. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3830. }
  3831. //==========================================
  3832. // csu trigger CancelReservationConf
  3833. //==========================================
  3834. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3835. {
  3836. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3837. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3838. }
  3839. //==========================================
  3840. // csu trigger ChangeAvailabilityConf
  3841. //==========================================
  3842. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3843. {
  3844. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3845. }
  3846. //==========================================
  3847. // csu trigger UnlockConnectorConf
  3848. //==========================================
  3849. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3850. {
  3851. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3852. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3853. }
  3854. //==========================================
  3855. // csu trigger ReserveNowConf
  3856. //==========================================
  3857. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3858. {
  3859. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3860. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3861. }
  3862. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3863. {
  3864. sendSignCertificateRequest();
  3865. }
  3866. }
  3867. }
  3868. //==========================================
  3869. // send request routine
  3870. //==========================================
  3871. int sendAuthorizeRequest(int gun_index)
  3872. {
  3873. mtrace();
  3874. int result = FAIL;
  3875. char message[100]={0};
  3876. char guid[37];
  3877. char tempdata[65]={0};
  3878. DEBUG_INFO("sendAuthorizeRequest...\n");
  3879. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3880. //Local Authorize
  3881. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3882. {
  3883. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3884. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3885. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3886. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3887. result = PASS;
  3888. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3889. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3890. authorizeRetryTimes = 0;
  3891. return result;
  3892. }
  3893. 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))||
  3894. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3895. {
  3896. // Query from cache
  3897. DEBUG_INFO("Authorize from cache.\n");
  3898. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3899. // Query from list
  3900. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3901. {
  3902. DEBUG_INFO("Authorize from list.\n");
  3903. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3904. }
  3905. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3906. {
  3907. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3908. {
  3909. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3910. }
  3911. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3912. {
  3913. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3914. }
  3915. if(!GetOcppConnStatus())
  3916. {
  3917. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3918. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3919. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3920. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3921. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3922. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3923. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3924. authorizeRetryTimes = 0;
  3925. return result;
  3926. }
  3927. }
  3928. else
  3929. {
  3930. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3931. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3932. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3933. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3934. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3935. else
  3936. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3937. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3938. result = PASS;
  3939. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3940. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3941. authorizeRetryTimes = 0;
  3942. return result;
  3943. }
  3944. }
  3945. //initialize struct Authorize
  3946. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3947. //get data from shared memory
  3948. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3949. random_uuid(guid);
  3950. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3951. LWS_Send(message);
  3952. sprintf(tempdata, "Authorize,%d", gun_index);
  3953. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3954. {
  3955. result = PASS;
  3956. DEBUG_INFO("Authorize mapItem pass\n");
  3957. }
  3958. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3959. return result;
  3960. }
  3961. int sendBootNotificationRequest(void)
  3962. {
  3963. mtrace();
  3964. int result = FAIL;
  3965. char message[500]={0}, payload[700]={0};
  3966. char guid[37]={0};
  3967. char tempdata[65]={0};
  3968. // Fill BootNotification fields
  3969. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3970. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3971. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3972. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3973. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3974. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3975. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3976. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3977. ShmOCPP16Data->ChargeBoxId
  3978. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3979. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3980. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3981. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3982. ,ShmOCPP16Data->BootNotification.CpIccid
  3983. ,ShmOCPP16Data->BootNotification.CpImsi);
  3984. random_uuid(guid);
  3985. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3986. LWS_Send(message);
  3987. sprintf(tempdata, "BootNotification,0");
  3988. 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*/)
  3989. {
  3990. result = PASS;
  3991. }
  3992. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3993. strcpy(queuedata,message);
  3994. return result;
  3995. }
  3996. int sendDataTransferRequest(int gun_index)
  3997. {
  3998. mtrace();
  3999. char message[1000]={0};
  4000. char guid[37]={0};
  4001. char tempdata[65]={0};
  4002. int result = FAIL;
  4003. random_uuid(guid);
  4004. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4005. MESSAGE_TYPE_CALL,
  4006. guid,
  4007. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4008. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4009. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4010. LWS_Send(message);
  4011. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4012. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4013. {
  4014. result = PASS;
  4015. DEBUG_INFO("DataTransfer mapItem pass\n");
  4016. }
  4017. return result;
  4018. }
  4019. int sendDiagnosticsStatusNotificationRequest(char *status)
  4020. {
  4021. mtrace();
  4022. int result = FAIL;
  4023. char message[110]={0};
  4024. char guid[37]={0};
  4025. char tempdata[65]={0};
  4026. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4027. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4028. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4029. random_uuid(guid);
  4030. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4031. LWS_SendNow(message);
  4032. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4033. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4034. {
  4035. result = PASS;
  4036. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4037. }
  4038. //#ifdef SystemLogMessage
  4039. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4040. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4041. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4042. //#endif
  4043. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4044. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4045. //record status
  4046. if(strcmp(status,"Idle")==0)
  4047. {
  4048. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4049. }
  4050. else if(strcmp(status,"Uploaded")==0)
  4051. {
  4052. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4053. }
  4054. else if(strcmp(status,"UploadFailed")==0)
  4055. {
  4056. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4057. }
  4058. else if(strcmp(status,"Uploading")==0)
  4059. {
  4060. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4061. }
  4062. return result;
  4063. }
  4064. int sendFirmwareStatusNotificationRequest(char *status)
  4065. {
  4066. mtrace();
  4067. int result = FAIL;
  4068. char message[110]={0};
  4069. char guid[37]={0};
  4070. char tempdata[65]={0};
  4071. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4072. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4073. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4074. random_uuid(guid);
  4075. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4076. LWS_SendNow(message);
  4077. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4078. 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*/)
  4079. {
  4080. result = PASS;
  4081. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4082. }
  4083. //#ifdef SystemLogMessage
  4084. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4085. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4086. //#endif
  4087. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4088. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4089. //record status
  4090. if(strcmp(status,"Downloaded")==0)
  4091. {
  4092. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4093. }
  4094. else if(strcmp(status,"DownloadFailed")==0)
  4095. {
  4096. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4097. }
  4098. else if(strcmp(status,"Downloading")==0)
  4099. {
  4100. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4101. }
  4102. else if(strcmp(status,"Idle")==0)
  4103. {
  4104. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4105. }
  4106. else if(strcmp(status,"InstallationFailed")==0)
  4107. {
  4108. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4109. }
  4110. else if(strcmp(status,"Installing")==0)
  4111. {
  4112. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4113. }
  4114. else if(strcmp(status,"Installed")==0)
  4115. {
  4116. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4117. }
  4118. return result;
  4119. }
  4120. int sendHeartbeatRequest(int gun_index)
  4121. {
  4122. mtrace();
  4123. int result = FAIL;
  4124. char message[80]={0};
  4125. char guid[37]={0};
  4126. char tempdata[65]={0};
  4127. random_uuid(guid);
  4128. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4129. , MESSAGE_TYPE_CALL
  4130. , guid );
  4131. LWS_Send(message);
  4132. sprintf(tempdata, "Heartbeat,%d", 0);
  4133. 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*/)
  4134. {
  4135. result = PASS;
  4136. }
  4137. return result;
  4138. }
  4139. int sendStartTransactionRequest(int gun_index)
  4140. {
  4141. mtrace();
  4142. int result = FAIL;
  4143. char message[250]={0};
  4144. char guid[37]={0};
  4145. struct timeval tmnow;
  4146. struct tm *tm;
  4147. char buf[28];//, usec_buf[6];
  4148. char tempdata[65]={0};
  4149. int tempIndex = 0;
  4150. DEBUG_INFO("sendStartTransactionRequest...\n");
  4151. gettimeofday(&tmnow, NULL);
  4152. time_t t;
  4153. t = time(NULL);
  4154. /*UTC time and date*/
  4155. tm = gmtime(&t);
  4156. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4157. #if 0 // remove temporally
  4158. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4159. strcat(buf,".");
  4160. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4161. strcat(buf,usec_buf);
  4162. #endif
  4163. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4164. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4165. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4166. // clear StartTransaction Response
  4167. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4168. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4169. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4170. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4171. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4172. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4173. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4176. {
  4177. tempIndex = ((gun_index==2) ? 1: 0);
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4186. {
  4187. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4188. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4189. }
  4190. }
  4191. }
  4192. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4193. {
  4194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4195. {
  4196. tempIndex = ((gun_index==2) ? 1: 0);
  4197. }
  4198. else
  4199. {
  4200. tempIndex = gun_index;
  4201. }
  4202. for (int index = 0; index < CCS_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4205. {
  4206. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4207. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4208. }
  4209. }
  4210. }
  4211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4212. {
  4213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4214. {
  4215. tempIndex = ((gun_index==2) ? 1: 0);
  4216. }
  4217. else
  4218. {
  4219. tempIndex = gun_index;
  4220. }
  4221. for (int index = 0; index < GB_QUANTITY; index++)
  4222. {
  4223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4224. {
  4225. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4226. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4227. }
  4228. }
  4229. }
  4230. else if(gunType[gun_index] == GUN_TYPE_DO)
  4231. {
  4232. tempIndex = gun_index;
  4233. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4236. {
  4237. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4238. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4239. }
  4240. }
  4241. }
  4242. else
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4245. {
  4246. tempIndex = 2;
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < AC_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4255. {
  4256. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4257. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4258. }
  4259. }
  4260. }
  4261. random_uuid(guid);
  4262. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4263. {
  4264. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4265. , gun_index +1
  4266. , MESSAGE_TYPE_CALL
  4267. , guid
  4268. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4269. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4270. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4271. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4272. }
  4273. else
  4274. {
  4275. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4276. , gun_index +1
  4277. , MESSAGE_TYPE_CALL
  4278. , guid
  4279. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4280. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4281. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4282. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4283. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4284. }
  4285. #if 1
  4286. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4287. 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*/)
  4288. {
  4289. result = PASS;
  4290. }
  4291. #endif
  4292. strcpy(queuedata, message);
  4293. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4294. OCPP_insert_transaction_msg(YES, queuedata);
  4295. return result;
  4296. }
  4297. int sendStatusNotificationRequest(int gun_index)
  4298. {
  4299. mtrace();
  4300. int result = FAIL;
  4301. char message[600]={0};
  4302. char guid[37];
  4303. int currentStatus = 0;
  4304. struct timeval tmnow;
  4305. struct tm *tm;
  4306. char buf[28];//, usec_buf[6];
  4307. char tempdata[65]={0};
  4308. int tempIndex = 0;
  4309. uint8_t isStateChanged = TRUE;
  4310. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4311. gettimeofday(&tmnow, NULL);
  4312. time_t t;
  4313. t = time(NULL);
  4314. /*UTC time and date*/
  4315. tm = gmtime(&t);
  4316. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4317. #if 0 // remove temporally
  4318. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4319. strcat(buf,".");
  4320. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4321. strcat(buf,usec_buf);
  4322. #endif
  4323. //printf("%s",buf);
  4324. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4325. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4326. // it's option
  4327. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4328. /*
  4329. enum _SYSTEM_STATUS
  4330. {
  4331. S_BOOTING = 0,
  4332. S_IDLE, = 1
  4333. S_AUTHORIZING, =2
  4334. S_REASSIGN_CHECK, =3
  4335. S_REASSIGN, =4
  4336. S_PRECHARGE, =5
  4337. S_PREPARING_FOR_EV, =6
  4338. S_PREPARING_FOR_EVSE, =7
  4339. S_CHARGING, =8
  4340. S_TERMINATING, =9
  4341. S_COMPLETE, =10
  4342. S_ALARM, =11
  4343. S_FAULT =12
  4344. }
  4345. */
  4346. //check Transaction active
  4347. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4348. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4349. {
  4350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4351. {
  4352. tempIndex = ((gun_index==2) ? 1: 0);
  4353. }
  4354. else
  4355. {
  4356. tempIndex = gun_index;
  4357. }
  4358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4359. {
  4360. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4361. {
  4362. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4363. {
  4364. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4365. {
  4366. currentStatus = Preparing; //OCPP Status: Preparing
  4367. }
  4368. else
  4369. {
  4370. currentStatus = Available; //OCPP Status: Available
  4371. }
  4372. }
  4373. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4374. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4375. ) //S_PRECHARGE
  4376. {
  4377. currentStatus = Preparing; //OCPP Status: Preparing
  4378. }
  4379. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4380. {
  4381. currentStatus = Charging; //OCPP Status: Charging
  4382. }
  4383. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4384. {
  4385. currentStatus = Finishing; //OCPP Status: Finishing
  4386. }
  4387. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4388. {
  4389. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4390. }
  4391. 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
  4392. {
  4393. currentStatus = Unavailable; //OCPP Status: Unavailable
  4394. }
  4395. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4396. {
  4397. currentStatus = Faulted; //OCPP Status: Faulted
  4398. }
  4399. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4400. {
  4401. currentStatus = Reserved; //OCPP Status: Reserved
  4402. }
  4403. } //end of the same index
  4404. }//end of for CHAdeMO_QUANTITY
  4405. }
  4406. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4409. {
  4410. tempIndex = ((gun_index==2) ? 1: 0);
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. for (int index = 0; index < CCS_QUANTITY; index++)
  4417. {
  4418. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4421. {
  4422. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4423. {
  4424. currentStatus = Preparing; //OCPP Status: Preparing
  4425. }
  4426. else
  4427. {
  4428. currentStatus = Available; //OCPP Status: Available
  4429. }
  4430. }
  4431. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4432. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4433. ) //S_PRECHARGE
  4434. {
  4435. currentStatus = Preparing; //OCPP Status: Preparing
  4436. }
  4437. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4438. {
  4439. currentStatus = Charging; //OCPP Status: Charging
  4440. }
  4441. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4442. {
  4443. currentStatus = Finishing; //OCPP Status: Finishing
  4444. }
  4445. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4446. {
  4447. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4448. }
  4449. 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
  4450. {
  4451. currentStatus = Unavailable; //OCPP Status : Unavailable
  4452. }
  4453. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4454. {
  4455. currentStatus = Faulted; //OCPP Status: Faulted
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4458. {
  4459. currentStatus = Reserved; //OCPP Status: Reserved
  4460. }
  4461. } //end of the same index
  4462. } // end of for CCS_QUANTITY
  4463. }
  4464. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4465. {
  4466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4467. {
  4468. tempIndex = ((gun_index==2) ? 1: 0);
  4469. }
  4470. else
  4471. {
  4472. tempIndex = gun_index;
  4473. }
  4474. for (int index = 0; index < GB_QUANTITY; index++)
  4475. {
  4476. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4479. {
  4480. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4481. {
  4482. currentStatus = Preparing; //OCPP Status: Preparing
  4483. }
  4484. else
  4485. {
  4486. currentStatus = Available; //OCPP Status: Available
  4487. }
  4488. }
  4489. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4490. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4491. ) //S_PRECHARGE
  4492. {
  4493. currentStatus = Preparing; //OCPP Status: Preparing
  4494. }
  4495. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4496. {
  4497. currentStatus = Charging; //OCPP Status: Charging
  4498. }
  4499. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4500. {
  4501. currentStatus = Finishing; //OCPP Status: Finishing
  4502. }
  4503. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4504. {
  4505. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4506. }
  4507. 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
  4508. {
  4509. currentStatus = Unavailable; //OCPP Status: Unavailable
  4510. }
  4511. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4512. {
  4513. currentStatus = Faulted; //OCPP Status: Faulted
  4514. }
  4515. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4516. {
  4517. currentStatus = Reserved; //OCPP Status: Reserved
  4518. }
  4519. } //end of the same index
  4520. } // end of for GB_QUANTITY
  4521. }
  4522. else if(gunType[gun_index] == GUN_TYPE_DO)
  4523. {
  4524. tempIndex = gun_index;
  4525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4526. {
  4527. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4528. {
  4529. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4530. {
  4531. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4532. {
  4533. currentStatus = Preparing; //OCPP Status: Preparing
  4534. }
  4535. else
  4536. {
  4537. currentStatus = Available; //OCPP Status: Available
  4538. }
  4539. }
  4540. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4541. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4542. ) //S_PRECHARGE
  4543. {
  4544. currentStatus = Preparing; //OCPP Status: Preparing
  4545. }
  4546. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4547. {
  4548. currentStatus = Charging; //OCPP Status: Charging
  4549. }
  4550. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4551. {
  4552. currentStatus = Finishing; //OCPP Status: Finishing
  4553. }
  4554. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4555. {
  4556. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4557. }
  4558. 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
  4559. {
  4560. currentStatus = Unavailable; //OCPP Status: Unavailable
  4561. }
  4562. 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
  4563. {
  4564. currentStatus = Faulted; //OCPP Status: Faulted
  4565. }
  4566. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4567. {
  4568. currentStatus = Reserved; //OCPP Status: Reserved
  4569. }
  4570. } //end of the same index
  4571. }
  4572. }
  4573. else
  4574. {
  4575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4576. {
  4577. tempIndex = 2;
  4578. }
  4579. else
  4580. {
  4581. tempIndex = gun_index;
  4582. }
  4583. for (int index = 0; index < AC_QUANTITY; index++)
  4584. {
  4585. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4586. {
  4587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4588. {
  4589. 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))
  4590. {
  4591. currentStatus = Preparing; //OCPP Status: Preparing
  4592. }
  4593. else
  4594. {
  4595. currentStatus = Available; //OCPP Status: Available
  4596. }
  4597. }
  4598. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4599. {
  4600. currentStatus = Preparing; //OCPP Status: Preparing
  4601. }
  4602. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4603. {
  4604. currentStatus = Charging; //OCPP Status: Charging
  4605. }
  4606. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4607. {
  4608. currentStatus = Finishing; //OCPP Status: Finishing
  4609. }
  4610. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4611. {
  4612. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4613. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4614. else
  4615. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4616. }
  4617. 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
  4618. {
  4619. currentStatus = Unavailable; //OCPP Status: Unavailable
  4620. }
  4621. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4622. {
  4623. currentStatus = Faulted; //OCPP Status: Faulted
  4624. }
  4625. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4626. {
  4627. currentStatus = Reserved; //OCPP Status: Reserved
  4628. }
  4629. }//end of the same index
  4630. }//end of for AC_QUANTITY
  4631. }
  4632. //it's option
  4633. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4634. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4635. {
  4636. isStateChanged = FALSE;
  4637. }
  4638. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4639. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4640. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4641. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4642. random_uuid(guid);
  4643. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4644. , MESSAGE_TYPE_CALL
  4645. , guid
  4646. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4647. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4648. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4649. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4650. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4651. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4652. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4653. if((server_sign == TRUE) && isStateChanged)
  4654. {
  4655. LWS_Send(message);
  4656. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4657. 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*/)
  4658. {
  4659. //DEBUG_ERROR("statusNotification mapitem pass");
  4660. result = PASS;
  4661. }
  4662. }
  4663. else
  4664. {
  4665. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4666. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4667. result = PASS;
  4668. }
  4669. return result;
  4670. }
  4671. int sendStopTransactionRequest(int gun_index)
  4672. {
  4673. mtrace();
  4674. int result = FAIL;
  4675. //char message[1500]={0};
  4676. char guid[37]={0};
  4677. char tempdata[65]={0};
  4678. int tempIndex = 0;
  4679. char TempStopTransaction[256];
  4680. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4681. //int idx_sample=0;
  4682. DEBUG_INFO("sendStopTransactionRequest \n");
  4683. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4684. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4685. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4688. {
  4689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4690. {
  4691. tempIndex = ((gun_index==2) ? 1: 0);
  4692. }
  4693. else
  4694. {
  4695. tempIndex = gun_index;
  4696. }
  4697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4698. {
  4699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4700. {
  4701. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4702. }
  4703. }// END OF CHAdeMO_QUANTITY
  4704. }
  4705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4706. {
  4707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4708. {
  4709. tempIndex = ((gun_index==2) ? 1: 0);
  4710. }
  4711. else
  4712. {
  4713. tempIndex = gun_index;
  4714. }
  4715. for (int index = 0; index < CCS_QUANTITY; index++)
  4716. {
  4717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4718. {
  4719. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4720. }
  4721. }// END OF CCS_QUANTITY
  4722. }
  4723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4724. {
  4725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4726. {
  4727. tempIndex = ((gun_index==2) ? 1: 0);
  4728. }
  4729. else
  4730. {
  4731. tempIndex = gun_index;
  4732. }
  4733. for (int index = 0; index < GB_QUANTITY; index++)
  4734. {
  4735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4736. {
  4737. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4738. }
  4739. }// END OF GB_QUANTITY
  4740. }
  4741. else if(gunType[gun_index] == GUN_TYPE_DO)
  4742. {
  4743. tempIndex = gun_index;
  4744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4745. {
  4746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4747. {
  4748. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4749. }
  4750. }// END OF GB_QUANTITY
  4751. }
  4752. else
  4753. {
  4754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4755. {
  4756. tempIndex = 2;
  4757. }
  4758. else
  4759. {
  4760. tempIndex = gun_index;
  4761. }
  4762. for (int index = 0; index < AC_QUANTITY; index++)
  4763. {
  4764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4765. {
  4766. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4767. }
  4768. }// END OF AC_QUANTITY
  4769. }
  4770. //====================================== Stop Transaction Time =====================================================
  4771. struct timeval tmnow;
  4772. struct tm *tm;
  4773. char buf[28];//, usec_buf[6];
  4774. gettimeofday(&tmnow, NULL);
  4775. time_t t;
  4776. t = time(NULL);
  4777. /*UTC time and date*/
  4778. tm = gmtime(&t);
  4779. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4781. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4782. random_uuid(guid);
  4783. /***********************************transactionData******************************************************/
  4784. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4786. //=================================
  4787. // Transaction_Begin
  4788. //=================================
  4789. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4790. {
  4791. //============================================ Energy.Active.Import.Interval ================================
  4792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4795. 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*/]);
  4796. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4797. 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))
  4798. {
  4799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4800. }
  4801. else
  4802. {
  4803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4804. }
  4805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4807. }
  4808. //=================================
  4809. // Transaction_End
  4810. //=================================
  4811. // ================================= Current.Import L1 ===============================================
  4812. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4813. {
  4814. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4815. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4816. {
  4817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4818. {
  4819. tempIndex = ((gun_index==2) ? 1: 0);
  4820. }
  4821. else
  4822. {
  4823. tempIndex = gun_index;
  4824. }
  4825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4826. {
  4827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4828. {
  4829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4830. }
  4831. }// End of for CHAdeMO_QUANTITY
  4832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4833. }
  4834. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4835. {
  4836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4837. {
  4838. tempIndex = ((gun_index==2) ? 1: 0);
  4839. }
  4840. else
  4841. {
  4842. tempIndex = gun_index;
  4843. }
  4844. for (int index = 0; index < CCS_QUANTITY; index++)
  4845. {
  4846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4847. {
  4848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4849. }
  4850. }// End of for CCS_QUANTITY
  4851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4852. }
  4853. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4854. {
  4855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4856. {
  4857. tempIndex = ((gun_index==2) ? 1: 0);
  4858. }
  4859. else
  4860. {
  4861. tempIndex = gun_index;
  4862. }
  4863. for (int index = 0; index < GB_QUANTITY; index++)
  4864. {
  4865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4866. {
  4867. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4868. }
  4869. }// End of for GB_QUANTITY
  4870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4871. }
  4872. else if(gunType[gun_index] == GUN_TYPE_DO)
  4873. {
  4874. tempIndex = gun_index;
  4875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4876. {
  4877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4878. {
  4879. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4880. }
  4881. }
  4882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4883. }
  4884. else
  4885. {
  4886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4887. {
  4888. tempIndex = 2;
  4889. }
  4890. else
  4891. {
  4892. tempIndex = gun_index;
  4893. }
  4894. for (int index = 0; index < AC_QUANTITY; index++)
  4895. {
  4896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4897. {
  4898. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4899. }
  4900. }// End of for AC_QUANTITY
  4901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4902. }
  4903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4908. }
  4909. // ================================= Energy.Active.Import.Interval ==============================================
  4910. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4911. {
  4912. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4916. {
  4917. tempIndex = ((gun_index==2) ? 1: 0);
  4918. }
  4919. else
  4920. {
  4921. tempIndex = gun_index;
  4922. }
  4923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4924. {
  4925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4926. {
  4927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4928. }
  4929. }// END OF CHAdeMO_QUANTITY
  4930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4931. }
  4932. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  4943. {
  4944. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4945. {
  4946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4947. }
  4948. }// END OF CCS_QUANTITY
  4949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4950. }
  4951. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4952. {
  4953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4954. {
  4955. tempIndex = ((gun_index==2) ? 1: 0);
  4956. }
  4957. else
  4958. {
  4959. tempIndex = gun_index;
  4960. }
  4961. for (int index = 0; index < GB_QUANTITY; index++)
  4962. {
  4963. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4964. {
  4965. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4966. }
  4967. }// END OF GB_QUANTITY
  4968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4969. }
  4970. else if(gunType[gun_index] == GUN_TYPE_DO)
  4971. {
  4972. tempIndex = gun_index;
  4973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4974. {
  4975. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4976. {
  4977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4978. }
  4979. }
  4980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4981. }
  4982. else
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4985. {
  4986. tempIndex = 2;
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < AC_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4995. {
  4996. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4997. }
  4998. }// END OF AC_QUANTITY
  4999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5000. }
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5006. }
  5007. //=================================== Power.Active.Import ==================================================
  5008. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5009. {
  5010. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5011. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5012. {
  5013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5014. {
  5015. tempIndex = ((gun_index==2) ? 1: 0);
  5016. }
  5017. else
  5018. {
  5019. tempIndex = gun_index;
  5020. }
  5021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5024. {
  5025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5026. }
  5027. } // End for CHAdeMO_QUANTITY
  5028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5029. }
  5030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5031. {
  5032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5033. {
  5034. tempIndex = ((gun_index==2) ? 1: 0);
  5035. }
  5036. else
  5037. {
  5038. tempIndex = gun_index;
  5039. }
  5040. for (int index = 0; index < CCS_QUANTITY; index++)
  5041. {
  5042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5043. {
  5044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5045. }
  5046. } // END for CCS_QUANTITY
  5047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5048. }
  5049. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5052. {
  5053. tempIndex = ((gun_index==2) ? 1: 0);
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < GB_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5062. {
  5063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5064. }
  5065. }// END for GB_QUANTITY
  5066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5067. }
  5068. else if(gunType[gun_index] == GUN_TYPE_DO)
  5069. {
  5070. tempIndex = gun_index;
  5071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5072. {
  5073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5074. {
  5075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5076. }
  5077. }
  5078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5079. }
  5080. else
  5081. {
  5082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5083. {
  5084. tempIndex = 2;
  5085. }
  5086. else
  5087. {
  5088. tempIndex = gun_index;
  5089. }
  5090. for (int index = 0; index < AC_QUANTITY; index++)
  5091. {
  5092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5093. {
  5094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5095. }
  5096. } // END for AC_QUANTITY
  5097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5098. }
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5104. }
  5105. //============================ Voltage L1 ====================================
  5106. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5107. {
  5108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5110. {
  5111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5112. {
  5113. tempIndex = ((gun_index==2) ? 1: 0);
  5114. }
  5115. else
  5116. {
  5117. tempIndex = gun_index;
  5118. }
  5119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5120. {
  5121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5122. {
  5123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5124. }
  5125. } // END OF FOR CHAdeMO_QUANTITY
  5126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5127. }
  5128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5129. {
  5130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5131. {
  5132. tempIndex = ((gun_index==2) ? 1: 0);
  5133. }
  5134. else
  5135. {
  5136. tempIndex = gun_index;
  5137. }
  5138. for (int index = 0; index < CCS_QUANTITY; index++)
  5139. {
  5140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5141. {
  5142. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5143. }
  5144. } // END OF FOR CCS_QUANTITY
  5145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5146. }
  5147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5148. {
  5149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5150. {
  5151. tempIndex = ((gun_index==2) ? 1: 0);
  5152. }
  5153. else
  5154. {
  5155. tempIndex = gun_index;
  5156. }
  5157. for (int index = 0; index < GB_QUANTITY; index++)
  5158. {
  5159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5160. {
  5161. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5162. }
  5163. } // END OF FOR GB_QUANTITY
  5164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5165. }
  5166. else if(gunType[gun_index] == GUN_TYPE_DO)
  5167. {
  5168. tempIndex = gun_index;
  5169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5170. {
  5171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5172. {
  5173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5174. }
  5175. }
  5176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5177. }
  5178. else
  5179. {
  5180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5181. {
  5182. tempIndex = 2;
  5183. }
  5184. else
  5185. {
  5186. tempIndex = gun_index;
  5187. }
  5188. for (int index = 0; index < AC_QUANTITY; index++)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5191. {
  5192. 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
  5193. }
  5194. } // END OF FOR AC_QUANTITY
  5195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5196. }
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5202. }
  5203. //====================== End SoC ================================
  5204. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5205. {
  5206. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5207. 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))
  5208. {
  5209. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5210. {
  5211. tempIndex = ((gun_index==2) ? 1: 0);
  5212. }
  5213. else
  5214. {
  5215. tempIndex = gun_index;
  5216. }
  5217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5218. {
  5219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5220. {
  5221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5222. {
  5223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5224. }
  5225. }
  5226. }
  5227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5228. {
  5229. for (int index = 0; index < CCS_QUANTITY; index++)
  5230. {
  5231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5232. {
  5233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5234. }
  5235. }
  5236. }
  5237. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5238. {
  5239. for (int index = 0; index < GB_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5242. {
  5243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5244. }
  5245. }
  5246. }
  5247. else if(gunType[gun_index] == GUN_TYPE_DO)
  5248. {
  5249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5250. {
  5251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5252. {
  5253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5254. }
  5255. }
  5256. }
  5257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5263. } // END FOR DC CASE
  5264. }
  5265. // ================================= Current.Import L2 ===============================================
  5266. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5267. {
  5268. // AC 3 phse L2 current
  5269. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5270. {
  5271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5272. {
  5273. tempIndex = 2;
  5274. }
  5275. else
  5276. {
  5277. tempIndex = gun_index;
  5278. }
  5279. for (int index = 0; index < AC_QUANTITY; index++)
  5280. {
  5281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5282. {
  5283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5284. }
  5285. }// End of for AC_QUANTITY
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5287. }
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5293. }
  5294. // ================================= Current.Import L3 ===============================================
  5295. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5296. {
  5297. // AC 3 phse L3 current
  5298. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5299. {
  5300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5301. {
  5302. tempIndex = 2;
  5303. }
  5304. else
  5305. {
  5306. tempIndex = gun_index;
  5307. }
  5308. for (int index = 0; index < AC_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5313. }
  5314. }// End of for AC_QUANTITY
  5315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5316. }
  5317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5322. }
  5323. //============================ Voltage L2 ====================================
  5324. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5325. {
  5326. // AC 3 phse L2 voltage
  5327. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5328. {
  5329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5330. {
  5331. tempIndex = 2;
  5332. }
  5333. else
  5334. {
  5335. tempIndex = gun_index;
  5336. }
  5337. for (int index = 0; index < AC_QUANTITY; index++)
  5338. {
  5339. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5340. {
  5341. 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
  5342. }
  5343. } // END OF FOR AC_QUANTITY
  5344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5345. }
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5351. }
  5352. //============================ Voltage L3 ====================================
  5353. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5354. {
  5355. // AC 3 phse L3 voltage
  5356. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5357. {
  5358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5359. {
  5360. tempIndex = 2;
  5361. }
  5362. else
  5363. {
  5364. tempIndex = gun_index;
  5365. }
  5366. for (int index = 0; index < AC_QUANTITY; index++)
  5367. {
  5368. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5369. {
  5370. 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
  5371. }
  5372. } // END OF FOR AC_QUANTITY
  5373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5374. }
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5380. }
  5381. //====================== Start SoC ================================
  5382. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5383. {
  5384. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5385. 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))
  5386. {
  5387. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5388. {
  5389. tempIndex = ((gun_index==2) ? 1: 0);
  5390. }
  5391. else
  5392. {
  5393. tempIndex = gun_index;
  5394. }
  5395. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5396. {
  5397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5400. {
  5401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5402. }
  5403. }
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5406. {
  5407. for (int index = 0; index < CCS_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5410. {
  5411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5412. }
  5413. }
  5414. }
  5415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5416. {
  5417. for (int index = 0; index < GB_QUANTITY; index++)
  5418. {
  5419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5420. {
  5421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5422. }
  5423. }
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_DO)
  5426. {
  5427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5430. {
  5431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5432. }
  5433. }
  5434. }
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5441. } // END FOR DC CASE
  5442. }
  5443. //================================================ Message create ====================================================
  5444. json_object *StopTransaction = json_object_new_object();
  5445. json_object *transactionDatas = json_object_new_array();
  5446. json_object *sampledValues = json_object_new_array();
  5447. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5448. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5449. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5450. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5451. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5452. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5453. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5454. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5455. {
  5456. json_object *transactionData = json_object_new_object();
  5457. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5458. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5459. {
  5460. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5461. {
  5462. json_object *sampledValue = json_object_new_object();
  5463. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5464. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5465. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5466. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5467. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5468. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5469. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5470. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5471. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5472. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5473. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5474. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5475. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5476. json_object_array_add(sampledValues, sampledValue);
  5477. }
  5478. }
  5479. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5480. json_object_array_add(transactionDatas, transactionData);
  5481. }
  5482. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5483. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5484. ,MESSAGE_TYPE_CALL
  5485. ,guid
  5486. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5487. json_object_put(StopTransaction);
  5488. #if 1 // for TempStopTransaction
  5489. //Delete TempStopTransaction
  5490. if((access(TempStopTransaction,F_OK))!=-1)
  5491. {
  5492. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5493. }
  5494. #endif
  5495. #if 1
  5496. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5497. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5498. {
  5499. result = PASS;
  5500. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5501. }
  5502. #endif
  5503. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5504. OCPP_insert_transaction_msg(NO, queuedata);
  5505. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5506. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5507. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5508. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5509. {
  5510. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5511. }
  5512. //for test
  5513. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5514. return result;
  5515. }
  5516. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5517. {
  5518. mtrace();
  5519. int result = FAIL;
  5520. char guid[37]={0};
  5521. char tempdata[65]={0};
  5522. int tempIndex = 0;
  5523. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5524. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5525. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5526. //set value
  5527. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5528. 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) )?
  5529. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5530. -1);
  5531. random_uuid(guid);
  5532. //UTC Date time
  5533. struct timeval tmnow;
  5534. struct tm *tm;
  5535. char buf[28];//, usec_buf[6];
  5536. gettimeofday(&tmnow, NULL);
  5537. time_t t;
  5538. t = time(NULL);
  5539. /*UTC time and date*/
  5540. tm = gmtime(&t);
  5541. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5543. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5544. //********************************(1)Current.Import L1************************************************/
  5545. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5546. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5547. (dataType == ReadingContext_Trigger))
  5548. {
  5549. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5550. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5551. {
  5552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5553. {
  5554. tempIndex = ((gun_index==2) ? 1: 0);
  5555. }
  5556. else
  5557. {
  5558. tempIndex = gun_index;
  5559. }
  5560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5561. {
  5562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5563. {
  5564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5565. }
  5566. }
  5567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5568. }
  5569. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5570. {
  5571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5572. {
  5573. tempIndex = ((gun_index==2) ? 1: 0);
  5574. }
  5575. else
  5576. {
  5577. tempIndex = gun_index;
  5578. }
  5579. for (int index = 0; index < CCS_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5582. {
  5583. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5584. }
  5585. }
  5586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5587. }
  5588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5589. {
  5590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5591. {
  5592. tempIndex = ((gun_index==2) ? 1: 0);
  5593. }
  5594. else
  5595. {
  5596. tempIndex = gun_index;
  5597. }
  5598. for (int index = 0; index < GB_QUANTITY; index++)
  5599. {
  5600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5601. {
  5602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5603. }
  5604. }
  5605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5606. }
  5607. else if(gunType[gun_index] == GUN_TYPE_DO)
  5608. {
  5609. tempIndex = gun_index;
  5610. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5611. {
  5612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5613. {
  5614. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5615. }
  5616. }
  5617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5618. }
  5619. else
  5620. {
  5621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5622. {
  5623. tempIndex = 2;
  5624. }
  5625. else
  5626. {
  5627. tempIndex = gun_index;
  5628. }
  5629. for (int index = 0; index < AC_QUANTITY; index++)
  5630. {
  5631. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5632. {
  5633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5634. }
  5635. }
  5636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5637. }
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5643. }
  5644. //********************************(2)Energy.Active.Import.Register ************************************************/
  5645. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5646. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5647. (dataType == ReadingContext_Trigger))
  5648. {
  5649. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5650. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5651. {
  5652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5653. {
  5654. tempIndex = ((gun_index==2) ? 1: 0);
  5655. }
  5656. else
  5657. {
  5658. tempIndex = gun_index;
  5659. }
  5660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5661. {
  5662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5663. {
  5664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5665. }
  5666. }
  5667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5668. }
  5669. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5670. {
  5671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5672. {
  5673. tempIndex = ((gun_index==2) ? 1: 0);
  5674. }
  5675. else
  5676. {
  5677. tempIndex = gun_index;
  5678. }
  5679. for (int index = 0; index < CCS_QUANTITY; index++)
  5680. {
  5681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5682. {
  5683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5684. }
  5685. }
  5686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5687. }
  5688. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < GB_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5703. }
  5704. }
  5705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5706. }
  5707. else if(gunType[gun_index] == GUN_TYPE_DO)
  5708. {
  5709. tempIndex = gun_index;
  5710. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5711. {
  5712. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5713. {
  5714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5715. }
  5716. }
  5717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5718. }
  5719. else
  5720. {
  5721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5722. {
  5723. tempIndex = 2;
  5724. }
  5725. else
  5726. {
  5727. tempIndex = gun_index;
  5728. }
  5729. for (int index = 0; index < AC_QUANTITY; index++)
  5730. {
  5731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5732. {
  5733. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5734. }
  5735. }
  5736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5737. }
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5743. }
  5744. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5745. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5746. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5747. (dataType == ReadingContext_Trigger))
  5748. {
  5749. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5750. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5751. {
  5752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5753. {
  5754. tempIndex = ((gun_index==2) ? 1: 0);
  5755. }
  5756. else
  5757. {
  5758. tempIndex = gun_index;
  5759. }
  5760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5761. {
  5762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5763. {
  5764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5765. }
  5766. } // END OF FOR CHAdeMO_QUANTITY
  5767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5768. }
  5769. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5770. {
  5771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5772. {
  5773. tempIndex = ((gun_index==2) ? 1: 0);
  5774. }
  5775. else
  5776. {
  5777. tempIndex = gun_index;
  5778. }
  5779. for (int index = 0; index < CCS_QUANTITY; index++)
  5780. {
  5781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5782. {
  5783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5784. }
  5785. } // END OF CCS_QUANTITY
  5786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5787. }
  5788. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5789. {
  5790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5791. {
  5792. tempIndex = ((gun_index==2) ? 1: 0);
  5793. }
  5794. else
  5795. {
  5796. tempIndex = gun_index;
  5797. }
  5798. for (int index = 0; index < GB_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5801. {
  5802. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5803. }
  5804. } // END OF GB_QUANTITY
  5805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5806. }
  5807. else if(gunType[gun_index] == GUN_TYPE_DO)
  5808. {
  5809. tempIndex = gun_index;
  5810. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5811. {
  5812. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5813. {
  5814. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5815. }
  5816. }
  5817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5818. }
  5819. else
  5820. {
  5821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5822. {
  5823. tempIndex = 2;
  5824. }
  5825. else
  5826. {
  5827. tempIndex = gun_index;
  5828. }
  5829. for (int index = 0; index < AC_QUANTITY; index++)
  5830. {
  5831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5832. {
  5833. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5834. }
  5835. }
  5836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5837. }
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5843. }
  5844. //********************************(4)Power.Active.Import************************************************/
  5845. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5846. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5847. (dataType == ReadingContext_Trigger))
  5848. {
  5849. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5850. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5851. {
  5852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5853. {
  5854. tempIndex = ((gun_index==2) ? 1: 0);
  5855. }
  5856. else
  5857. {
  5858. tempIndex = gun_index;
  5859. }
  5860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5861. {
  5862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5863. {
  5864. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5865. }
  5866. } // END OF FOR
  5867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5868. }
  5869. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5870. {
  5871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5872. {
  5873. tempIndex = ((gun_index==2) ? 1: 0);
  5874. }
  5875. else
  5876. {
  5877. tempIndex = gun_index;
  5878. }
  5879. for (int index = 0; index < CCS_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5882. {
  5883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5884. }
  5885. }
  5886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5887. }
  5888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5889. {
  5890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5891. {
  5892. tempIndex = ((gun_index==2) ? 1: 0);
  5893. }
  5894. else
  5895. {
  5896. tempIndex = gun_index;
  5897. }
  5898. for (int index = 0; index < GB_QUANTITY; index++)
  5899. {
  5900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5901. {
  5902. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5904. }
  5905. }
  5906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5907. }
  5908. else if(gunType[gun_index] == GUN_TYPE_DO)
  5909. {
  5910. tempIndex = gun_index;
  5911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5914. {
  5915. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5917. }
  5918. }
  5919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5920. }
  5921. else
  5922. {
  5923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5924. {
  5925. tempIndex = 2;
  5926. }
  5927. else
  5928. {
  5929. tempIndex = gun_index;
  5930. }
  5931. for (int index = 0; index < AC_QUANTITY; index++)
  5932. {
  5933. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5934. {
  5935. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5936. }
  5937. }
  5938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5939. }
  5940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5944. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5945. }
  5946. //***********************************************(5)VOLTAGE L1******************************************************/
  5947. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5948. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5949. (dataType == ReadingContext_Trigger))
  5950. {
  5951. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5953. {
  5954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5955. {
  5956. tempIndex = ((gun_index==2) ? 1: 0);
  5957. }
  5958. else
  5959. {
  5960. tempIndex = gun_index;
  5961. }
  5962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5963. {
  5964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5965. {
  5966. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5967. }
  5968. }
  5969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5970. }
  5971. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5972. {
  5973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5974. {
  5975. tempIndex = ((gun_index==2) ? 1: 0);
  5976. }
  5977. else
  5978. {
  5979. tempIndex = gun_index;
  5980. }
  5981. for (int index = 0; index < CCS_QUANTITY; index++)
  5982. {
  5983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5984. {
  5985. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5986. }
  5987. }
  5988. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5989. }
  5990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5991. {
  5992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5993. {
  5994. tempIndex = ((gun_index==2) ? 1: 0);
  5995. }
  5996. else
  5997. {
  5998. tempIndex = gun_index;
  5999. }
  6000. for (int index = 0; index < GB_QUANTITY; index++)
  6001. {
  6002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6003. {
  6004. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6005. }
  6006. }
  6007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6008. }
  6009. else if(gunType[gun_index] == GUN_TYPE_DO)
  6010. {
  6011. tempIndex = gun_index;
  6012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6013. {
  6014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6015. {
  6016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6017. }
  6018. }
  6019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6020. }
  6021. else
  6022. {
  6023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6024. {
  6025. tempIndex = 2;
  6026. }
  6027. else
  6028. {
  6029. tempIndex = gun_index;
  6030. }
  6031. for (int index = 0; index < AC_QUANTITY; index++)
  6032. {
  6033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6034. {
  6035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6036. }
  6037. }
  6038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6039. }
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6045. }
  6046. //***********************************************(6)SOC******************************************************/
  6047. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  6048. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  6049. (dataType == ReadingContext_Trigger))
  6050. {
  6051. 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))
  6052. {
  6053. //idx_sample=5;
  6054. //sampledValue = NULL;
  6055. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6056. {
  6057. tempIndex = ((gun_index==2) ? 1: 0);
  6058. }
  6059. else
  6060. {
  6061. tempIndex = gun_index;
  6062. }
  6063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6064. {
  6065. //tempIndex = ((gun_index==2) ? 1: 0);
  6066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6067. {
  6068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6069. {
  6070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6071. }
  6072. }
  6073. }
  6074. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6075. {
  6076. //tempIndex = ((gun_index==2) ? 1: 0);
  6077. for (int index = 0; index < CCS_QUANTITY; index++)
  6078. {
  6079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6080. {
  6081. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6082. }
  6083. }
  6084. }
  6085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6086. {
  6087. //tempIndex = ((gun_index==2) ? 1: 0);
  6088. for (int index = 0; index < GB_QUANTITY; index++)
  6089. {
  6090. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6091. {
  6092. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6093. }
  6094. }
  6095. }
  6096. else if(gunType[gun_index] == GUN_TYPE_DO)
  6097. {
  6098. //tempIndex = ((gun_index==2) ? 1: 0);
  6099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6104. }
  6105. }
  6106. }
  6107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6113. }
  6114. }
  6115. //********************************(7)Current.Import L2************************************************/
  6116. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6117. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6118. (dataType == ReadingContext_Trigger))
  6119. {
  6120. // Only for AC 3 phase
  6121. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6122. {
  6123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6124. {
  6125. tempIndex = 2;
  6126. }
  6127. else
  6128. {
  6129. tempIndex = gun_index;
  6130. }
  6131. for (int index = 0; index < AC_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6134. {
  6135. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6136. }
  6137. }
  6138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6139. }
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6144. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6145. }
  6146. //********************************(8)Current.Import L3************************************************/
  6147. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6148. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6149. (dataType == ReadingContext_Trigger))
  6150. {
  6151. // Only for AC 3 phase
  6152. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6153. {
  6154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6155. {
  6156. tempIndex = 2;
  6157. }
  6158. else
  6159. {
  6160. tempIndex = gun_index;
  6161. }
  6162. for (int index = 0; index < AC_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6165. {
  6166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6167. }
  6168. }
  6169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6170. }
  6171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6176. }
  6177. //***********************************************(9)VOLTAGE L2******************************************************/
  6178. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6179. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6180. (dataType == ReadingContext_Trigger))
  6181. {
  6182. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6183. {
  6184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6185. {
  6186. tempIndex = 2;
  6187. }
  6188. else
  6189. {
  6190. tempIndex = gun_index;
  6191. }
  6192. for (int index = 0; index < AC_QUANTITY; index++)
  6193. {
  6194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6195. {
  6196. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6200. }
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6206. }
  6207. //***********************************************(10)VOLTAGE L3******************************************************/
  6208. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6209. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6210. (dataType == ReadingContext_Trigger))
  6211. {
  6212. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6215. {
  6216. tempIndex = 2;
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < AC_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6227. }
  6228. }
  6229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6230. }
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6236. }
  6237. // Message create ====================================================================================================
  6238. if(TRUE)
  6239. {
  6240. json_object *MeterValueReq = json_object_new_object();
  6241. json_object *MeterValues = json_object_new_array();
  6242. json_object *sampledValues = json_object_new_array();
  6243. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6244. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6245. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6246. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6247. {
  6248. json_object *MeterValue = json_object_new_object();
  6249. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6250. {
  6251. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6252. {
  6253. json_object *sampledValue = json_object_new_object();
  6254. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6255. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6256. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6257. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6258. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6259. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6260. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6261. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6262. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6263. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6264. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6265. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6266. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6267. json_object_array_add(sampledValues, sampledValue);
  6268. }
  6269. }
  6270. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6271. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6272. json_object_array_add(MeterValues, MeterValue);
  6273. }
  6274. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6275. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6276. ,gun_index + 1
  6277. ,MESSAGE_TYPE_CALL
  6278. ,guid
  6279. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6280. json_object_put(MeterValueReq);
  6281. }
  6282. // Put request guid to hash map
  6283. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6284. 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*/)
  6285. {
  6286. result = PASS;
  6287. //DEBUG_INFO("MeterValues mapitem pass\n");
  6288. }
  6289. if((dataType != ReadingContext_Trigger) &&
  6290. (dataType != ReadingContext_Sample_Clock) &&
  6291. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6292. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6293. else
  6294. {
  6295. if(FirstHeartBeat)
  6296. LWS_Send(queuedata +2);
  6297. }
  6298. return result;
  6299. }
  6300. int sendLogStatusNotificationRequest(char *status)
  6301. {
  6302. mtrace();
  6303. int result = PASS;
  6304. char message[4096]={0};
  6305. char guid[37]={0};
  6306. char tempdata[128]={0};
  6307. json_object *LogStatusNotification = json_object_new_object();
  6308. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6309. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6310. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6311. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6312. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6313. random_uuid(guid);
  6314. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6315. json_object_put(LogStatusNotification);
  6316. LWS_Send(message);
  6317. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6318. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6319. {
  6320. result = PASS;
  6321. }
  6322. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6323. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6324. return result;
  6325. }
  6326. int sendSecurityEventNotificationRequest()
  6327. {
  6328. mtrace();
  6329. int result = PASS;
  6330. char message[4096]={0};
  6331. char guid[37]={0};
  6332. char tempdata[128]={0};
  6333. json_object *SecurityEventNotification = json_object_new_object();
  6334. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6335. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6336. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6337. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6338. random_uuid(guid);
  6339. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6340. json_object_put(SecurityEventNotification);
  6341. LWS_Send(message);
  6342. sprintf(tempdata, "SecurityEventNotification,0");
  6343. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6344. {
  6345. result = PASS;
  6346. }
  6347. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6348. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6349. return result;
  6350. }
  6351. int sendSignCertificateRequest()
  6352. {
  6353. mtrace();
  6354. int result = PASS;
  6355. char message[4096]={0};
  6356. char guid[37]={0};
  6357. char tempdata[128]={0};
  6358. json_object *SignCertificate = json_object_new_object();
  6359. DEBUG_INFO("sendSignCertificateRequest...\n");
  6360. // Read csr file content
  6361. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6362. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6363. char *line = NULL;
  6364. size_t len = 0;
  6365. while(getline(&line, &len, fp) != -1)
  6366. {
  6367. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6368. {
  6369. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6370. }
  6371. }
  6372. fclose(fp);
  6373. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6374. random_uuid(guid);
  6375. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6376. json_object_put(SignCertificate);
  6377. LWS_Send(message);
  6378. sprintf(tempdata, "SignCertificate,0");
  6379. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6380. {
  6381. result = PASS;
  6382. }
  6383. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6384. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6385. return result;
  6386. }
  6387. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6388. {
  6389. mtrace();
  6390. int result = PASS;
  6391. char message[110]={0};
  6392. char guid[37]={0};
  6393. char tempdata[65]={0};
  6394. json_object *FirmwareStatusNotification = json_object_new_object();
  6395. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6396. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6397. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6398. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6399. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6400. random_uuid(guid);
  6401. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6402. json_object_put(FirmwareStatusNotification);
  6403. LWS_Send(message);
  6404. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6405. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6406. {
  6407. result = PASS;
  6408. }
  6409. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6410. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6411. return result;
  6412. }
  6413. //==========================================
  6414. // send confirm routine
  6415. //==========================================
  6416. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6417. {
  6418. mtrace();
  6419. int result = FAIL;
  6420. char message[100]={0};
  6421. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6423. LWS_Send(message);
  6424. result = TRUE;
  6425. return result;
  6426. }
  6427. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6428. {
  6429. mtrace();
  6430. int result = FAIL;
  6431. char message[100]={0};
  6432. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6433. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6434. LWS_Send(message);
  6435. result = TRUE;
  6436. return result;
  6437. }
  6438. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6439. {
  6440. mtrace();
  6441. int result = FAIL;
  6442. char message[100]={0};
  6443. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6444. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6445. LWS_Send(message);
  6446. result = TRUE;
  6447. return result;
  6448. }
  6449. int sendClearCacheConfirmation(char *uuid,char *payload)
  6450. {
  6451. mtrace();
  6452. int result = FAIL;
  6453. char message[500]={0};
  6454. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6455. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6456. LWS_Send(message);
  6457. return result;
  6458. }
  6459. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6460. {
  6461. mtrace();
  6462. int result = FAIL;
  6463. char message[500]={0};
  6464. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6465. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6466. LWS_Send(message);
  6467. return result;
  6468. }
  6469. int sendDataTransferConfirmation(char *uuid,char *payload)
  6470. {
  6471. mtrace();
  6472. char statusStr[20]={0};
  6473. char dataStr[10]={0};
  6474. char sstr[20]={0};
  6475. int c = 0;
  6476. char *loc;
  6477. int result = FAIL;
  6478. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6479. /**********************status**************************/
  6480. loc = strstr(payload, "status");
  6481. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6482. c = 0;
  6483. while (loc[3+strlen("status")+c] != '\"')
  6484. {
  6485. sstr[c] = loc[3+strlen("status")+c];
  6486. c++;
  6487. }
  6488. sstr[c] = '\0';
  6489. strcpy(statusStr, sstr);
  6490. /**********************data**************************/
  6491. loc = strstr(payload, "data");
  6492. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6493. c = 0;
  6494. while (loc[3+strlen("data")+c] != '\"')
  6495. {
  6496. sstr[c] = loc[3+strlen("data")+c];
  6497. c++;
  6498. }
  6499. sstr[c] = '\0';
  6500. strcpy(dataStr, sstr);
  6501. return result;
  6502. }
  6503. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6504. {
  6505. mtrace();
  6506. int result = FAIL;
  6507. char message[1000]={0};
  6508. int CompositeScheduleIndex = 0;
  6509. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6510. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6511. if(nPeriod == 0)
  6512. {
  6513. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6514. {
  6515. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6516. ,MESSAGE_TYPE_CALLRESULT
  6517. ,uuid
  6518. ,payload
  6519. ,connectorIdInt);
  6520. }
  6521. else
  6522. {
  6523. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6524. ,MESSAGE_TYPE_CALLRESULT
  6525. ,uuid
  6526. ,payload
  6527. ,connectorIdInt
  6528. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6529. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6530. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6531. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6532. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6533. }
  6534. }
  6535. else
  6536. {
  6537. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6538. ,MESSAGE_TYPE_CALLRESULT
  6539. ,uuid
  6540. ,payload
  6541. ,connectorIdInt
  6542. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6543. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6544. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6545. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6546. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6547. {
  6548. if (idx_sample == 0)
  6549. {
  6550. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6551. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6552. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6553. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6554. }
  6555. else
  6556. {
  6557. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6558. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6559. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6560. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6561. }
  6562. }
  6563. sprintf(message + strlen(message), "]}}]");
  6564. }
  6565. LWS_Send(message);
  6566. result = TRUE;
  6567. return result;
  6568. }
  6569. int sendGetConfigurationConfirmation(char *uuid)
  6570. {
  6571. mtrace();
  6572. int result = FAIL;
  6573. int MaxKeySupported = 0;
  6574. int sentConfigurationNumber= 0;
  6575. int sentunConfigurationNumber= 0;
  6576. char message[4000]={0};
  6577. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6578. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6579. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6580. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6581. ,MESSAGE_TYPE_CALLRESULT
  6582. ,uuid );
  6583. //configuration key
  6584. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6585. {
  6586. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6587. {
  6588. if (sentConfigurationNumber == 0)
  6589. {
  6590. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6591. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6592. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6593. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6594. }
  6595. else
  6596. {
  6597. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6598. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6599. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6600. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6601. }
  6602. sentConfigurationNumber = sentConfigurationNumber + 1;
  6603. }
  6604. }
  6605. sprintf(message + strlen(message), "]");
  6606. if(UnknownKeynum != 0)
  6607. {
  6608. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6609. //unkown key
  6610. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6611. {
  6612. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6613. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6614. if(sentunConfigurationNumber == 0)
  6615. {
  6616. sprintf(message + strlen(message), "\"%s\""
  6617. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6618. }
  6619. else
  6620. {
  6621. sprintf(message + strlen(message), ",\"%s\""
  6622. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6623. }
  6624. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6625. }
  6626. sprintf(message + strlen(message), "]");
  6627. }
  6628. sprintf(message + strlen(message), "}]");
  6629. LWS_Send(message);
  6630. return result;
  6631. }
  6632. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6633. {
  6634. mtrace();
  6635. int result = FAIL;
  6636. char message[400]={0};
  6637. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6638. if(strcmp(payload,"")==0)
  6639. {
  6640. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6641. }
  6642. else
  6643. {
  6644. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6645. }
  6646. LWS_Send(message);
  6647. result = TRUE;
  6648. return result;
  6649. }
  6650. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6651. {
  6652. mtrace();
  6653. int result = FAIL;
  6654. char message[80]={0};
  6655. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6656. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6657. LWS_Send(message);
  6658. result = TRUE;
  6659. return result;
  6660. }
  6661. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6662. {
  6663. mtrace();
  6664. int result = FAIL;
  6665. char message[80]={0};
  6666. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6667. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6668. LWS_Send(message);
  6669. result = TRUE;
  6670. return result;
  6671. }
  6672. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6673. {
  6674. mtrace();
  6675. int result = FAIL;
  6676. char message[80]={0};
  6677. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6678. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6679. LWS_Send(message);
  6680. result = TRUE;
  6681. return result;
  6682. }
  6683. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6684. {
  6685. mtrace();
  6686. int result = FAIL;
  6687. char message[80]={0};
  6688. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6689. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6690. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6691. LWS_Send(message);
  6692. result = TRUE;
  6693. return result;
  6694. }
  6695. int sendResetConfirmation(char *uuid,char *payload)
  6696. {
  6697. mtrace();
  6698. int result = FAIL;
  6699. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6700. char message[80]={0};
  6701. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6702. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6703. LWS_Send(message);
  6704. result = TRUE;
  6705. return result;
  6706. }
  6707. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6708. {
  6709. mtrace();
  6710. int result = FAIL;
  6711. char message[500]={0};
  6712. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6713. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6714. LWS_Send(message);
  6715. result = TRUE;
  6716. return result;
  6717. }
  6718. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6719. {
  6720. mtrace();
  6721. int result = FAIL;
  6722. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6723. char message[80]={0};
  6724. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6725. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6726. LWS_Send(message);
  6727. result = TRUE;
  6728. return result;
  6729. }
  6730. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6731. {
  6732. mtrace();
  6733. int result = FAIL;
  6734. char message[80]={0};
  6735. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6736. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6737. LWS_Send(message);
  6738. result = TRUE;
  6739. return result;
  6740. }
  6741. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6742. {
  6743. mtrace();
  6744. int result = FAIL;
  6745. char message[80]={0};
  6746. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6747. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6748. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6749. LWS_Send(message);
  6750. result = TRUE;
  6751. return result;
  6752. }
  6753. int sendUpdateFirmwareConfirmation(char *uuid)
  6754. {
  6755. mtrace();
  6756. int result = FAIL;
  6757. char message[60]={0};
  6758. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6759. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6760. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6761. LWS_Send(message);
  6762. result = TRUE;
  6763. return result;
  6764. }
  6765. int sendCertificateSignedConfirmation(char *uuid)
  6766. {
  6767. mtrace();
  6768. int result = PASS;
  6769. char message[4096]={0};
  6770. json_object *CertificateSigned = json_object_new_object();
  6771. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6772. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6773. sprintf(message,"[%d,\"%s\",%s]"
  6774. ,MESSAGE_TYPE_CALLRESULT
  6775. ,uuid
  6776. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6777. json_object_put(CertificateSigned);
  6778. LWS_Send(message);
  6779. return result;
  6780. }
  6781. int sendDeleteCertificateConfirmation(char *uuid)
  6782. {
  6783. mtrace();
  6784. int result = PASS;
  6785. char message[4096]={0};
  6786. json_object *DeleteCertificate = json_object_new_object();
  6787. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6788. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6789. sprintf(message,"[%d,\"%s\",%s]"
  6790. ,MESSAGE_TYPE_CALLRESULT
  6791. ,uuid
  6792. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6793. json_object_put(DeleteCertificate);
  6794. LWS_Send(message);
  6795. return result;
  6796. }
  6797. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6798. {
  6799. mtrace();
  6800. int result = PASS;
  6801. char message[4096]={0};
  6802. json_object *ExtendedTriggerMessage = json_object_new_object();
  6803. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6804. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6805. sprintf(message,"[%d,\"%s\",%s]"
  6806. ,MESSAGE_TYPE_CALLRESULT
  6807. ,uuid
  6808. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6809. json_object_put(ExtendedTriggerMessage);
  6810. LWS_Send(message);
  6811. return result;
  6812. }
  6813. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6814. {
  6815. mtrace();
  6816. int result = PASS;
  6817. char message[4096]={0};
  6818. json_object *GetInstalledCertificateIds = json_object_new_object();
  6819. json_object *certificateHashDataDatas = json_object_new_array();
  6820. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6821. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6822. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6823. {
  6824. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6825. {
  6826. json_object *certificateHashData = json_object_new_object();
  6827. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6828. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6829. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6830. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6831. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6832. }
  6833. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6834. }
  6835. else
  6836. {
  6837. json_object_put(certificateHashDataDatas);
  6838. }
  6839. sprintf(message,"[%d,\"%s\",%s]"
  6840. ,MESSAGE_TYPE_CALLRESULT
  6841. ,uuid
  6842. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6843. json_object_put(GetInstalledCertificateIds);
  6844. LWS_Send(message);
  6845. return result;
  6846. }
  6847. int sendGetLogConfirmation(char *uuid)
  6848. {
  6849. mtrace();
  6850. int result = PASS;
  6851. char message[4096]={0};
  6852. json_object *GetLog = json_object_new_object();
  6853. DEBUG_INFO("sendGetLogConfirmation...\n");
  6854. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6855. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6856. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6857. sprintf(message,"[%d,\"%s\",%s]"
  6858. ,MESSAGE_TYPE_CALLRESULT
  6859. ,uuid
  6860. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6861. json_object_put(GetLog);
  6862. LWS_Send(message);
  6863. return result;
  6864. }
  6865. int sendInstallCertificateConfirmation(char *uuid)
  6866. {
  6867. mtrace();
  6868. int result = PASS;
  6869. char message[4096]={0};
  6870. json_object *InstallCertificate = json_object_new_object();
  6871. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6872. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6873. sprintf(message,"[%d,\"%s\",%s]"
  6874. ,MESSAGE_TYPE_CALLRESULT
  6875. ,uuid
  6876. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6877. json_object_put(InstallCertificate);
  6878. LWS_Send(message);
  6879. return result;
  6880. }
  6881. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6882. {
  6883. mtrace();
  6884. int result = PASS;
  6885. char message[4096]={0};
  6886. json_object *SignedUpdateFirmware = json_object_new_object();
  6887. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6888. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6889. sprintf(message,"[%d,\"%s\",%s]"
  6890. ,MESSAGE_TYPE_CALLRESULT
  6891. ,uuid
  6892. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6893. json_object_put(SignedUpdateFirmware);
  6894. LWS_Send(message);
  6895. return result;
  6896. }
  6897. int sendUnknownConfirmation(char *uuid)
  6898. {
  6899. mtrace();
  6900. int result = PASS;
  6901. char message[256]={0};
  6902. DEBUG_INFO("sendUnknownConfirmation...\n");
  6903. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6904. LWS_Send(message);
  6905. return result;
  6906. }
  6907. //==========================================
  6908. // Handle server request routine Start
  6909. //==========================================
  6910. int handleCancelReservationRequest(char *uuid, char *payload)
  6911. {
  6912. mtrace();
  6913. int result = FAIL;
  6914. int gunNO = 0;
  6915. int reservationIdInt = -1;
  6916. char comfirmstr[20];
  6917. DEBUG_INFO("handleCancelReservationRequest...\n");
  6918. json_object *CancelReservation;
  6919. CancelReservation = json_tokener_parse(payload);
  6920. if(!is_error(CancelReservation))
  6921. {
  6922. // Required data
  6923. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6924. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6925. }
  6926. json_object_put(CancelReservation);
  6927. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6928. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6929. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6930. if(reservationIdInt != -1)
  6931. {
  6932. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6933. //check Transaction active
  6934. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6938. {
  6939. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6940. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6941. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6942. {
  6943. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6944. }
  6945. else
  6946. {
  6947. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6948. }
  6949. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6950. goto end;
  6951. }
  6952. }
  6953. for (int index = 0; index < CCS_QUANTITY; index++)
  6954. {
  6955. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6956. {
  6957. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6958. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6959. if(gunType[2] == GUN_TYPE_CCS)
  6960. {
  6961. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6962. }
  6963. else
  6964. {
  6965. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6966. }
  6967. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6968. goto end;
  6969. }
  6970. }
  6971. for (int index = 0; index < GB_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6974. {
  6975. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6976. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6977. if(gunType[2] == GUN_TYPE_GBT)
  6978. {
  6979. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6980. }
  6981. else
  6982. {
  6983. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6984. }
  6985. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6986. goto end;
  6987. }
  6988. }
  6989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6990. {
  6991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6992. {
  6993. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6994. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6995. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6996. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6997. goto end;
  6998. }
  6999. }
  7000. for (int index = 0; index < AC_QUANTITY; index++)
  7001. {
  7002. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7003. {
  7004. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7005. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7007. {
  7008. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7009. }
  7010. else
  7011. {
  7012. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7013. }
  7014. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7015. goto end;
  7016. }
  7017. }
  7018. }
  7019. //The reservationId does NOT match the reservationId
  7020. sendCancelReservationConfirmation(uuid, comfirmstr);
  7021. end:
  7022. // Fill in ocpp packet uuid
  7023. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7024. return result;
  7025. }
  7026. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7027. {
  7028. mtrace();
  7029. int result = FAIL;
  7030. int gunIndex = 0;
  7031. char typeStr[16]={0};
  7032. char comfirmstr[20];
  7033. int specificId = FALSE;
  7034. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7035. json_object *ChangeAvailability;
  7036. ChangeAvailability = json_tokener_parse(payload);
  7037. if(!is_error(ChangeAvailability))
  7038. {
  7039. // Required data
  7040. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7041. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7042. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7043. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7044. }
  7045. json_object_put(ChangeAvailability);
  7046. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7047. {
  7048. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7049. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7050. }
  7051. else if(gunIndex == 0)
  7052. {
  7053. for(int i=0; i < gunTotalNumber; i++)
  7054. {
  7055. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7056. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7057. }
  7058. }
  7059. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7061. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7062. {
  7063. specificId = TRUE;
  7064. }
  7065. if(specificId == FALSE)
  7066. goto end;
  7067. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7068. {
  7069. //----------------------gunIndex is 0 ------------------------------------------------//
  7070. if(gunIndex == 0)
  7071. {
  7072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7073. {
  7074. for(int i=0; i < gunTotalNumber; i++)
  7075. {
  7076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7077. {
  7078. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7079. {
  7080. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7081. {
  7082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7083. goto end;
  7084. }
  7085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7090. {
  7091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7092. goto end;
  7093. }
  7094. }
  7095. }//END FOR CHAdeMO_QUANTITY
  7096. for (int index = 0; index < CCS_QUANTITY; index++)
  7097. {
  7098. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7099. {
  7100. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7101. {
  7102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7103. goto end;
  7104. }
  7105. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7106. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7107. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7108. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7109. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7110. {
  7111. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7112. goto end;
  7113. }
  7114. }
  7115. }//END FOR CCS_QUANTITY
  7116. for (int index = 0; index < GB_QUANTITY; index++)
  7117. {
  7118. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7119. {
  7120. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7121. {
  7122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7123. goto end;
  7124. }
  7125. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7126. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7127. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7128. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7129. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7130. {
  7131. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7132. goto end;
  7133. }
  7134. }
  7135. }// END FOR GB_QUANTITY
  7136. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7137. {
  7138. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7139. {
  7140. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7141. {
  7142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7143. goto end;
  7144. }
  7145. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7146. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7147. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7148. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7149. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7150. {
  7151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7152. goto end;
  7153. }
  7154. }
  7155. }// END FOR GENERAL_GUN_QUANTITY
  7156. for (int index = 0; index < AC_QUANTITY; index++)
  7157. {
  7158. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7159. {
  7160. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7161. {
  7162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7163. goto end;
  7164. }
  7165. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7167. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7168. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7169. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7170. {
  7171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7172. goto end;
  7173. }
  7174. }
  7175. }//END FOR AC_QUANTITY
  7176. }// END FOR gunTotalNumber
  7177. }
  7178. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7179. {
  7180. for(int i=0; i < gunTotalNumber; i++)
  7181. {
  7182. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7183. {
  7184. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7185. goto end;
  7186. }
  7187. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7189. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7190. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7191. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7192. {
  7193. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7194. goto end;
  7195. }
  7196. }
  7197. }
  7198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7199. goto end;
  7200. }
  7201. //----------------------gunIndex is not 0 ------------------------------------------------//
  7202. //check Transaction active
  7203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7204. {
  7205. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7206. {
  7207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7208. {
  7209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7210. goto end;
  7211. }
  7212. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7213. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7214. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7215. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7216. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7217. {
  7218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7219. goto end;
  7220. }
  7221. else
  7222. {
  7223. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7224. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7225. goto end;
  7226. }
  7227. }
  7228. }//END FOR CHAdeMO_QUANTITY
  7229. for (int index = 0; index < CCS_QUANTITY; index++)
  7230. {
  7231. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7232. {
  7233. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7234. {
  7235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7236. goto end;
  7237. }
  7238. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7239. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7240. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7241. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7242. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7243. {
  7244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7245. goto end;
  7246. }
  7247. else
  7248. {
  7249. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7250. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7251. goto end;
  7252. }
  7253. }
  7254. }//END FOR CCS_QUANTITY
  7255. for (int index = 0; index < GB_QUANTITY; index++)
  7256. {
  7257. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7258. {
  7259. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7260. {
  7261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7262. goto end;
  7263. }
  7264. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7265. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7266. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7267. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7268. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7269. {
  7270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7271. goto end;
  7272. }
  7273. else
  7274. {
  7275. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7277. goto end;
  7278. }
  7279. }
  7280. }// END FOR GB_QUANTITY
  7281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7282. {
  7283. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7284. {
  7285. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7286. {
  7287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7288. goto end;
  7289. }
  7290. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7292. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7293. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7294. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7295. {
  7296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7297. goto end;
  7298. }
  7299. else
  7300. {
  7301. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7303. goto end;
  7304. }
  7305. }
  7306. }// END FOR GENERAL_GUN_QUANTITY
  7307. for (int index = 0; index < AC_QUANTITY; index++)
  7308. {
  7309. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7310. {
  7311. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7312. {
  7313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7314. goto end;
  7315. }
  7316. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7317. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7318. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7319. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7320. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7321. {
  7322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7323. goto end;
  7324. }
  7325. else
  7326. {
  7327. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7329. goto end;
  7330. }
  7331. }
  7332. }//END FOR AC_QUANTITY
  7333. }//END FOR AvailabilityTypeStr[Inoperative]
  7334. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7335. {
  7336. //----------------------gunIndex is 0 ------------------------------------------------//
  7337. if(gunIndex == 0)
  7338. {
  7339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7340. {
  7341. for(int i=0; i < gunTotalNumber; i++)
  7342. {
  7343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7344. {
  7345. 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
  7346. {
  7347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7348. goto end;
  7349. }
  7350. }//END FOR CHAdeMO_QUANTITY
  7351. for (int index = 0; index < CCS_QUANTITY; index++)
  7352. {
  7353. 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
  7354. {
  7355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7356. goto end;
  7357. }
  7358. }//END FOR CCS_QUANTITY
  7359. for (int index = 0; index < GB_QUANTITY; index++)
  7360. {
  7361. 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
  7362. {
  7363. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7365. goto end;
  7366. }
  7367. }// END FOR GB_QUANTITY
  7368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7369. {
  7370. 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
  7371. {
  7372. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7374. goto end;
  7375. }
  7376. }// END FOR GENERAL_GUN_QUANTITY
  7377. for (int index = 0; index < AC_QUANTITY; index++)
  7378. {
  7379. 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
  7380. {
  7381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7382. goto end;
  7383. }
  7384. }//END FOR CHAdeMO_QUANTITY
  7385. }// END FOR gunTotalNumber
  7386. }
  7387. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7388. {
  7389. for(int i=0; i < gunTotalNumber; i++)
  7390. {
  7391. for (int index = 0; index < AC_QUANTITY; index++)
  7392. {
  7393. 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
  7394. {
  7395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7396. goto end;
  7397. }
  7398. }//END FOR CHAdeMO_QUANTITY
  7399. } // END FOR gunTotalNumber
  7400. }
  7401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7402. goto end;
  7403. }
  7404. //----------------------gunIndex is not 0 ------------------------------------------------//
  7405. //check Transaction active
  7406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7407. {
  7408. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7409. {
  7410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7411. goto end;
  7412. }
  7413. }//END FOR CHAdeMO_QUANTITY
  7414. for (int index = 0; index < CCS_QUANTITY; index++)
  7415. {
  7416. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7417. {
  7418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7419. goto end;
  7420. }
  7421. }//END FOR CCS_QUANTITY
  7422. for (int index = 0; index < GB_QUANTITY; index++)
  7423. {
  7424. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7425. {
  7426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7427. goto end;
  7428. }
  7429. }// END FOR GB_QUANTITY
  7430. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7431. {
  7432. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7433. {
  7434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7435. goto end;
  7436. }
  7437. }// END FOR GENERAL_GUN_QUANTITY
  7438. for (int index = 0; index < AC_QUANTITY; index++)
  7439. {
  7440. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7441. {
  7442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7443. goto end;
  7444. }
  7445. }//END FOR AC_QUANTITY
  7446. }//END FOR AvailabilityTypeStr[Operative]
  7447. end:
  7448. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7449. {
  7450. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7451. }
  7452. else
  7453. {
  7454. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7455. }
  7456. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7457. {
  7458. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7459. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7460. }
  7461. else if(gunIndex == 0)
  7462. {
  7463. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7464. {
  7465. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7466. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7467. }
  7468. }
  7469. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7470. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7471. return result;
  7472. }
  7473. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7474. {
  7475. mtrace();
  7476. int result = FAIL;
  7477. char keystr[40]={0};
  7478. char valuestr[256]={0};
  7479. char comfirmstr[20]={0};
  7480. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7481. json_object *ChangeConfiguration;
  7482. ChangeConfiguration = json_tokener_parse(payload);
  7483. if(!is_error(ChangeConfiguration))
  7484. {
  7485. // Required data
  7486. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7487. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7488. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7489. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7490. }
  7491. json_object_put(ChangeConfiguration);
  7492. if((uuid==NULL) || (payload ==NULL) )
  7493. {
  7494. DEBUG_ERROR("Payload is null\n");
  7495. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7496. }
  7497. else
  7498. {
  7499. int status = setKeyValue(keystr, valuestr);
  7500. switch(status)
  7501. {
  7502. case ConfigurationStatus_Accepted:
  7503. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7504. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7505. StoreConfigurationTable();
  7506. break;
  7507. case RebootRequired:
  7508. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7509. StoreConfigurationTable();
  7510. break;
  7511. case NotSupported:
  7512. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7513. break;
  7514. case ConfigurationStatus_Rejected:
  7515. default:
  7516. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7517. break;
  7518. }
  7519. }
  7520. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7521. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7522. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7523. {
  7524. ChageWebSocketPingInterval(atoi(valuestr));
  7525. }
  7526. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7527. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7528. {
  7529. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7530. SetOcppConnStatus(FALSE);
  7531. }
  7532. return result;
  7533. }
  7534. int handleClearCacheRequest(char *uuid, char *payload)
  7535. {
  7536. mtrace();
  7537. int result = FAIL;
  7538. char comfirmstr[20];
  7539. char rmFileCmd[100]={0};
  7540. struct stat stats;
  7541. DEBUG_INFO("handleClearCacheRequest...\n");
  7542. stat("/Storage/OCPP", &stats);
  7543. // Check for directory existence
  7544. if (S_ISDIR(stats.st_mode) == 1)
  7545. {}
  7546. else
  7547. {
  7548. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7549. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7550. system(rmFileCmd);
  7551. }
  7552. if(OCPP_cleanLocalCache())
  7553. {
  7554. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7555. }
  7556. else
  7557. {
  7558. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7559. }
  7560. sendClearCacheConfirmation(uuid, comfirmstr);
  7561. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7562. return result;
  7563. }
  7564. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7565. {
  7566. mtrace();
  7567. int result = FAIL;
  7568. int resultRename;
  7569. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7570. char chargingProfilePurposeStr[26]={0};
  7571. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7572. char tempchargingProfilePurposeStr[26]={0};
  7573. char str[100]={0};
  7574. char fname[200]={0};
  7575. char comfirmstr[20]={0};
  7576. char word[1600]={0};
  7577. int clearflag = FALSE;
  7578. int chargingProfileIdIsNULL = FALSE;
  7579. int connectorIsNULL = FALSE;
  7580. int chargingProfilePurposeIsNULL = FALSE;
  7581. int stackLevelIsNULL = FALSE;
  7582. //int GotoEnd = FALSE;
  7583. FILE *fptr1, *fptr2;
  7584. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7585. int n_chargingProfile=0;
  7586. int isEmptyFile = FALSE;
  7587. char sLineWord[1600]={0};
  7588. char chargingProfiles[10][100]={0};
  7589. int ChargeProfileCount = 0;
  7590. int ch;
  7591. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7592. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7593. json_object *ClearChargingProfile;
  7594. ClearChargingProfile = json_tokener_parse(payload);
  7595. if(!is_error(ClearChargingProfile))
  7596. {
  7597. // Optional data
  7598. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7599. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7600. else
  7601. chargingProfileIdIsNULL = TRUE;
  7602. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7603. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7604. else
  7605. connectorIsNULL = TRUE;
  7606. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7607. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7608. else
  7609. chargingProfilePurposeIsNULL = TRUE;
  7610. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7611. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7612. else
  7613. stackLevelIsNULL = TRUE;
  7614. }
  7615. json_object_put(ClearChargingProfile);
  7616. if(connectorIsNULL == FALSE)
  7617. {
  7618. switch(connectorIdInt)
  7619. {
  7620. case 0:
  7621. if(chargingProfilePurposeIsNULL == TRUE)
  7622. {
  7623. int l = 0;
  7624. strcpy(fname, ChargePointMaxProfile_JSON);
  7625. if((access(fname,F_OK))!=-1)
  7626. {
  7627. strcpy(chargingProfiles[l], fname);
  7628. l = l + 1;
  7629. }
  7630. strcpy(fname, TxDefaultProfile_0_JSON);
  7631. if((access(fname,F_OK))!=-1)
  7632. {
  7633. strcpy(chargingProfiles[l], fname);
  7634. l = l + 1;
  7635. }
  7636. ChargeProfileCount = l;
  7637. }
  7638. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7639. {
  7640. strcpy(fname, ChargePointMaxProfile_JSON);
  7641. if((access(fname,F_OK))!=-1)
  7642. {
  7643. strcpy(chargingProfiles[0], fname);
  7644. ChargeProfileCount = 1;
  7645. }
  7646. }
  7647. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7648. {
  7649. strcpy(fname, TxDefaultProfile_0_JSON);
  7650. if((access(fname,F_OK))!=-1)
  7651. {
  7652. strcpy(chargingProfiles[0], fname);
  7653. ChargeProfileCount = 1;
  7654. }
  7655. }
  7656. break;
  7657. default:
  7658. if(chargingProfilePurposeIsNULL == TRUE)
  7659. {
  7660. int m = 0;
  7661. memset(fname, 0, ARRAY_SIZE(fname));
  7662. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7663. if((access(fname,F_OK))!=-1)
  7664. {
  7665. strcpy(chargingProfiles[m], fname);
  7666. m = m + 1;
  7667. }
  7668. memset(fname, 0, ARRAY_SIZE(fname));
  7669. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7670. if((access(fname,F_OK))!=-1)
  7671. {
  7672. strcpy(chargingProfiles[m], fname);
  7673. m = m + 1;
  7674. }
  7675. ChargeProfileCount = m;
  7676. }
  7677. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7678. {
  7679. //strcpy(fname, TxDefaultProfile_1_JSON);
  7680. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7681. if((access(fname,F_OK))!=-1)
  7682. {
  7683. strcpy(chargingProfiles[0], fname);
  7684. ChargeProfileCount = 1;
  7685. }
  7686. }
  7687. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7688. {
  7689. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7690. if((access(fname,F_OK))!=-1)
  7691. {
  7692. strcpy(chargingProfiles[0], fname);
  7693. ChargeProfileCount = 1;
  7694. }
  7695. //strcpy(fname, TxProfile_1_JSON);
  7696. }
  7697. //strcpy(fname, ChargePointMaxProfile_JSON );
  7698. break;
  7699. }
  7700. }
  7701. else // Check all Charging Profiles
  7702. {
  7703. int i = 0;
  7704. char fnametemp[200]={0};
  7705. ChargeProfileCount = 0;
  7706. //Check ChargePointMaxProfile.json exit
  7707. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7708. {
  7709. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7710. i = i + 1;
  7711. }
  7712. //Check TxDefaultProfile_0.json exit
  7713. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7714. {
  7715. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7716. i = i + 1;
  7717. }
  7718. //Check TxDefaultProfile_%d.json
  7719. for(int j=1; j <= gunTotalNumber; j++)
  7720. {
  7721. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7722. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7723. if((access(fnametemp,F_OK))!=-1)
  7724. {
  7725. strcpy(chargingProfiles[i], fnametemp);
  7726. i = i + 1;
  7727. }
  7728. }
  7729. //Check TxProfile_%d.json
  7730. for(int j=1; j <= gunTotalNumber; j++)
  7731. {
  7732. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7733. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7734. if((access(fnametemp,F_OK))!=-1)
  7735. {
  7736. strcpy(chargingProfiles[i], fnametemp);
  7737. i = i + 1;
  7738. }
  7739. }
  7740. ChargeProfileCount = i;
  7741. }// End connectorIsNULL is TRUE
  7742. if(ChargeProfileCount == 0)
  7743. {
  7744. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7745. goto end;
  7746. }
  7747. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7748. {
  7749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7750. goto end;
  7751. }
  7752. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7753. {
  7754. memset(str, 0, ARRAY_SIZE(str));
  7755. // clear temp file
  7756. sprintf(str,"rm -f %s",temp);
  7757. system(str);
  7758. for(int k=0; k < ChargeProfileCount; k++)
  7759. {
  7760. memset(str, 0, ARRAY_SIZE(str));
  7761. //clear file in C
  7762. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7763. system(str);
  7764. }
  7765. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7766. goto end;
  7767. }
  7768. else if(connectorIsNULL == TRUE)
  7769. {
  7770. for(int k=0; k < ChargeProfileCount; k++)
  7771. {
  7772. fptr1 = fopen(chargingProfiles[k], "r");
  7773. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7774. //Check Charging Profile Count
  7775. while(fscanf(fptr1, "%s", word) != EOF)
  7776. {
  7777. //DEBUG_INFO("word=%s\n",word);
  7778. if(strstr(word, "chargingProfileId")!= NULL)
  7779. {
  7780. //DEBUG_INFO("test chargingProfileId \n");
  7781. n_chargingProfile = n_chargingProfile + 1;
  7782. //DEBUG_INFO("chargingProfileId Found\n");
  7783. }
  7784. }
  7785. rewind(fptr1);
  7786. //search Charging Profile Element
  7787. //int i= 0;
  7788. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7789. {
  7790. json_object *tmpProfilee;
  7791. tmpProfilee = json_tokener_parse(sLineWord);
  7792. if(!is_error(tmpProfilee))
  7793. {
  7794. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7795. {
  7796. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7797. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7798. }
  7799. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7800. {
  7801. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7802. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7803. }
  7804. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7805. {
  7806. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7807. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7808. }
  7809. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7810. {
  7811. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7812. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7813. }
  7814. }
  7815. json_object_put(tmpProfilee);
  7816. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7817. {
  7818. //------- not write to fptr2-------//
  7819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7820. //clearflag = TRUE;
  7821. }
  7822. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7823. {
  7824. //------- not write to fptr2-------//
  7825. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7826. }
  7827. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7828. {
  7829. //------- not write to fptr2-------//
  7830. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7831. }
  7832. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7833. {
  7834. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7835. }
  7836. else
  7837. {
  7838. fprintf(fptr2, sLineWord);//writing data into file
  7839. }
  7840. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7841. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7842. if(clearflag == TRUE)
  7843. {
  7844. fclose(fptr1);
  7845. fclose(fptr2);
  7846. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7847. system(str);
  7848. // clear temp file
  7849. sprintf(str,"rm -f %s",temp);
  7850. system(str);
  7851. }
  7852. else
  7853. {
  7854. fclose(fptr1);
  7855. fclose(fptr2);
  7856. memset(str, 0, ARRAY_SIZE(str));
  7857. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7858. system(str);
  7859. resultRename = rename(temp, chargingProfiles[k]);
  7860. if(resultRename == 0)
  7861. {
  7862. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7863. }
  7864. else
  7865. {
  7866. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7867. }
  7868. if(comfirmstr[0]== 0)
  7869. {
  7870. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7871. }
  7872. //Check chargingProfile is empty file
  7873. /*------ Read the file ----------------*/
  7874. fptr1=fopen(chargingProfiles[k],"r");
  7875. ch=fgetc(fptr1);
  7876. rewind(fptr1);
  7877. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7878. if(ch!=EOF)
  7879. {
  7880. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7881. {
  7882. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7883. if(sLineWord[0]=='\0')
  7884. {
  7885. isEmptyFile = TRUE;
  7886. break;
  7887. }
  7888. else
  7889. {
  7890. isEmptyFile = FALSE;
  7891. break;
  7892. }
  7893. }
  7894. }
  7895. else
  7896. isEmptyFile = TRUE;
  7897. fclose(fptr1);
  7898. if(isEmptyFile == TRUE)
  7899. {
  7900. memset(str, 0, ARRAY_SIZE(str));
  7901. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7902. system(str);
  7903. }
  7904. }
  7905. }// End of while(int k=0; k < ChargePointCount; k++)
  7906. }
  7907. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7908. {
  7909. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7910. for(int k=0; k < ChargeProfileCount; k++)
  7911. {
  7912. fptr1 = fopen(chargingProfiles[k], "r");
  7913. fptr2 = fopen(temp, "w+");
  7914. //Check Charging Profile Count
  7915. while(fscanf(fptr1, "%s", word) != EOF)
  7916. {
  7917. //DEBUG_INFO("word=%s\n",word);
  7918. if(strstr(word, "chargingProfileId")!= NULL)
  7919. {
  7920. n_chargingProfile = n_chargingProfile + 1;
  7921. }
  7922. }
  7923. rewind(fptr1);
  7924. //search Charging Profile Element
  7925. //int i= 0;
  7926. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7927. {
  7928. json_object *tmpProfilee;
  7929. tmpProfilee = json_tokener_parse(sLineWord);
  7930. if(!is_error(tmpProfilee))
  7931. {
  7932. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7933. {
  7934. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7935. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7936. }
  7937. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7938. {
  7939. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7940. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7941. }
  7942. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7943. {
  7944. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7945. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7946. }
  7947. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7948. {
  7949. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7950. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7951. }
  7952. }
  7953. json_object_put(tmpProfilee);
  7954. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7955. {
  7956. //------- not write to fptr2-------//
  7957. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7958. //clearflag = TRUE;
  7959. }
  7960. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7961. {
  7962. //------- not write to fptr2-------//
  7963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7964. }
  7965. else if(stackLevelIsNULL == TRUE)
  7966. {
  7967. //Clear Whole File
  7968. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7969. clearflag = TRUE;
  7970. break;
  7971. }
  7972. else
  7973. {
  7974. fprintf(fptr2, sLineWord);//writing data into file
  7975. }
  7976. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7977. }
  7978. if(clearflag == TRUE)
  7979. {
  7980. fclose(fptr1);
  7981. fclose(fptr2);
  7982. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7983. system(str);
  7984. // clear temp file
  7985. sprintf(str,"rm -f %s",temp);
  7986. system(str);
  7987. }
  7988. else
  7989. {
  7990. fclose(fptr1);
  7991. fclose(fptr2);
  7992. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7993. system(str);
  7994. resultRename = rename(temp, chargingProfiles[k]);
  7995. if(resultRename == 0)
  7996. {
  7997. DEBUG_INFO("File ChargingProfile renamed successfully");
  7998. }
  7999. else
  8000. {
  8001. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8002. }
  8003. if(comfirmstr[0]== 0)
  8004. {
  8005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8006. }
  8007. //Check chargingProfile is empty file
  8008. /*------ Read the file ----------------*/
  8009. fptr1=fopen(chargingProfiles[k],"r");
  8010. ch=fgetc(fptr1);
  8011. rewind(fptr1);
  8012. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8013. if(ch!=EOF)
  8014. {
  8015. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8016. {
  8017. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8018. if(sLineWord[0]=='\0')
  8019. {
  8020. isEmptyFile = TRUE;
  8021. break;
  8022. }
  8023. else
  8024. {
  8025. isEmptyFile = FALSE;
  8026. break;
  8027. }
  8028. }
  8029. }
  8030. else
  8031. isEmptyFile = TRUE;
  8032. fclose(fptr1);
  8033. if(isEmptyFile == TRUE)
  8034. {
  8035. memset(str, 0, ARRAY_SIZE(str));
  8036. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8037. system(str);
  8038. }
  8039. /*------- End of reading ---------------*/
  8040. }
  8041. } // while(int k=0; k < ChargeProfileCount; k++)
  8042. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8043. end:
  8044. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8045. {
  8046. if(connectorIdInt == 0)
  8047. {
  8048. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8049. {
  8050. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8051. }
  8052. }
  8053. else
  8054. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8055. }
  8056. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8057. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8058. return result;
  8059. }
  8060. void createFirmwareVersionByDataTransfer(void)
  8061. {
  8062. json_object *FirmwareDataTransfer = json_object_new_object();
  8063. // AC & DC model
  8064. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8065. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8066. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8067. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8068. // DC model
  8069. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8070. {
  8071. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8072. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8073. (gunType[3] != GUN_TYPE_UNKNOWN))
  8074. {
  8075. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8076. }
  8077. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8078. {
  8079. // DS DM DW
  8080. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8081. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8082. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8083. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8084. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8085. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8086. }
  8087. else
  8088. {
  8089. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8090. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8091. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8092. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8094. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8095. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8096. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8097. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8098. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8099. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8100. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8101. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8102. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8103. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8104. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8105. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8106. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8107. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8108. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8109. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8110. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8111. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8112. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8113. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8114. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8115. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8116. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8117. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8118. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8119. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8120. }
  8121. }
  8122. // 4G model
  8123. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8124. {
  8125. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8126. }
  8127. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8128. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8129. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8130. json_object_put(FirmwareDataTransfer);
  8131. }
  8132. int handleDataTransferRequest(char *uuid, char *payload)
  8133. {
  8134. mtrace();
  8135. json_object *response = json_object_new_object();
  8136. int result = FAIL;
  8137. char tempvendorId[255]={0};
  8138. char tempmessageId[50]={0};
  8139. char tempdata[512]={0};
  8140. char message[2048]={0};
  8141. DEBUG_INFO("handleDataTransferRequest...\n");
  8142. if((uuid != NULL) && (payload != NULL))
  8143. {
  8144. json_object *DataTransfer;
  8145. DataTransfer = json_tokener_parse(payload);
  8146. if(!is_error(DataTransfer))
  8147. {
  8148. // Required data
  8149. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8150. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8151. // Optional data
  8152. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8153. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8154. if(json_object_object_get(DataTransfer, "data") != NULL)
  8155. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8156. result = PASS;
  8157. }
  8158. json_object_put(DataTransfer);
  8159. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8160. {
  8161. // Send all moudle firmware version on EVSE
  8162. createFirmwareVersionByDataTransfer();
  8163. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8164. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8165. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8166. json_object_put(response);
  8167. }
  8168. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8169. {
  8170. system("/usr/bin/run_tmate_restart.sh &");
  8171. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8172. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8173. json_object_put(response);
  8174. }
  8175. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8176. {
  8177. json_object *data;
  8178. data = json_tokener_parse(tempdata);
  8179. if(!is_error(data))
  8180. {
  8181. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8182. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8183. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8184. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8185. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8186. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8187. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8188. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8189. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8190. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8191. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8192. }
  8193. else
  8194. {
  8195. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8196. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8197. }
  8198. json_object_put(data);
  8199. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8200. json_object_put(response);
  8201. }
  8202. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8203. {
  8204. json_object *data;
  8205. data = json_tokener_parse(tempdata);
  8206. if(!is_error(data))
  8207. {
  8208. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8209. if(json_object_object_get(data, "idToken") != NULL)
  8210. {
  8211. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8212. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8213. }
  8214. if(json_object_object_get(data, "price") != NULL)
  8215. {
  8216. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8217. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8218. }
  8219. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8220. }
  8221. else
  8222. {
  8223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8225. }
  8226. json_object_put(data);
  8227. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8228. json_object_put(response);
  8229. }
  8230. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8231. {
  8232. json_object *data;
  8233. data = json_tokener_parse(tempdata);
  8234. if(!is_error(data))
  8235. {
  8236. if(json_object_object_get(data, "txId") != NULL)
  8237. {
  8238. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8239. for(int idx = 0;idx<gunTotalNumber;idx++)
  8240. {
  8241. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8242. {
  8243. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8244. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8245. if(json_object_object_get(data, "description") != NULL)
  8246. {
  8247. // California pricing V1.0
  8248. DEBUG_INFO("California pricing V1.0\n");
  8249. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8250. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8251. }
  8252. else
  8253. {
  8254. // California pricing V1.1
  8255. DEBUG_INFO("California pricing V1.1\n");
  8256. if(json_object_object_get(data, "timestamp") != NULL)
  8257. {
  8258. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8259. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8260. }
  8261. if(json_object_object_get(data, "meterValue") != NULL)
  8262. {
  8263. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8264. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8265. }
  8266. if(json_object_object_get(data, "cost") != NULL)
  8267. {
  8268. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8269. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8270. }
  8271. if(json_object_object_get(data, "state") != NULL)
  8272. {
  8273. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8274. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8275. }
  8276. if(json_object_object_get(data, "chargingPrice") != NULL)
  8277. {
  8278. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8279. {
  8280. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8281. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8282. }
  8283. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8284. {
  8285. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8286. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8287. }
  8288. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8289. {
  8290. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8291. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8292. }
  8293. }
  8294. if(json_object_object_get(data, "idlePrice") != NULL)
  8295. {
  8296. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8297. {
  8298. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8299. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8300. }
  8301. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8302. {
  8303. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8304. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8305. }
  8306. }
  8307. if(json_object_object_get(data, "nextPeriod") != NULL)
  8308. {
  8309. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8310. {
  8311. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8312. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8313. }
  8314. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8315. {
  8316. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8317. {
  8318. 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")));
  8319. 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"));
  8320. }
  8321. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8322. {
  8323. 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")));
  8324. 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"));
  8325. }
  8326. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8327. {
  8328. 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")));
  8329. 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"));
  8330. }
  8331. }
  8332. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8333. {
  8334. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8335. {
  8336. 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")));
  8337. 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"));
  8338. }
  8339. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8340. {
  8341. 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")));
  8342. 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"));
  8343. }
  8344. }
  8345. }
  8346. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8347. {
  8348. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8349. {
  8350. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8351. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8352. }
  8353. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8354. {
  8355. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8356. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8357. }
  8358. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8359. {
  8360. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8361. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8362. }
  8363. }
  8364. }
  8365. }
  8366. }
  8367. }
  8368. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8369. }
  8370. else
  8371. {
  8372. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8373. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8374. }
  8375. json_object_put(data);
  8376. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8377. json_object_put(response);
  8378. }
  8379. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8380. {
  8381. json_object *data;
  8382. data = json_tokener_parse(tempdata);
  8383. if(!is_error(data))
  8384. {
  8385. if(json_object_object_get(data, "txId") != NULL)
  8386. {
  8387. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8388. for(int idx = 0;idx<gunTotalNumber;idx++)
  8389. {
  8390. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8391. {
  8392. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8393. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8394. if(json_object_object_get(data, "description") != NULL)
  8395. {
  8396. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8397. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8398. }
  8399. }
  8400. }
  8401. }
  8402. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8403. }
  8404. else
  8405. {
  8406. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8407. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8408. }
  8409. json_object_put(data);
  8410. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8411. json_object_put(response);
  8412. }
  8413. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8414. {
  8415. json_object *data;
  8416. data = json_tokener_parse(tempdata);
  8417. if(!is_error(data))
  8418. {
  8419. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8420. if(json_object_object_get(data, "Content_Type") != NULL)
  8421. {
  8422. 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))
  8423. {
  8424. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8425. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8426. {
  8427. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8428. }
  8429. }
  8430. else
  8431. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8432. }
  8433. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8434. }
  8435. else
  8436. {
  8437. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8438. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8439. }
  8440. json_object_put(data);
  8441. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8442. json_object_put(response);
  8443. }
  8444. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8445. {
  8446. json_object *data;
  8447. data = json_tokener_parse(tempdata);
  8448. if(!is_error(data))
  8449. {
  8450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8451. if(json_object_object_get(data, "Page_Index") != NULL)
  8452. {
  8453. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8454. }
  8455. if(json_object_object_get(data, "Duration") != NULL)
  8456. {
  8457. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8458. }
  8459. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8460. }
  8461. else
  8462. {
  8463. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8464. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8465. }
  8466. json_object_put(data);
  8467. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8468. json_object_put(response);
  8469. }
  8470. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8471. {
  8472. json_object *data;
  8473. data = json_tokener_parse(tempdata);
  8474. if(!is_error(data))
  8475. {
  8476. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8477. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8478. {
  8479. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8480. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8481. else
  8482. {
  8483. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8484. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8485. }
  8486. }
  8487. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8488. {
  8489. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8490. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8491. else
  8492. {
  8493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8495. }
  8496. }
  8497. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8498. {
  8499. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8500. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8501. else
  8502. {
  8503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8504. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8505. }
  8506. }
  8507. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8508. {
  8509. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8510. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8511. else
  8512. {
  8513. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8514. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8515. }
  8516. }
  8517. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8518. {
  8519. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8520. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8521. else
  8522. {
  8523. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8524. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8525. }
  8526. }
  8527. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8528. {
  8529. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8530. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8531. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8532. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8533. else
  8534. {
  8535. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8536. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8537. }
  8538. }
  8539. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8540. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8541. }
  8542. else
  8543. {
  8544. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8545. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8546. }
  8547. json_object_put(data);
  8548. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8549. json_object_put(response);
  8550. }
  8551. else
  8552. {
  8553. // Can not find valid message id
  8554. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8555. }
  8556. }
  8557. else
  8558. {
  8559. // Payload is null
  8560. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8561. }
  8562. LWS_Send(message);
  8563. return result;
  8564. }
  8565. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8566. {
  8567. mtrace();
  8568. int result = FAIL;
  8569. int connectorIdInt, durationInt;
  8570. char chargingRateUnitStr[4]={0};
  8571. char comfirmstr[20];
  8572. int confirmPeriods = 0;
  8573. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8574. json_object *GetCompositeSchedule;
  8575. GetCompositeSchedule = json_tokener_parse(payload);
  8576. if(!is_error(GetCompositeSchedule))
  8577. {
  8578. // Required data
  8579. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8580. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8581. else
  8582. connectorIdInt = -1;
  8583. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8584. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8585. else
  8586. durationInt = 86400;
  8587. // Optional data
  8588. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8589. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8590. }
  8591. json_object_put(GetCompositeSchedule);
  8592. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8593. if((connectorIdInt == 0) ||
  8594. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8595. {
  8596. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8597. struct StructChargingProfile tmpProfile[1];
  8598. if(strstr(chargingRateUnitStr, "W") != NULL)
  8599. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8600. else
  8601. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8602. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8603. {
  8604. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8605. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8606. }
  8607. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8608. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8609. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8610. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8611. {
  8612. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8613. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8614. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8615. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8616. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8617. {
  8618. confirmPeriods = idx;
  8619. break;
  8620. }
  8621. }
  8622. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8623. {
  8624. confirmPeriods += 1;
  8625. }
  8626. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8627. }
  8628. else
  8629. {
  8630. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8631. }
  8632. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8633. return result;
  8634. }
  8635. int handleGetConfigurationRequest(char *uuid, char *payload)
  8636. {
  8637. mtrace();
  8638. int result = FAIL;
  8639. int MaxKeySupported = 0;
  8640. int n_keys = 0;
  8641. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8642. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8643. json_object *GetConfiguration;
  8644. GetConfiguration = json_tokener_parse(payload);
  8645. if(!is_error(GetConfiguration))
  8646. {
  8647. // Optional data
  8648. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8649. {
  8650. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8651. {
  8652. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8653. n_keys = idx + 1;
  8654. }
  8655. }
  8656. }
  8657. json_object_put(GetConfiguration);
  8658. UnknownKeynum = 0;
  8659. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8660. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8661. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8662. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8663. if(n_keys != 0)
  8664. {
  8665. for(int i=0;i<n_keys;i++)
  8666. {
  8667. getKeyValue(requestKey[i]);
  8668. }
  8669. }
  8670. else
  8671. {
  8672. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8673. getKeyValue("");
  8674. }
  8675. processUnkownKey();
  8676. sendGetConfigurationConfirmation(uuid);
  8677. return result;
  8678. }
  8679. static char fnamePlusPath[100]={0};
  8680. static char fnamePWithNoPath[60]={0};
  8681. void checkUploadLog(void)
  8682. {
  8683. FILE *fp;
  8684. /* Open the command for reading. */
  8685. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8686. if (fp == NULL) {
  8687. DEBUG_WARN("Failed to run command\n" );
  8688. exit(1);
  8689. }
  8690. int ftppathlen = 0;
  8691. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8692. int i = 0;
  8693. /* Read the output a line at a time - output it. */
  8694. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8695. if(i==0)
  8696. {
  8697. ftppathlen = strlen(fnamePlusPath);
  8698. DEBUG_INFO("%s\n", fnamePlusPath);
  8699. fnamePlusPath[ftppathlen]='\0';
  8700. break;
  8701. }
  8702. i= i+1;
  8703. }
  8704. /* close */
  8705. pclose(fp);
  8706. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8707. {
  8708. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8709. {
  8710. fnamePlusPath[k]='\0';
  8711. }
  8712. }
  8713. i=1;
  8714. //char fname[60]={0};
  8715. while(i < ftppathlen)
  8716. {
  8717. int len=ftppathlen-i;
  8718. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8719. {
  8720. DEBUG_INFO("compare '/' all right\n");
  8721. break;
  8722. }
  8723. i=i+1;
  8724. }
  8725. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8726. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8727. fnamePWithNoPath[i+1] = '\0';
  8728. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8729. {
  8730. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8731. {
  8732. fnamePWithNoPath[j]='\0';
  8733. }
  8734. }
  8735. FILE* fp1 = fopen(fnamePlusPath, "r");
  8736. if (fp1)
  8737. {
  8738. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8739. // file exists
  8740. fclose(fp1);
  8741. }
  8742. else
  8743. {
  8744. // file doesn't exist
  8745. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8746. }
  8747. }
  8748. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8749. {
  8750. mtrace();
  8751. int result = FAIL;
  8752. time_t CurrentTime;
  8753. struct tm *tm;
  8754. pthread_t th_Status;
  8755. CurrentTime = time(NULL);
  8756. tm = localtime(&CurrentTime);
  8757. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8758. 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);
  8759. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8760. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8761. return result;
  8762. }
  8763. void* GetDiagnosticsProcess(void* data)
  8764. {
  8765. pthread_detach(pthread_self());
  8766. mtrace();
  8767. int retriesInt=0, retryIntervalInt=0;
  8768. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8769. 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};
  8770. int port=0;
  8771. int isSuccess = FALSE;
  8772. char cmdBuf[2048];
  8773. struct tm *tmNow;
  8774. time_t CurrentTime;
  8775. struct tm tmStart;
  8776. struct tm tmStop;
  8777. CurrentTime = time(NULL);
  8778. tmNow=localtime(&CurrentTime);
  8779. uint16_t targetYear, targetMonth;
  8780. json_object *GetDiagnostics;
  8781. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8782. GetDiagnostics = json_tokener_parse(data);
  8783. if(!is_error(GetDiagnostics))
  8784. {
  8785. // Required data
  8786. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8787. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8788. // Optional data
  8789. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8790. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8791. else
  8792. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8793. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8794. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8795. else
  8796. retryIntervalInt = 30;
  8797. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8798. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8799. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8800. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8801. }
  8802. json_object_put(GetDiagnostics);
  8803. // Pack log to compress file
  8804. 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) &&
  8805. (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))
  8806. {
  8807. // Pack system log
  8808. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8809. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8810. targetYear = tmStart.tm_year;
  8811. targetMonth = tmStart.tm_mon;
  8812. do
  8813. {
  8814. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8815. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8816. if(targetMonth+1>=13)
  8817. {
  8818. targetYear += 1;
  8819. targetMonth = 1;
  8820. }
  8821. else
  8822. {
  8823. targetMonth += 1;
  8824. }
  8825. }while((targetYear < (tmNow->tm_year+1900)) ||
  8826. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8827. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8828. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8829. system(cmdBuf);
  8830. // Pack charging & event log
  8831. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8832. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8833. targetYear = tmStart.tm_year;
  8834. targetMonth = tmStart.tm_mon;
  8835. do
  8836. {
  8837. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8838. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8839. if(targetMonth+1>=13)
  8840. {
  8841. targetYear += 1;
  8842. targetMonth = 1;
  8843. }
  8844. else
  8845. {
  8846. targetMonth += 1;
  8847. }
  8848. }while((targetYear < (tmNow->tm_year+1900)) ||
  8849. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8850. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8851. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8852. system(cmdBuf);
  8853. // Combine log file
  8854. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8855. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8856. }
  8857. else
  8858. {
  8859. system("exec /root/logPackTools 'log' 6");
  8860. }
  8861. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8862. system(cmdBuf);
  8863. checkUploadLog();
  8864. //****************location*******************/
  8865. if(strcmp(locationstr,"")==0)
  8866. {
  8867. DEBUG_INFO("location is <Empty>!\n");
  8868. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8869. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8870. goto end;
  8871. }
  8872. memset(protocol, 0, ARRAY_SIZE(protocol));
  8873. memset(user, 0, ARRAY_SIZE(user) );
  8874. memset(password, 0, ARRAY_SIZE(password));
  8875. memset(host, 0, ARRAY_SIZE(host));
  8876. memset(path, 0, ARRAY_SIZE(path));
  8877. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8878. memset(host1, 0, ARRAY_SIZE(host1));
  8879. memset(path1, 0, ARRAY_SIZE(path1));
  8880. /*location: ftp://user:password@host:port/path*/
  8881. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8882. if((access(fnamePlusPath,F_OK))!=-1)
  8883. {
  8884. DEBUG_INFO("fnamePlusPath exist.\n");
  8885. }
  8886. else
  8887. {
  8888. DEBUG_INFO("fnamePlusPath not exist!\n");
  8889. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8890. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8891. goto end;
  8892. }
  8893. if(strchr(locationstr,'@')==NULL)
  8894. {
  8895. sscanf(locationstr,
  8896. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8897. protocol, host, &port, path);
  8898. strcpy(user,"anonymous");
  8899. strcpy(password,"");
  8900. }
  8901. else
  8902. {
  8903. //DEBUG_INFO("pch=%s\n", pch);
  8904. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8905. protocol, user, password, host, &port, path);
  8906. }
  8907. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8908. {
  8909. DEBUG_INFO("protocol is not ftp/http ! \n");
  8910. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8911. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8912. goto end;
  8913. }
  8914. if(strncmp(locationstr,"http", 4) == 0)
  8915. {
  8916. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8917. sprintf(ftppath,"/%s", path);
  8918. do
  8919. {
  8920. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8921. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8922. sleep(3);
  8923. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8924. if(!isSuccess)
  8925. {
  8926. DEBUG_INFO("Diagnostics fail.\n");
  8927. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8928. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8929. sleep(retryIntervalInt);
  8930. }
  8931. else
  8932. {
  8933. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8934. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8935. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8936. }
  8937. retriesInt--;
  8938. }while((isSuccess == 0)&&(retriesInt >= 0));
  8939. }
  8940. else
  8941. {
  8942. sscanf(host,"%[^/]%s",host1, path1);
  8943. if(strlen(path) > 0)
  8944. sprintf(ftppath,"/%s", path);
  8945. else
  8946. sprintf(ftppath,"/%s", path1);
  8947. int ftppathlen=strlen(ftppath);
  8948. int i=1;
  8949. char filenametemp[50];
  8950. while(i < ftppathlen)
  8951. {
  8952. int len=ftppathlen-i;
  8953. if(ftppath[len]== 47) // '/' ascll code: 47
  8954. {
  8955. DEBUG_INFO("find '/' all right\n");
  8956. break;
  8957. }
  8958. i=i+1;
  8959. }
  8960. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8961. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8962. filenametemp[i+1] = 0;
  8963. if(port == 0)
  8964. port = 21;
  8965. do
  8966. {
  8967. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8968. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8969. sleep(3);
  8970. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8971. if(!isSuccess)
  8972. {
  8973. DEBUG_INFO("Diagnostics fail.\n");
  8974. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8975. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8976. sleep(retryIntervalInt);
  8977. }
  8978. else
  8979. {
  8980. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8981. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8982. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8983. }
  8984. retriesInt--;
  8985. }while((!isSuccess)&&(retriesInt >= 0));
  8986. }
  8987. end:
  8988. system("rm -f /mnt/*");
  8989. sleep(5);
  8990. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8991. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8992. pthread_exit(NULL);
  8993. }
  8994. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8995. {
  8996. mtrace();
  8997. int result = FAIL;
  8998. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8999. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9000. {
  9001. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9002. locallistVersion = -1;
  9003. }
  9004. else
  9005. {
  9006. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9007. OCPP_getListVerion();
  9008. }
  9009. //from db.OCPP_getListVerion
  9010. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9011. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9012. sendGetLocalListVersionConfirmation(uuid,"");
  9013. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9014. return result;
  9015. }
  9016. int handleRemoteStartRequest(char *uuid, char *payload)
  9017. {
  9018. mtrace();
  9019. int result = FAIL;
  9020. int connectorIdInt=-1;
  9021. int tempIndex = 0;
  9022. int connectorIdIsNULL, chargingProfileIsNULL;
  9023. char comfirmstr[20]={0};
  9024. char cmdBuf[512];
  9025. json_object *RemoteStartTransaction;
  9026. FILE *fp;
  9027. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9028. if(server_pending == TRUE)
  9029. {
  9030. return 0;
  9031. }
  9032. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9033. RemoteStartTransaction = json_tokener_parse(payload);
  9034. if(!is_error(RemoteStartTransaction))
  9035. {
  9036. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9037. {
  9038. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9039. }
  9040. else
  9041. {
  9042. connectorIdIsNULL = TRUE;
  9043. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9044. {
  9045. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9046. {
  9047. connectorIdIsNULL = FALSE;
  9048. connectorIdInt = (gun_index+1);
  9049. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9050. break;
  9051. }
  9052. }
  9053. }
  9054. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9055. {
  9056. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9057. // Required data
  9058. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9059. // Optional data
  9060. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9061. {
  9062. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9063. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9064. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9065. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9066. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9067. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9068. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9069. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9070. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9071. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9072. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9073. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9074. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9075. {
  9076. 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")));
  9077. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9078. 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"));
  9079. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9080. 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"));
  9081. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9082. 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")));
  9083. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9084. {
  9085. 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++)
  9086. {
  9087. 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"));
  9088. 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"));
  9089. 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)
  9090. 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"));
  9091. }
  9092. }
  9093. }
  9094. }
  9095. else
  9096. {
  9097. chargingProfileIsNULL = TRUE;
  9098. }
  9099. }
  9100. }
  9101. else
  9102. {
  9103. connectorIdIsNULL = TRUE;
  9104. }
  9105. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9106. {
  9107. DEBUG_WARN("Connector id is NULL\n.");
  9108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9109. goto end;
  9110. }
  9111. /*
  9112. enum _SYSTEM_STATUS
  9113. {
  9114. S_BOOTING = 0,
  9115. S_IDLE, = 1
  9116. S_AUTHORIZING, = 2
  9117. S_REASSIGN_CHECK, = 3
  9118. S_REASSIGN, = 4
  9119. S_PRECHARGE, = 5
  9120. S_PREPARING_FOR_EV, = 6
  9121. S_PREPARING_FOR_EVSE, = 7
  9122. S_CHARGING, = 8
  9123. S_TERMINATING, = 9
  9124. S_COMPLETE, = 10
  9125. S_ALARM, = 11
  9126. S_FAULT = 12
  9127. }
  9128. */
  9129. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9130. {
  9131. //check Transaction active
  9132. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9133. {
  9134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9135. {
  9136. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9137. }
  9138. else
  9139. {
  9140. tempIndex = connectorIdInt -1;
  9141. }
  9142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9143. {
  9144. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9145. {
  9146. 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))
  9147. {
  9148. //Reserved
  9149. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9150. }
  9151. 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))
  9152. {
  9153. //Reserved
  9154. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9155. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9156. goto end;
  9157. }
  9158. else
  9159. {
  9160. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9161. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9162. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9163. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9164. {
  9165. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9167. goto end;
  9168. }
  9169. }//END FOR ELSE
  9170. }
  9171. }// END FOR CHAdeMO_QUANTITY
  9172. }
  9173. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9174. {
  9175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9176. {
  9177. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9178. }
  9179. else
  9180. {
  9181. tempIndex = connectorIdInt -1;
  9182. }
  9183. for (int index = 0; index < CCS_QUANTITY; index++)
  9184. {
  9185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9186. {
  9187. 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))
  9188. {
  9189. //Reserved
  9190. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9191. }
  9192. 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))
  9193. {
  9194. //Reserved
  9195. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9196. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9197. goto end;
  9198. }
  9199. else
  9200. {
  9201. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9202. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9203. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9204. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9205. {
  9206. DEBUG_WARN("CCS connector not allow start\n.");
  9207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9208. goto end;
  9209. }
  9210. }// END FOR ELSE
  9211. }
  9212. }// END FOR CCS_QUANTITY
  9213. }
  9214. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9215. {
  9216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9217. {
  9218. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9219. }
  9220. else
  9221. {
  9222. tempIndex = connectorIdInt -1;
  9223. }
  9224. for (int index = 0; index < GB_QUANTITY; index++)
  9225. {
  9226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9227. {
  9228. 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))
  9229. {
  9230. //Reserved
  9231. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9232. }
  9233. 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))
  9234. {
  9235. //Reserved
  9236. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9238. goto end;
  9239. }
  9240. else
  9241. {
  9242. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9243. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9244. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9245. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9246. {
  9247. DEBUG_WARN("GB connector not allow start\n.");
  9248. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9249. goto end;
  9250. }
  9251. }// END FOR ELSE
  9252. }
  9253. } // END FOR GB_QUANTITY
  9254. }
  9255. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9256. {
  9257. tempIndex = connectorIdInt -1;
  9258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9259. {
  9260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9261. {
  9262. 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))
  9263. {
  9264. //Reserved
  9265. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9266. }
  9267. 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))
  9268. {
  9269. //Reserved
  9270. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9272. goto end;
  9273. }
  9274. else
  9275. {
  9276. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9277. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9278. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9279. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9280. {
  9281. DEBUG_WARN("GB connector not allow start\n.");
  9282. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9283. goto end;
  9284. }
  9285. }// END FOR ELSE
  9286. }
  9287. } // END FOR GB_QUANTITY
  9288. }
  9289. else
  9290. {
  9291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9292. {
  9293. tempIndex = 2;
  9294. }
  9295. else
  9296. {
  9297. tempIndex = connectorIdInt -1;
  9298. }
  9299. for (int index = 0; index < AC_QUANTITY; index++)
  9300. {
  9301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9302. {
  9303. 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))
  9304. {
  9305. //Reserved
  9306. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9307. }
  9308. 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))
  9309. {
  9310. //Reserved
  9311. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9313. goto end;
  9314. }
  9315. else
  9316. {
  9317. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9318. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9319. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9320. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9321. {
  9322. DEBUG_WARN("AC connector not allow start\n.");
  9323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9324. goto end;
  9325. }
  9326. }//END FOR ELSE
  9327. }
  9328. }// END FOR AC_QUANTITY
  9329. }
  9330. if(chargingProfileIsNULL == FALSE)
  9331. {
  9332. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9333. {
  9334. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9335. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9336. //memset idTag
  9337. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9338. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9339. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9340. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9341. // Save profile to file
  9342. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9343. system(cmdBuf);
  9344. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9345. fp = fopen(cmdBuf, "w");
  9346. 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));
  9347. fclose(fp);
  9348. }
  9349. else
  9350. {
  9351. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9353. }
  9354. }
  9355. else
  9356. {
  9357. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9358. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9359. //memset idTag
  9360. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9361. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9362. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9363. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9364. }
  9365. }
  9366. else
  9367. {
  9368. DEBUG_WARN("Connector id over\n.");
  9369. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9370. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9371. }
  9372. end:
  9373. json_object_put(RemoteStartTransaction);
  9374. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9375. {
  9376. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9377. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9378. }
  9379. //OCPP send RemoteStartConfirmation by first.
  9380. sendRemoteStartConfirmation(uuid, comfirmstr);
  9381. return result;
  9382. }
  9383. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9384. {
  9385. mtrace();
  9386. int result = FAIL;
  9387. int match = FALSE;
  9388. int GunNO = 0;
  9389. int tempIndex = 0;
  9390. int transactionIdInt=0;
  9391. int transactionIdIsNULL= TRUE;
  9392. char comfirmstr[20];
  9393. json_object *RemoteStopTransaction;
  9394. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9395. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9396. if(server_pending == TRUE)
  9397. {
  9398. return 0;
  9399. }
  9400. RemoteStopTransaction = json_tokener_parse(payload);
  9401. if(!is_error(RemoteStopTransaction))
  9402. {
  9403. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9404. {
  9405. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9406. transactionIdIsNULL = FALSE;
  9407. }
  9408. }
  9409. json_object_put(RemoteStopTransaction);
  9410. if(transactionIdIsNULL == FALSE)
  9411. {
  9412. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9413. {
  9414. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9415. {
  9416. //check Transaction active
  9417. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9418. {
  9419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9420. {
  9421. tempIndex = ((gun_index==2) ? 1: 0);
  9422. }
  9423. else
  9424. {
  9425. tempIndex = gun_index;
  9426. }
  9427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9428. {
  9429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9430. {
  9431. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9432. {
  9433. match = TRUE;
  9434. GunNO = gun_index;
  9435. }
  9436. }
  9437. }// END FOR CHAdeMO_QUANTITY
  9438. }
  9439. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9440. {
  9441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9442. {
  9443. tempIndex = ((gun_index==2) ? 1: 0);
  9444. }
  9445. else
  9446. {
  9447. tempIndex = gun_index;
  9448. }
  9449. for (int index = 0; index < CCS_QUANTITY; index++)
  9450. {
  9451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9452. {
  9453. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9454. {
  9455. match = TRUE;
  9456. GunNO = gun_index;
  9457. }
  9458. }
  9459. }// END FOR CCS_QUANTITY
  9460. }
  9461. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9462. {
  9463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9464. {
  9465. tempIndex = ((gun_index==2) ? 1: 0);
  9466. }
  9467. else
  9468. {
  9469. tempIndex = gun_index;
  9470. }
  9471. for (int index = 0; index < GB_QUANTITY; index++)
  9472. {
  9473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9474. {
  9475. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9476. {
  9477. match = TRUE;
  9478. GunNO = gun_index;
  9479. }
  9480. }
  9481. }// END FOR GB_QUANTITY
  9482. }
  9483. else if(gunType[gun_index] == GUN_TYPE_DO)
  9484. {
  9485. tempIndex = gun_index;
  9486. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9487. {
  9488. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9489. {
  9490. 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
  9491. {
  9492. match = TRUE;
  9493. GunNO = gun_index;
  9494. }
  9495. }
  9496. }// END FOR GB_QUANTITY
  9497. }
  9498. else
  9499. {
  9500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9501. {
  9502. tempIndex = 2;
  9503. }
  9504. else
  9505. {
  9506. tempIndex = gun_index;
  9507. }
  9508. for (int index = 0; index < AC_QUANTITY; index++)
  9509. {
  9510. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9511. {
  9512. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9513. {
  9514. match = TRUE;
  9515. GunNO = gun_index;
  9516. }
  9517. }
  9518. }// END FOR CHAdeMO_QUANTITY
  9519. } // END FOR AC ELSE
  9520. }// CHECK IF ResponseTransactionId == transactionIdInt
  9521. }//END FOR
  9522. if( match == TRUE)
  9523. {
  9524. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9526. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9527. }
  9528. else
  9529. {
  9530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9531. }
  9532. }
  9533. else
  9534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9535. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9536. return result;
  9537. }
  9538. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9539. {
  9540. mtrace();
  9541. int result = FAIL;
  9542. int connectorIdInt=0, reservationIdInt=0;
  9543. int tempIndex = 0;
  9544. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9545. char comfirmstr[20]={0};
  9546. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9547. int c = 0;
  9548. char *loc;
  9549. //char *ptr;
  9550. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9551. strcpy(sstrtemp, stringtrimspace(payload));
  9552. //***(1)connectorId ****/
  9553. c=0;
  9554. loc = strstr(sstrtemp, "connectorId");
  9555. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9556. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9557. {
  9558. sstr[c] = loc[strlen("connectorId")+2+c];
  9559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9560. c++;
  9561. }
  9562. sstr[c] = '\0';
  9563. connectorIdInt = atoi(sstr);
  9564. //***(2)expiryDate ****/
  9565. loc = strstr(sstrtemp, "expiryDate");
  9566. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9567. c = 0;
  9568. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9569. {
  9570. sstr[c] = loc[3+strlen("expiryDate")+c];
  9571. c++;
  9572. }
  9573. sstr[c] = '\0';
  9574. strcpy(expiryDatestr, sstr);
  9575. //***(3)idTag ****/
  9576. loc = strstr(sstrtemp, "idTag");
  9577. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9578. c = 0;
  9579. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9580. {
  9581. sstr[c] = loc[3+strlen("idTag")+c];
  9582. c++;
  9583. }
  9584. sstr[c] = '\0';
  9585. strcpy(idTagstr, sstr);
  9586. //***(4)parentIdTag ****/
  9587. loc = strstr(sstrtemp, "parentIdTag");
  9588. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9589. c = 0;
  9590. if(loc == NULL)
  9591. {
  9592. strcpy(parentIdTagstr, "");
  9593. }
  9594. else
  9595. {
  9596. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9597. {
  9598. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9599. c++;
  9600. }
  9601. sstr[c] = '\0';
  9602. strcpy(parentIdTagstr, sstr);
  9603. }
  9604. //***(5)reservationId ****/
  9605. c=0;
  9606. loc = strstr(sstrtemp, "reservationId");
  9607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9608. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9609. {
  9610. sstr[c] = loc[strlen("reservationId")+2+c];
  9611. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9612. c++;
  9613. }
  9614. sstr[c] = '\0';
  9615. reservationIdInt = atoi(sstr);
  9616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9617. /*
  9618. enum SYSTEM_STATUS
  9619. {
  9620. SYS_MODE_BOOTING = 0,
  9621. SYS_MODE_IDLE = 1,
  9622. SYS_MODE_AUTHORIZING = 2,
  9623. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9624. SYS_MODE_REASSIGN = 4,
  9625. SYS_MODE_PREPARING = 5,
  9626. SYS_MODE_PREPARE_FOR_EV = 6,
  9627. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9628. SYS_MODE_CHARGING = 8,
  9629. SYS_MODE_TERMINATING = 9,
  9630. SYS_MODE_COMPLETE = 10,
  9631. SYS_MODE_ALARM = 11,
  9632. SYS_MODE_FAULT = 12,
  9633. SYS_MODE_RESERVATION = 13,
  9634. SYS_MODE_BOOKING = 14,
  9635. SYS_MODE_MAINTAIN = 15,
  9636. SYS_MODE_DEBUG = 16,
  9637. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9638. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9639. SYS_MODE_UPDATE = 19
  9640. };
  9641. */
  9642. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9643. {
  9644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9645. goto end;
  9646. }
  9647. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9648. {
  9649. //check Transaction active
  9650. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9651. {
  9652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9653. {
  9654. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9655. }
  9656. else
  9657. {
  9658. tempIndex = connectorIdInt -1;
  9659. }
  9660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9661. {
  9662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9663. {
  9664. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9665. {
  9666. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9667. {
  9668. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9669. {
  9670. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9672. }
  9673. 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'))
  9674. {
  9675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9676. }
  9677. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9678. {
  9679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9680. }
  9681. else
  9682. {
  9683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9684. }
  9685. }
  9686. 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
  9687. {
  9688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9689. }
  9690. }
  9691. else
  9692. {
  9693. //replace reservation
  9694. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9696. }
  9697. }
  9698. } // END FOR CHAdeMO_QUANTITY
  9699. }
  9700. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9701. {
  9702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9703. {
  9704. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9705. }
  9706. else
  9707. {
  9708. tempIndex = connectorIdInt -1;
  9709. }
  9710. for (int index = 0; index < CCS_QUANTITY; index++)
  9711. {
  9712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9713. {
  9714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9715. {
  9716. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9717. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9718. {
  9719. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9720. {
  9721. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9723. }
  9724. 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'))
  9725. {
  9726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9727. }
  9728. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9729. {
  9730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9731. }
  9732. else
  9733. {
  9734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9735. }
  9736. }
  9737. 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
  9738. {
  9739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9740. }
  9741. }
  9742. else
  9743. {
  9744. //replace reservation
  9745. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9747. }
  9748. }
  9749. } // END FOR CCS_QUANTITY
  9750. }
  9751. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9752. {
  9753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9754. {
  9755. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9756. }
  9757. else
  9758. {
  9759. tempIndex = connectorIdInt -1;
  9760. }
  9761. for (int index = 0; index < GB_QUANTITY; index++)
  9762. {
  9763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9764. {
  9765. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9766. {
  9767. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9768. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9769. {
  9770. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9771. {
  9772. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9774. }
  9775. 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'))
  9776. {
  9777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9778. }
  9779. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9780. {
  9781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9782. }
  9783. else
  9784. {
  9785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9786. }
  9787. }
  9788. 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
  9789. {
  9790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9791. }
  9792. }
  9793. else
  9794. {
  9795. //replace reservation
  9796. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9798. }
  9799. }
  9800. }// END FOR GB_QUANTITY
  9801. }
  9802. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9803. {
  9804. tempIndex = connectorIdInt -1;
  9805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9806. {
  9807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9808. {
  9809. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9810. {
  9811. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9812. 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
  9813. {
  9814. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9815. {
  9816. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9818. }
  9819. 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'))
  9820. {
  9821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9822. }
  9823. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9824. {
  9825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9826. }
  9827. else
  9828. {
  9829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9830. }
  9831. }
  9832. 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
  9833. {
  9834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9835. }
  9836. }
  9837. else
  9838. {
  9839. //replace reservation
  9840. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9842. }
  9843. }
  9844. }// END FOR GB_QUANTITY
  9845. }
  9846. else
  9847. {
  9848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9849. {
  9850. tempIndex = 2;
  9851. }
  9852. else
  9853. {
  9854. tempIndex = (connectorIdInt -1);
  9855. }
  9856. for (int index = 0; index < AC_QUANTITY; index++)
  9857. {
  9858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9859. {
  9860. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9861. {
  9862. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9863. {
  9864. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9865. {
  9866. 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))
  9867. {
  9868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9869. }
  9870. else
  9871. {
  9872. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9874. }
  9875. }
  9876. 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'))
  9877. {
  9878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9879. }
  9880. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9881. {
  9882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9883. }
  9884. else
  9885. {
  9886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9887. }
  9888. }
  9889. 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
  9890. {
  9891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9892. }
  9893. }
  9894. else
  9895. {
  9896. //replace reservation
  9897. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9899. }
  9900. }
  9901. } // END FOR AC_QUANTITY
  9902. }
  9903. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9904. }
  9905. else if(connectorIdInt == 0)
  9906. {
  9907. //check Transaction active
  9908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9909. {
  9910. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9911. {
  9912. 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'))
  9913. {
  9914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9915. goto end;
  9916. }
  9917. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9918. {
  9919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9920. goto end;
  9921. }
  9922. 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
  9923. {
  9924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9925. goto end;
  9926. }
  9927. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9928. {
  9929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9930. goto end;
  9931. }
  9932. }
  9933. }// END FOR CHAdeMO_QUANTITY
  9934. for (int index = 0; index < CCS_QUANTITY; index++)
  9935. {
  9936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9937. {
  9938. 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'))
  9939. {
  9940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9941. goto end;
  9942. }
  9943. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9944. {
  9945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9946. goto end;
  9947. }
  9948. 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
  9949. {
  9950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9951. goto end;
  9952. }
  9953. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9954. {
  9955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9956. goto end;
  9957. }
  9958. }
  9959. } // END FOR CCS_QUANTITY
  9960. for (int index = 0; index < GB_QUANTITY; index++)
  9961. {
  9962. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9963. {
  9964. 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'))
  9965. {
  9966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9967. goto end;
  9968. }
  9969. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9970. {
  9971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9972. goto end;
  9973. }
  9974. 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
  9975. {
  9976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9977. goto end;
  9978. }
  9979. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9980. {
  9981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9982. goto end;
  9983. }
  9984. }
  9985. } // END FOR GB_QUANTITY
  9986. for (int index = 0; index < AC_QUANTITY; index++)
  9987. {
  9988. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9989. {
  9990. 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'))
  9991. {
  9992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9993. goto end;
  9994. }
  9995. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9996. {
  9997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9998. goto end;
  9999. }
  10000. 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
  10001. {
  10002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10003. goto end;
  10004. }
  10005. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10006. {
  10007. 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))
  10008. {
  10009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10010. goto end;
  10011. }
  10012. }
  10013. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10014. {
  10015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10016. goto end;
  10017. }
  10018. }
  10019. }// END FOR AC_QUANTITY
  10020. //The connectorId is 0
  10021. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10023. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10024. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10025. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10026. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10027. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10028. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10029. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10030. result = TRUE;
  10031. return result;
  10032. }
  10033. else
  10034. {
  10035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10036. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10037. }
  10038. if(strcmp(comfirmstr,"Accepted") == 0)
  10039. {
  10040. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10041. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10042. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10043. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10044. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10045. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10046. result = TRUE;
  10047. return result;
  10048. }
  10049. end:
  10050. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10051. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10052. return result;
  10053. }
  10054. int handleResetRequest(char *uuid, char *payload)
  10055. {
  10056. mtrace();
  10057. int result = FAIL;
  10058. char sstr[10]={0},sstrtemp[30]={ 0 };
  10059. char typestr[10]={0};
  10060. char comfirmstr[20]={0};
  10061. int c = 0;
  10062. char *loc;
  10063. DEBUG_INFO("handleResetRequest...\n");
  10064. strcpy(sstrtemp, stringtrimspace(payload));
  10065. loc = strstr(sstrtemp, "type");
  10066. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10067. c = 0;
  10068. while (loc[3+strlen("type")+c] != '\"')
  10069. {
  10070. sstr[c] = loc[3+strlen("type")+c];
  10071. c++;
  10072. }
  10073. sstr[c] = '\0';
  10074. strcpy(typestr,sstr);
  10075. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10076. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10077. {
  10078. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10079. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10080. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10081. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10082. }
  10083. else
  10084. {
  10085. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10086. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10087. result = PASS;
  10088. }
  10089. sendResetConfirmation(uuid, comfirmstr);
  10090. return result;
  10091. }
  10092. int handleSendLocalListRequest(char *uuid, char *payload)
  10093. {
  10094. mtrace();
  10095. int result = FAIL;
  10096. char comfirmstr[20];
  10097. int checkState_Faulted = FALSE;
  10098. json_object *SendLocalList;
  10099. DEBUG_INFO("handleSendLocalListRequest...\n");
  10100. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10101. {
  10102. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10103. goto end;
  10104. }
  10105. //check Charge Point state
  10106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10107. {
  10108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10109. {
  10110. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10111. }
  10112. }
  10113. for (int index = 0; index < CCS_QUANTITY; index++)
  10114. {
  10115. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10116. {
  10117. checkState_Faulted = TRUE; //OCPP Status
  10118. }
  10119. }
  10120. for (int index = 0; index < GB_QUANTITY; index++)
  10121. {
  10122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10123. {
  10124. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10125. }
  10126. }
  10127. //check Charge Point state
  10128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10129. {
  10130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10131. {
  10132. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10133. }
  10134. }
  10135. //check Charge Point state
  10136. for (int index = 0; index < AC_QUANTITY; index++)
  10137. {
  10138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10139. {
  10140. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10141. }
  10142. }
  10143. if(checkState_Faulted == TRUE)
  10144. {
  10145. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10146. goto end;
  10147. }
  10148. // Parsing payload
  10149. SendLocalList = json_tokener_parse(payload);
  10150. if(!is_error(SendLocalList))
  10151. {
  10152. // Required data
  10153. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10154. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10155. // Optional data
  10156. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10157. {
  10158. //Check UpdateType
  10159. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10160. {
  10161. //Local list full update
  10162. DEBUG_INFO("Local list full update.\n");
  10163. OCPP_getListVerion();
  10164. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10165. {
  10166. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10167. goto end;
  10168. }
  10169. OCPP_cleanLocalList();
  10170. }
  10171. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10172. {
  10173. //Local list different update
  10174. DEBUG_INFO("Local list different update.\n");
  10175. OCPP_getListVerion();
  10176. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10177. {
  10178. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10179. goto end;
  10180. }
  10181. }
  10182. else
  10183. {
  10184. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10185. goto end;
  10186. }
  10187. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10188. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10189. {
  10190. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10191. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10192. {
  10193. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10194. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10195. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10196. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10197. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10198. }
  10199. // Add to db
  10200. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10201. {
  10202. //Local list full update
  10203. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10204. idx,
  10205. ShmOCPP16Data->SendLocalList.ListVersion,
  10206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10208. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10209. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10210. // update list
  10211. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10213. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10214. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10215. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10216. }
  10217. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10218. {
  10219. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10220. idx,
  10221. ShmOCPP16Data->SendLocalList.ListVersion,
  10222. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10223. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10224. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10225. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10226. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10227. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10228. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10229. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10230. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10231. }
  10232. }
  10233. }
  10234. else
  10235. {
  10236. //Check UpdateType
  10237. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10238. {
  10239. //Local list full update
  10240. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10241. OCPP_cleanLocalList();
  10242. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10243. goto end;
  10244. }
  10245. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10246. {
  10247. //Local list different update
  10248. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10249. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10250. goto end;
  10251. }
  10252. }
  10253. result = PASS;
  10254. }
  10255. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10256. end:
  10257. json_object_put(SendLocalList);
  10258. sendSendLocalListConfirmation(uuid, comfirmstr);
  10259. return result;
  10260. }
  10261. #define MAX 200
  10262. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10263. {
  10264. mtrace();
  10265. int result = FAIL;
  10266. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10267. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10268. char chargingProfilePurposeStr[30]={0};
  10269. char chargingProfileKindStr[16]={0};
  10270. char recurrencyKindStr[10]={0};
  10271. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10272. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10273. int chargingSchedulePeriodCount = 0;
  10274. char comfirmstr[20]={0};
  10275. int meet= FALSE;
  10276. FILE *fptr1;
  10277. char filename[MAX]={0};
  10278. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10279. char rmFileCmd[50]={0};
  10280. char tempchargingProfilePurposeStr[30]={0};
  10281. char word[1600]={0};
  10282. int n_chargingProfile = 0;
  10283. json_object *SetChargingProfile;
  10284. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10285. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10286. SetChargingProfile = json_tokener_parse(payload);
  10287. if(!is_error(SetChargingProfile))
  10288. {
  10289. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10290. {
  10291. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10292. if(connectorIdInt == 0)
  10293. {
  10294. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10295. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10296. }
  10297. else
  10298. {
  10299. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10300. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10301. }
  10302. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10303. }
  10304. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10305. {
  10306. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10307. {
  10308. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10309. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10310. {
  10311. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10312. }
  10313. else
  10314. {
  10315. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10316. }
  10317. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10318. }
  10319. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10320. {
  10321. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10322. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10323. {
  10324. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10325. }
  10326. else
  10327. {
  10328. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10329. }
  10330. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10331. }
  10332. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10333. {
  10334. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10335. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10336. {
  10337. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10338. }
  10339. else
  10340. {
  10341. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10342. }
  10343. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10344. }
  10345. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10346. {
  10347. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10348. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10349. {
  10350. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10351. }
  10352. else
  10353. {
  10354. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10355. }
  10356. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10357. }
  10358. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10359. {
  10360. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10361. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10362. {
  10363. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10364. }
  10365. else
  10366. {
  10367. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10368. }
  10369. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10370. }
  10371. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10372. {
  10373. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10374. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10375. {
  10376. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10377. }
  10378. else
  10379. {
  10380. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10381. }
  10382. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10383. }
  10384. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10385. {
  10386. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10387. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10390. }
  10391. else
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10394. }
  10395. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10396. }
  10397. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10398. {
  10399. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10400. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10401. {
  10402. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10403. }
  10404. else
  10405. {
  10406. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10407. }
  10408. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10409. }
  10410. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10411. {
  10412. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10413. {
  10414. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10416. {
  10417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10418. }
  10419. else
  10420. {
  10421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10422. }
  10423. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10424. }
  10425. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10426. {
  10427. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10428. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10429. {
  10430. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10431. }
  10432. else
  10433. {
  10434. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10435. }
  10436. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10437. }
  10438. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10439. {
  10440. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10441. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10442. {
  10443. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10444. }
  10445. else
  10446. {
  10447. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10448. }
  10449. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10450. }
  10451. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10452. {
  10453. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10454. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10455. {
  10456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10457. }
  10458. else
  10459. {
  10460. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10461. }
  10462. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10463. }
  10464. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10465. {
  10466. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10467. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10468. if(chargingSchedulePeriodCount <= 10)
  10469. {
  10470. 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++)
  10471. {
  10472. 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)
  10473. {
  10474. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10475. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10476. {
  10477. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10478. }
  10479. else
  10480. {
  10481. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10482. }
  10483. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10484. }
  10485. 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)
  10486. {
  10487. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10489. {
  10490. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10491. }
  10492. else
  10493. {
  10494. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10495. }
  10496. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10497. }
  10498. 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)
  10499. {
  10500. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10501. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10502. {
  10503. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10504. }
  10505. else
  10506. {
  10507. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10508. }
  10509. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10510. }
  10511. }
  10512. }
  10513. }
  10514. }
  10515. }
  10516. }
  10517. json_object_put(SetChargingProfile);
  10518. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10519. {
  10520. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10521. goto end;
  10522. }
  10523. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10524. {
  10525. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10526. if(connectorIdInt != 0)
  10527. {
  10528. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10529. goto end;
  10530. }
  10531. strcpy(filename, ChargePointMaxProfile_JSON );
  10532. fptr1 = fopen(filename, "r");
  10533. if (!fptr1)
  10534. {
  10535. //file not exist
  10536. DEBUG_INFO("Unable to open the input file!!\n");
  10537. fptr1 = fopen(filename, "w+");
  10538. }
  10539. else
  10540. {
  10541. //Check Charging Profile Count
  10542. while(fscanf(fptr1, "%s", word) != EOF)
  10543. {
  10544. //DEBUG_INFO("word=%s\n",word);
  10545. if(strstr(word, "chargingProfileId")!= NULL)
  10546. {
  10547. //DEBUG_INFO("test chargingProfileId \n");
  10548. n_chargingProfile = n_chargingProfile + 1;
  10549. //DEBUG_INFO("chargingProfileId Found\n");
  10550. }
  10551. }
  10552. }
  10553. fclose(fptr1);
  10554. }
  10555. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10556. {
  10557. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10558. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10559. {
  10560. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10561. goto end;
  10562. }
  10563. memset(filename, 0, ARRAY_SIZE(filename));
  10564. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10565. fptr1 = fopen(filename, "r");
  10566. if (!fptr1)
  10567. {
  10568. //file not exist
  10569. //DEBUG_INFO("Unable to open the input file!!\n");
  10570. fptr1 = fopen(filename, "w+");
  10571. }
  10572. else
  10573. {
  10574. //Check Charging Profile Count
  10575. while(fscanf(fptr1, "%s", word) != EOF)
  10576. {
  10577. //DEBUG_INFO("word=%s\n",word);
  10578. if(strstr(word, "chargingProfileId")!= NULL)
  10579. {
  10580. //DEBUG_INFO("test chargingProfileId \n");
  10581. n_chargingProfile = n_chargingProfile + 1;
  10582. //DEBUG_INFO("chargingProfileId Found\n");
  10583. }
  10584. }
  10585. }
  10586. fclose(fptr1);
  10587. }
  10588. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10589. {
  10590. //printf("set chargingProfile 1-4\n");
  10591. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10592. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10593. if(connectorIdInt == 0)
  10594. {
  10595. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10596. goto end;
  10597. }
  10598. int tempIndex = 0;
  10599. //check Transaction active
  10600. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10601. {
  10602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10603. {
  10604. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10605. }
  10606. else
  10607. {
  10608. tempIndex = connectorIdInt -1;
  10609. }
  10610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10611. {
  10612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10613. {
  10614. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10615. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10616. {
  10617. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10618. {
  10619. meet = TRUE;
  10620. break;
  10621. }
  10622. }
  10623. }
  10624. }
  10625. }
  10626. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10627. {
  10628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10629. {
  10630. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10631. }
  10632. else
  10633. {
  10634. tempIndex = connectorIdInt -1;
  10635. }
  10636. for (int index = 0; index < CCS_QUANTITY; index++)
  10637. {
  10638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10639. {
  10640. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10641. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10642. {
  10643. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10644. {
  10645. meet = TRUE;
  10646. break;
  10647. }
  10648. }
  10649. }
  10650. }
  10651. }
  10652. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10653. {
  10654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10655. {
  10656. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10657. }
  10658. else
  10659. {
  10660. tempIndex = connectorIdInt -1;
  10661. }
  10662. for (int index = 0; index < GB_QUANTITY; index++)
  10663. {
  10664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10665. {
  10666. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10667. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10668. {
  10669. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10670. {
  10671. meet = TRUE;
  10672. break;
  10673. }
  10674. }
  10675. }
  10676. }
  10677. }
  10678. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10679. {
  10680. tempIndex = connectorIdInt -1;
  10681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10682. {
  10683. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10684. {
  10685. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10686. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10687. {
  10688. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10689. {
  10690. meet = TRUE;
  10691. break;
  10692. }
  10693. }
  10694. }
  10695. }
  10696. }
  10697. else
  10698. {
  10699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10700. {
  10701. tempIndex = 2;
  10702. }
  10703. else
  10704. {
  10705. tempIndex = (connectorIdInt -1);
  10706. }
  10707. for (int index = 0; index < AC_QUANTITY; index++)
  10708. {
  10709. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10710. {
  10711. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10712. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10713. {
  10714. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10715. {
  10716. meet = TRUE;
  10717. break;
  10718. }
  10719. }
  10720. }
  10721. }
  10722. }
  10723. //check Transaction active
  10724. if(meet == FALSE)
  10725. {
  10726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10727. goto end;
  10728. }
  10729. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10730. {
  10731. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10732. goto end;
  10733. }
  10734. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10735. fptr1 = fopen(filename, "r");
  10736. if (!fptr1)
  10737. {
  10738. //file not exist
  10739. DEBUG_INFO("Unable to open the input file!!\n");
  10740. fptr1 = fopen(filename, "w+");
  10741. }
  10742. else
  10743. {
  10744. //Check Charging Profile Count
  10745. while(fscanf(fptr1, "%s", word) != EOF)
  10746. {
  10747. //DEBUG_INFO("word=%s\n",word);
  10748. if(strstr(word, "chargingProfileId")!= NULL)
  10749. {
  10750. //DEBUG_INFO("test chargingProfileId \n");
  10751. n_chargingProfile = n_chargingProfile + 1;
  10752. //DEBUG_INFO("chargingProfileId Found\n");
  10753. }
  10754. }
  10755. }
  10756. fclose(fptr1);
  10757. }
  10758. // Check ChargeProfileMaxStackLevel
  10759. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10760. {
  10761. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10762. goto end;
  10763. }
  10764. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10765. {
  10766. int i = 0;
  10767. char fnametemp[200]={0};
  10768. n_chargingProfile = 0;
  10769. //Check ChargePointMaxProfile.json exit
  10770. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10771. {
  10772. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10773. //Check Charging Profile Count
  10774. while(fscanf(fptr1, "%s", word) != EOF)
  10775. {
  10776. //DEBUG_INFO("word=%s\n",word);
  10777. if(strstr(word, "chargingProfileId")!= NULL)
  10778. {
  10779. //DEBUG_INFO("test chargingProfileId \n");
  10780. n_chargingProfile = n_chargingProfile + 1;
  10781. i = i + 1;
  10782. //DEBUG_INFO("chargingProfileId Found\n");
  10783. }
  10784. memset(word, 0, ARRAY_SIZE(word));
  10785. }
  10786. fclose(fptr1);
  10787. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10788. }
  10789. //Check TxDefaultProfile_0.json exit
  10790. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10791. {
  10792. i = 0;
  10793. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10794. //Check Charging Profile Count
  10795. while(fscanf(fptr1, "%s", word) != EOF)
  10796. {
  10797. //DEBUG_INFO("word=%s\n",word);
  10798. if(strstr(word, "chargingProfileId")!= NULL)
  10799. {
  10800. //DEBUG_INFO("test chargingProfileId \n");
  10801. n_chargingProfile = n_chargingProfile + 1;
  10802. i = i + 1;
  10803. //DEBUG_INFO("chargingProfileId Found\n");
  10804. }
  10805. memset(word, 0, ARRAY_SIZE(word));
  10806. }
  10807. fclose(fptr1);
  10808. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10809. }
  10810. //Check TxDefaultProfile_%d.json
  10811. for(int j=1; j <= gunTotalNumber; j++)
  10812. {
  10813. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10814. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10815. if((access(fnametemp,F_OK))!=-1)
  10816. {
  10817. i = 0;
  10818. fptr1 = fopen(fnametemp, "r");
  10819. //Check Charging Profile Count
  10820. while(fscanf(fptr1, "%s", word) != EOF)
  10821. {
  10822. //DEBUG_INFO("word=%s\n",word);
  10823. if(strstr(word, "chargingProfileId")!= NULL)
  10824. {
  10825. //DEBUG_INFO("test chargingProfileId \n");
  10826. n_chargingProfile = n_chargingProfile + 1;
  10827. i = i + 1;
  10828. //DEBUG_INFO("chargingProfileId Found\n");
  10829. }
  10830. memset(word, 0, ARRAY_SIZE(word));
  10831. }
  10832. fclose(fptr1);
  10833. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10834. }
  10835. }
  10836. //Check TxProfile_%d.json
  10837. for(int j=1; j <= gunTotalNumber; j++)
  10838. {
  10839. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10840. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10841. if((access(fnametemp,F_OK))!=-1)
  10842. {
  10843. i = 0;
  10844. fptr1 = fopen(fnametemp, "r");
  10845. //Check Charging Profile Count
  10846. while(fscanf(fptr1, "%s", word) != EOF)
  10847. {
  10848. //DEBUG_INFO("word=%s\n",word);
  10849. if(strstr(word, "chargingProfileId")!= NULL)
  10850. {
  10851. //DEBUG_INFO("test chargingProfileId \n");
  10852. n_chargingProfile = n_chargingProfile + 1;
  10853. i = i + 1;
  10854. //DEBUG_INFO("chargingProfileId Found\n");
  10855. }
  10856. memset(word, 0, ARRAY_SIZE(word));
  10857. }
  10858. fclose(fptr1);
  10859. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10860. }
  10861. }
  10862. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10863. {
  10864. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10865. goto end;
  10866. }
  10867. }
  10868. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10869. //**********************************Write to File********************************************************/
  10870. FILE *infile;
  10871. FILE *outfile;
  10872. infile = fopen (filename, "r");
  10873. outfile = fopen (tempfile, "w");
  10874. int d =0;
  10875. d = fgetc(infile);
  10876. rewind(infile);
  10877. if(d == EOF)
  10878. {
  10879. // Profile is empty
  10880. fprintf(outfile,"%s\n",payload);
  10881. fclose(infile);
  10882. fclose(outfile);
  10883. sprintf(rmFileCmd,"rm -f %s",filename);
  10884. system(rmFileCmd);
  10885. rename(tempfile, filename);
  10886. }
  10887. else
  10888. {
  10889. // Profile is not empty
  10890. char buf[2048]={0};
  10891. int ChargingProfileAdded = FALSE;
  10892. while (fgets(buf, sizeof(buf), infile) != NULL)
  10893. {
  10894. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10895. json_object *tmpChargingProfile;
  10896. tmpChargingProfile = json_tokener_parse(buf);
  10897. if(!is_error(SetChargingProfile))
  10898. {
  10899. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10900. {
  10901. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10902. }
  10903. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10904. {
  10905. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10906. {
  10907. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10908. }
  10909. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10910. {
  10911. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10912. }
  10913. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10914. {
  10915. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10916. }
  10917. }
  10918. }
  10919. json_object_put(tmpChargingProfile);
  10920. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10921. {
  10922. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10923. {
  10924. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10925. if(ChargingProfileAdded == FALSE)
  10926. {
  10927. fprintf(outfile,"%s\n",payload);
  10928. ChargingProfileAdded = TRUE;
  10929. }
  10930. }
  10931. else
  10932. {
  10933. if(tempstackLevelInt < stackLevelInt)
  10934. {
  10935. if(ChargingProfileAdded == FALSE)
  10936. {
  10937. fprintf(outfile,"%s\n",buf);
  10938. fprintf(outfile,"%s\n",payload);
  10939. ChargingProfileAdded = TRUE;
  10940. }
  10941. else
  10942. {
  10943. fprintf(outfile,"%s\n",buf);
  10944. }
  10945. }
  10946. else
  10947. {
  10948. if(ChargingProfileAdded == FALSE)
  10949. {
  10950. fprintf(outfile,"%s\n",buf);
  10951. fprintf(outfile,"%s\n",payload);
  10952. ChargingProfileAdded = TRUE;
  10953. }
  10954. else
  10955. {
  10956. fprintf(outfile,"%s\n",buf);
  10957. }
  10958. }
  10959. }
  10960. }
  10961. else
  10962. {
  10963. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10964. {
  10965. if(ChargingProfileAdded == FALSE)
  10966. {
  10967. fprintf(outfile,"%s\n",buf);
  10968. fprintf(outfile,"%s\n",payload);
  10969. ChargingProfileAdded = TRUE;
  10970. }
  10971. else
  10972. {
  10973. fprintf(outfile,"%s\n",buf);
  10974. }
  10975. }
  10976. else if(tempstackLevelInt < stackLevelInt)
  10977. {
  10978. if(ChargingProfileAdded == FALSE)
  10979. {
  10980. fprintf(outfile,"%s\n",buf);
  10981. fprintf(outfile,"%s\n",payload);
  10982. ChargingProfileAdded = TRUE;
  10983. }
  10984. else
  10985. {
  10986. fprintf(outfile,"%s\n",buf);
  10987. }
  10988. }
  10989. else
  10990. {
  10991. if(ChargingProfileAdded == FALSE)
  10992. {
  10993. fprintf(outfile,"%s\n",buf);
  10994. fprintf(outfile,"%s\n",payload);
  10995. ChargingProfileAdded = TRUE;
  10996. }
  10997. else
  10998. {
  10999. fprintf(outfile,"%s\n",buf);
  11000. }
  11001. }
  11002. }
  11003. } // end of while loop
  11004. fclose(infile);
  11005. fclose(outfile);
  11006. sprintf(rmFileCmd,"rm -f %s",filename);
  11007. system(rmFileCmd);
  11008. rename(tempfile, filename);
  11009. }
  11010. sleep(1);
  11011. result = TRUE;
  11012. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11013. end:
  11014. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11015. {
  11016. if(connectorIdInt == 0)
  11017. {
  11018. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11019. {
  11020. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11021. }
  11022. }
  11023. else
  11024. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11025. }
  11026. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11027. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11028. return result;
  11029. }
  11030. int handleTriggerMessageRequest(char *uuid, char *payload)
  11031. {
  11032. mtrace();
  11033. int result = FAIL;
  11034. int connectorIdIsNULL = FALSE;
  11035. int connectorIdInt =0;
  11036. char sstr[40]={0},sstrtemp[100]={ 0 };
  11037. char requestedMessagestr[40]={0};
  11038. char comfirmstr[20]={0};
  11039. int c = 0;
  11040. char *loc;
  11041. DEBUG_INFO("handleTriggerMessageRequest\n");
  11042. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11043. strcpy(sstrtemp, stringtrimspace(payload));
  11044. c = 0;
  11045. loc = strstr(sstrtemp, "requestedMessage");
  11046. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11047. {
  11048. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11049. c++;
  11050. }
  11051. sstr[c] = '\0';
  11052. strcpy(requestedMessagestr, sstr);
  11053. c = 0;
  11054. loc = strstr(sstrtemp, "connectorId");
  11055. if(loc == NULL)
  11056. {
  11057. connectorIdIsNULL = TRUE;
  11058. }
  11059. else
  11060. {
  11061. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11062. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11063. {
  11064. sstr[c] = loc[strlen("connectorId")+2+c];
  11065. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11066. c++;
  11067. }
  11068. sstr[c] = '\0';
  11069. connectorIdInt = atoi(sstr);
  11070. }
  11071. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11072. {
  11073. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11074. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11075. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11076. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11077. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11078. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11079. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11080. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11081. {
  11082. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11083. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11084. return TRUE;
  11085. }
  11086. else
  11087. {
  11088. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11089. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11090. }
  11091. }
  11092. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11093. {
  11094. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11095. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11096. return TRUE;
  11097. }
  11098. //==========================
  11099. // Trigger message
  11100. //==========================
  11101. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11102. {
  11103. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11104. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11105. {
  11106. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11107. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11108. }
  11109. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11110. }
  11111. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11112. {
  11113. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11114. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11115. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11116. }
  11117. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11118. {
  11119. //sendBootNotificationRequest();
  11120. server_sign = FALSE;
  11121. }
  11122. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11123. {
  11124. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11125. }
  11126. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11127. {
  11128. if(connectorIdIsNULL == FALSE)
  11129. {
  11130. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11131. {
  11132. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11133. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11134. }
  11135. }
  11136. else
  11137. {
  11138. for(int idx=0;idx< gunTotalNumber;idx++)
  11139. {
  11140. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11141. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11142. }
  11143. }
  11144. }
  11145. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11146. {
  11147. if(connectorIdIsNULL == FALSE)
  11148. {
  11149. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11150. {
  11151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11152. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11153. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11154. }
  11155. }
  11156. else
  11157. {
  11158. for(int idx=0;idx< gunTotalNumber;idx++)
  11159. {
  11160. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11161. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11162. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11163. }
  11164. }
  11165. }
  11166. return result;
  11167. }
  11168. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11169. {
  11170. mtrace();
  11171. int result = FAIL;
  11172. int connectorIdInt =0;
  11173. char comfirmstr[20]={0};
  11174. int tempIndex = 0;
  11175. json_object *UnlockConnector;
  11176. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11177. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11178. UnlockConnector = json_tokener_parse(payload);
  11179. if(!is_error(UnlockConnector))
  11180. {
  11181. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11182. {
  11183. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11184. }
  11185. }
  11186. json_object_put(UnlockConnector);
  11187. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11188. if(gunTotalNumber == 0)
  11189. {
  11190. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11191. goto end;
  11192. }
  11193. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11194. {
  11195. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11196. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11197. goto end;
  11198. }
  11199. else
  11200. {
  11201. //check Transaction active
  11202. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11203. {
  11204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11205. {
  11206. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11207. }
  11208. else
  11209. {
  11210. tempIndex = connectorIdInt -1;
  11211. }
  11212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11213. {
  11214. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11215. {
  11216. //stop Transaction
  11217. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11218. }
  11219. }
  11220. }
  11221. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11222. {
  11223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11224. {
  11225. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11226. }
  11227. else
  11228. {
  11229. tempIndex = connectorIdInt -1;
  11230. }
  11231. for (int index = 0; index < CCS_QUANTITY; index++)
  11232. {
  11233. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11234. {
  11235. //stop Transaction
  11236. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11237. }
  11238. }
  11239. }
  11240. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11241. {
  11242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11243. {
  11244. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11245. }
  11246. else
  11247. {
  11248. tempIndex = connectorIdInt -1;
  11249. }
  11250. for (int index = 0; index < GB_QUANTITY; index++)
  11251. {
  11252. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11253. {
  11254. //stop Transaction
  11255. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11256. }
  11257. }
  11258. }
  11259. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11260. {
  11261. tempIndex = connectorIdInt -1;
  11262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11263. {
  11264. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11265. {
  11266. //stop Transaction
  11267. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11268. }
  11269. }
  11270. }
  11271. else
  11272. {
  11273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11274. {
  11275. tempIndex = 2;
  11276. }
  11277. else
  11278. {
  11279. tempIndex = connectorIdInt-1;
  11280. }
  11281. for (int index = 0; index < AC_QUANTITY; index++)
  11282. {
  11283. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11284. {
  11285. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11286. }
  11287. }
  11288. }
  11289. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11290. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11291. result = TRUE;
  11292. return result;
  11293. }
  11294. end:
  11295. //json_object_put(obj); --- remove temporally
  11296. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11297. return result;
  11298. }
  11299. static char UpdateFirmwarepayloadData[300]={0};
  11300. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11301. {
  11302. mtrace();
  11303. int result = FAIL;
  11304. pthread_t t;
  11305. sendUpdateFirmwareConfirmation(uuid);
  11306. memset(UpdateFirmwarepayloadData, 0, 300);
  11307. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11308. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11309. ////pthread_join(t, NULL); //
  11310. //pthread_detach(t);
  11311. //sendUpdateFirmwareConfirmation(uuid);
  11312. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11313. return result;
  11314. }
  11315. void *UpdateFirmwareProcess(void *data)
  11316. {
  11317. pthread_detach(pthread_self());
  11318. mtrace();
  11319. int retriesInt =0, retryIntervalInt=0;
  11320. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11321. int port=0;
  11322. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11323. int isSuccess = 0;
  11324. char ftpbuf[1024];
  11325. char temp[1024];
  11326. char * pch;
  11327. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11328. json_object *UpdateFirmware;
  11329. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11330. if(!is_error(UpdateFirmware))
  11331. {
  11332. // Required data
  11333. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11334. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11335. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11336. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11337. // Optional data
  11338. if(json_object_object_get(UpdateFirmware, "retries"))
  11339. {
  11340. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11341. }
  11342. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11343. {
  11344. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11345. }
  11346. }
  11347. json_object_put(UpdateFirmware);
  11348. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11349. memset(path, 0, ARRAY_SIZE(path));
  11350. // Wait retrieveData
  11351. if(strlen(retrieveDatestr) > 10)
  11352. {
  11353. do
  11354. {
  11355. sleep(1);
  11356. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11357. }
  11358. // Ready to download
  11359. system("rm -f /mnt/*");
  11360. if(strncmp(locationstr,"http", 4) == 0)
  11361. {
  11362. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11363. sprintf(ftppath,"/%s", path);
  11364. DEBUG_INFO("locationstr: %s\n", locationstr);
  11365. DEBUG_INFO("protocol: %s\n",protocol);
  11366. DEBUG_INFO("host: %s\n",host);
  11367. DEBUG_INFO("path: %s\n",path);
  11368. DEBUG_INFO("ftppath: %s\n",ftppath);
  11369. int ftppathlen=strlen(ftppath);
  11370. int i=1;
  11371. char filenametemp[50];
  11372. while(i < ftppathlen)
  11373. {
  11374. int len=ftppathlen-i;
  11375. if(ftppath[len]== 47) // '/' ascll code: 47
  11376. {
  11377. DEBUG_INFO("compare '/' all right\n");
  11378. break;
  11379. }
  11380. i=i+1;
  11381. }
  11382. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11383. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11384. filenametemp[i+1] = 0;
  11385. do
  11386. {
  11387. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11388. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11389. sleep(1);
  11390. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11391. if(!isSuccess)
  11392. {
  11393. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11394. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11395. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11396. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11397. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11398. }
  11399. else
  11400. {
  11401. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11402. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11403. }
  11404. retriesInt--;
  11405. }while((isSuccess == 0)&&(retriesInt >= 0));
  11406. }
  11407. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11408. {
  11409. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11410. memset(temp, 0, ARRAY_SIZE(temp));
  11411. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11412. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11413. int ftppathlen=strlen(ftpbuf);
  11414. int i=1;
  11415. char filenametemp[50];
  11416. while(i < ftppathlen)
  11417. {
  11418. int len=ftppathlen-i;
  11419. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11420. {
  11421. DEBUG_INFO(" compare '/' all right\n");
  11422. break;
  11423. }
  11424. i=i+1;
  11425. }
  11426. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11427. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11428. filenametemp[i+1] = 0;
  11429. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11430. pch=strchr(temp,'@');
  11431. if(pch==NULL)
  11432. {
  11433. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11434. protocol, host, &port, path);
  11435. strcpy(user,"anonymous");
  11436. strcpy(password,"");
  11437. }
  11438. else
  11439. {
  11440. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11441. protocol, user, password, host, &port, path);
  11442. }
  11443. sscanf(host,"%[^/]%s",host1, path1);
  11444. sprintf(ftppath,"%s", path1);
  11445. //DEBUG_INFO("protocol =%s\n",protocol);
  11446. //DEBUG_INFO("user =%s\n",user);
  11447. //DEBUG_INFO("password =%s\n",password);
  11448. //DEBUG_INFO("host1 =%s\n",host1);
  11449. //DEBUG_INFO("port =%d\n",port);
  11450. //DEBUG_INFO("path1 =%s\n",path1);
  11451. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11452. //ftpFile(host, user, password, port, ftppath, fname);
  11453. //download firmware pthred
  11454. if(port == 0)
  11455. {
  11456. port = 21;
  11457. }
  11458. do
  11459. {
  11460. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11461. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11462. sleep(1);
  11463. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11464. if(!isSuccess)
  11465. {
  11466. //BulldogUtil.sleepMs(interval*1000);
  11467. DEBUG_INFO("Update firmware request and download file fail.\n");
  11468. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11470. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11471. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11472. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11473. }
  11474. else
  11475. {
  11476. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11477. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11478. }
  11479. retriesInt--;
  11480. }while((!isSuccess)&&(retriesInt >= 0));
  11481. }
  11482. else
  11483. {
  11484. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11485. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11486. sleep(1);
  11487. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11488. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11489. }
  11490. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11491. pthread_exit(NULL);
  11492. }
  11493. int handleCertificateSignedRequest(char *uuid, char *payload)
  11494. {
  11495. mtrace();
  11496. int result = PASS;
  11497. json_object *CertificateSigned;
  11498. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11499. CertificateSigned = json_tokener_parse(payload);
  11500. if(!is_error(CertificateSigned))
  11501. {
  11502. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11503. }
  11504. json_object_put(CertificateSigned);
  11505. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11506. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11507. fclose(fp);
  11508. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11509. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11510. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11511. sendCertificateSignedConfirmation(uuid);
  11512. return result;
  11513. }
  11514. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11515. {
  11516. mtrace();
  11517. int result = PASS;
  11518. json_object *DeleteCertificate;
  11519. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11520. DeleteCertificate = json_tokener_parse(payload);
  11521. if(!is_error(DeleteCertificate))
  11522. {
  11523. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11524. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11525. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11526. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11527. }
  11528. json_object_put(DeleteCertificate);
  11529. /*
  11530. * TODO: Delete certificateSigned process
  11531. */
  11532. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11533. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11534. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11535. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11536. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11537. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11538. sendDeleteCertificateConfirmation(uuid);
  11539. return result;
  11540. }
  11541. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11542. {
  11543. mtrace();
  11544. int result = PASS;
  11545. json_object *ExtendedTriggerMessage;
  11546. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11547. ExtendedTriggerMessage = json_tokener_parse(payload);
  11548. if(!is_error(ExtendedTriggerMessage))
  11549. {
  11550. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11551. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11552. {
  11553. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11554. }
  11555. else
  11556. {
  11557. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11558. }
  11559. }
  11560. json_object_put(ExtendedTriggerMessage);
  11561. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11562. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11563. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11564. {
  11565. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11566. }
  11567. else
  11568. {
  11569. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11570. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11571. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11572. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11573. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11574. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11575. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11576. {
  11577. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11578. }
  11579. else
  11580. {
  11581. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11582. }
  11583. }
  11584. sendExtendedTriggerMessageConfirmation(uuid);
  11585. //==========================
  11586. // Trigger message
  11587. //==========================
  11588. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11589. {
  11590. //sendBootNotificationRequest();
  11591. server_sign = FALSE;
  11592. }
  11593. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11594. {
  11595. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11596. }
  11597. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11598. {
  11599. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11600. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11601. {
  11602. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11603. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11604. }
  11605. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11606. }
  11607. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11608. {
  11609. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11610. }
  11611. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11612. {
  11613. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11614. {
  11615. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11616. }
  11617. else
  11618. {
  11619. for(int idx=0;idx< gunTotalNumber;idx++)
  11620. {
  11621. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11622. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11623. }
  11624. }
  11625. }
  11626. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11627. {
  11628. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11629. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11630. {
  11631. 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\" &");
  11632. }
  11633. }
  11634. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11635. {
  11636. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11637. {
  11638. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11639. }
  11640. else
  11641. {
  11642. for(int idx=0;idx< gunTotalNumber;idx++)
  11643. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11644. }
  11645. }
  11646. return result;
  11647. }
  11648. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11649. {
  11650. mtrace();
  11651. int result = PASS;
  11652. json_object *GetInstalledCertificateIds;
  11653. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11654. GetInstalledCertificateIds = json_tokener_parse(payload);
  11655. if(!is_error(GetInstalledCertificateIds))
  11656. {
  11657. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11658. }
  11659. json_object_put(GetInstalledCertificateIds);
  11660. /*
  11661. * TODO: Return installed certificate process
  11662. */
  11663. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11664. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11665. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11666. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11667. sendGetInstalledCertificateIdsConfirmation(uuid);
  11668. return result;
  11669. }
  11670. int handleGetLogRequest(char *uuid, char *payload)
  11671. {
  11672. mtrace();
  11673. int result = PASS;
  11674. json_object *GetLog;
  11675. DEBUG_INFO("handleGetLogRequest...\n");
  11676. GetLog = json_tokener_parse(payload);
  11677. if(!is_error(GetLog))
  11678. {
  11679. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11680. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11681. if(json_object_object_get(GetLog, "retries") != NULL)
  11682. {
  11683. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11684. }
  11685. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11686. {
  11687. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11688. }
  11689. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11690. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11691. {
  11692. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11693. }
  11694. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11695. {
  11696. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11697. }
  11698. }
  11699. json_object_put(GetLog);
  11700. /*
  11701. * TODO: Upload log process
  11702. */
  11703. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11704. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11705. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11706. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11707. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11708. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11709. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11710. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11711. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11712. sendGetLogConfirmation(uuid);
  11713. return result;
  11714. }
  11715. int handleInstallCertificateRequest(char *uuid, char *payload)
  11716. {
  11717. mtrace();
  11718. int result = PASS;
  11719. json_object *InstallCertificate;
  11720. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11721. InstallCertificate = json_tokener_parse(payload);
  11722. if(!is_error(InstallCertificate))
  11723. {
  11724. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11725. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11726. /*
  11727. * TODO: Install certificate process
  11728. */
  11729. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11730. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11731. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11732. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11733. sendInstallCertificateConfirmation(uuid);
  11734. }
  11735. json_object_put(InstallCertificate);
  11736. return result;
  11737. }
  11738. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11739. {
  11740. mtrace();
  11741. int result = PASS;
  11742. json_object *SignedUpdateFirmware;
  11743. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11744. SignedUpdateFirmware = json_tokener_parse(payload);
  11745. if(!is_error(SignedUpdateFirmware))
  11746. {
  11747. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11748. {
  11749. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11750. }
  11751. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11752. {
  11753. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11754. }
  11755. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11756. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11757. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11758. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11759. {
  11760. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11761. }
  11762. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11763. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11764. }
  11765. json_object_put(SignedUpdateFirmware);
  11766. /*
  11767. * TODO: Upgrade firmware process
  11768. */
  11769. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11770. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11771. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11772. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11773. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11774. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11775. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11776. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11777. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11778. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11779. sendInstallCertificateConfirmation(uuid);
  11780. return result;
  11781. }
  11782. int handleUnknownRequest(char *uuid, char *payload)
  11783. {
  11784. mtrace();
  11785. int result = PASS;
  11786. DEBUG_INFO("handleUnknownRequest...\n");
  11787. sendUnknownConfirmation(uuid);
  11788. result = PASS;
  11789. return result;
  11790. }
  11791. //==========================================
  11792. // Handle server response routine
  11793. //==========================================
  11794. void handleAuthorizeResponse(char *payload, int gun_index)
  11795. {
  11796. mtrace();
  11797. char expiryDatestr[30]={0};
  11798. char parentIdTagstr[20]={0};
  11799. char statusstr[20]={0};
  11800. int expiryDateISNULL=FALSE;
  11801. int parentIdTagISNULL=FALSE;
  11802. DEBUG_INFO("handleAuthorizeResponse...\n");
  11803. json_object *Authorize;
  11804. Authorize = json_tokener_parse(payload);
  11805. if(!is_error(Authorize))
  11806. {
  11807. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11808. {
  11809. // Required data
  11810. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11811. // Optional data
  11812. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11813. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11814. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11815. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11816. }
  11817. }
  11818. json_object_put(Authorize);
  11819. if(expiryDateISNULL == FALSE)
  11820. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11821. if(parentIdTagISNULL == FALSE)
  11822. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11823. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11824. //Update idTag information to authorization cache if supproted
  11825. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11826. {
  11827. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11828. }
  11829. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11830. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11831. authorizeRetryTimes = 0;
  11832. }
  11833. void handleBootNotificationResponse(char *payload, int gun_index)
  11834. {
  11835. mtrace();
  11836. char statusStr[12]={0};
  11837. char currentTimeStr[30]={0};
  11838. int intervalInt = 0;
  11839. DEBUG_INFO("handleBootNotificationResponse...\n");
  11840. json_object *BootNotification;
  11841. BootNotification = json_tokener_parse(payload);
  11842. if(!is_error(BootNotification))
  11843. {
  11844. // Required data
  11845. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11846. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11847. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11848. }
  11849. json_object_put(BootNotification);
  11850. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11851. BootNotificationInterval = intervalInt;
  11852. HeartBeatWaitTime = intervalInt;
  11853. //write back to ShmOCPP16Data->BootNotification
  11854. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11855. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11856. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11857. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11858. {
  11859. server_sign = TRUE;
  11860. server_pending =FALSE;
  11861. }
  11862. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11863. {
  11864. server_pending = TRUE;
  11865. }
  11866. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11867. srand(time(NULL));
  11868. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11869. SetOcppConnStatus(TRUE);
  11870. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11871. }
  11872. void handleDataTransferResponse(char *payload, int gun_index)
  11873. {
  11874. char sstr[160]={0};//sstr[200]={ 0 };
  11875. int c = 0;
  11876. char *loc;
  11877. DEBUG_INFO("handleDataTransferResponse ...\n");
  11878. loc = strstr(payload, "status");
  11879. c = 0;
  11880. while (loc[3+strlen("status")+c] != '\"')
  11881. {
  11882. sstr[c] = loc[3+strlen("status")+c];
  11883. c++;
  11884. }
  11885. sstr[c] = '\0';
  11886. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11887. }
  11888. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11889. {
  11890. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11891. //struct json_object *obj;
  11892. // obj = json_tokener_parse(payload);
  11893. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11894. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11895. //No fields are defined.
  11896. }
  11897. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11898. {
  11899. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11900. //struct json_object *obj;
  11901. // obj = json_tokener_parse(payload);
  11902. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11903. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11904. //No fields are defined.
  11905. }
  11906. void handleHeartbeatResponse(char *payload, int gun_index)
  11907. {
  11908. mtrace();
  11909. DEBUG_INFO("handleHeartbeatResponse...\n");
  11910. json_object *Heartbeat;
  11911. Heartbeat = json_tokener_parse(payload);
  11912. if(!is_error(Heartbeat))
  11913. {
  11914. // Required data
  11915. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11916. }
  11917. json_object_put(Heartbeat);
  11918. if(FirstHeartBeat == 0)
  11919. {
  11920. FirstHeartBeat = 1;
  11921. DEBUG_INFO("FirstHeartBeat \n");
  11922. }
  11923. HeartBeatWithNOResponse = 0;
  11924. clientTime.Heartbeat=time((time_t*)NULL);
  11925. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11926. }
  11927. void handleMeterValuesResponse(char *payload, int gun_index)
  11928. {
  11929. mtrace();
  11930. DEBUG_INFO("handleMeterValuesResponse...\n");
  11931. }
  11932. void handleStartTransactionResponse(char *payload, int gun_index)
  11933. {
  11934. mtrace();
  11935. //int transactionIdInt = 0;
  11936. FILE *outfile;
  11937. char data[100]={0};
  11938. DEBUG_INFO("handleStartTransactionResponse...\n");
  11939. json_object *StartTransaction;
  11940. StartTransaction = json_tokener_parse(payload);
  11941. if(!is_error(StartTransaction))
  11942. {
  11943. // Required data
  11944. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11945. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11946. // Optional data
  11947. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11948. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11949. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11950. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11951. }
  11952. json_object_put(StartTransaction);
  11953. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11954. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11955. //-----------Start : write to the Queue TransactionId file -----------------//
  11956. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11957. {}
  11958. else
  11959. {
  11960. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11961. if(log == NULL)
  11962. {
  11963. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11964. return ;
  11965. }
  11966. else
  11967. {
  11968. fclose(log);
  11969. }
  11970. }
  11971. // open file for writing
  11972. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11973. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11974. {
  11975. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11976. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11977. fputs(data, outfile);
  11978. fclose (outfile);
  11979. }
  11980. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11981. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11982. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11983. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11984. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11985. }
  11986. void handleStatusNotificationResponse(char *payload, int gun_index)
  11987. {
  11988. mtrace();
  11989. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11990. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11991. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11992. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11993. }
  11994. void handleStopTransactionnResponse(char *payload, int gun_index)
  11995. {
  11996. mtrace();
  11997. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11998. json_object *StopTransaction;
  11999. StopTransaction = json_tokener_parse(payload);
  12000. if(!is_error(StopTransaction))
  12001. {
  12002. // Optional data
  12003. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12004. {
  12005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12006. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12008. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12010. }
  12011. }
  12012. json_object_put(StopTransaction);
  12013. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12014. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12015. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12016. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12017. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12018. }
  12019. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12020. {
  12021. mtrace();
  12022. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12023. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12024. }
  12025. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12026. {
  12027. mtrace();
  12028. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12029. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12030. }
  12031. void handleSignCertificateResponse(char *payload, int gun_index)
  12032. {
  12033. mtrace();
  12034. DEBUG_INFO("handleSignCertificateResponse...\n");
  12035. json_object *SignCertificate;
  12036. SignCertificate = json_tokener_parse(payload);
  12037. if(!is_error(SignCertificate))
  12038. {
  12039. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12040. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12041. }
  12042. json_object_put(SignCertificate);
  12043. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12044. }
  12045. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12046. {
  12047. mtrace();
  12048. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12049. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12050. }
  12051. //==========================================
  12052. // Handle Error routine
  12053. //==========================================
  12054. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12055. {
  12056. mtrace();
  12057. #ifdef SystemLogMessage
  12058. DEBUG_INFO("errorCode: %s\n", errorCode);
  12059. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12060. DEBUG_INFO("errorDetails: %s\n", payload);
  12061. #endif
  12062. }
  12063. //===============================================
  12064. // Common routine
  12065. //===============================================
  12066. int initialConfigurationTable(void)
  12067. {
  12068. //clock_t start_t, end_t, total_t;
  12069. FILE *fp;
  12070. FILE *outfile;
  12071. char str[512]={0};
  12072. char sstr[256]={0};
  12073. int c = 0;
  12074. char *loc;
  12075. int confVersion = 6;
  12076. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12077. //start_t = clock();
  12078. //printf("Starting of the program, start_t = %ld\n", start_t);
  12079. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12080. // Check configuration file size is correct
  12081. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12082. {
  12083. struct stat st;
  12084. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12085. if(st.st_size < 3100)
  12086. {
  12087. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12088. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12089. }
  12090. }
  12091. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12092. {
  12093. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12094. if(outfile == NULL)
  12095. {
  12096. DEBUG_INFO("Error opening file\n");
  12097. return FALSE;
  12098. }
  12099. /*Core Profile*/
  12100. //AllowOfflineTxForUnknownId
  12101. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12105. //AuthorizationCacheEnabled
  12106. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12110. //AuthorizeRemoteTxRequests
  12111. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12115. //BlinkRepeat
  12116. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12120. //ClockAlignedDataInterval
  12121. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12125. //ConnectionTimeOut
  12126. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12130. //GetConfigurationMaxKeys
  12131. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12135. // HeartbeatInterval
  12136. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12140. // LightIntensity
  12141. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12145. // LocalAuthorizeOffline
  12146. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12150. // LocalPreAuthorize
  12151. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12155. // MaxEnergyOnInvalidId
  12156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12160. // MeterValuesAlignedData
  12161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12165. else
  12166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12168. // MeterValuesAlignedDataMaxLength
  12169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  12173. else
  12174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  12175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12176. // MeterValuesSampledData
  12177. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12181. else
  12182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12184. // MeterValuesSampledDataMaxLength
  12185. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  12189. else
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  12191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12192. // MeterValueSampleInterval
  12193. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12197. // MinimumStatusDuration
  12198. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12201. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12203. // NumberOfConnectors
  12204. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12207. {
  12208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12209. }
  12210. else
  12211. {
  12212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12213. }
  12214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12215. // ResetRetries
  12216. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12220. // ConnectorPhaseRotation
  12221. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12225. // ConnectorPhaseRotationMaxLength
  12226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12230. // StopTransactionOnEVSideDisconnect
  12231. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12235. // StopTransactionOnInvalidId
  12236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12240. // StopTxnAlignedData
  12241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12245. // StopTxnAlignedDataMaxLength
  12246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12250. // StopTxnSampledData
  12251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12255. else
  12256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12258. // StopTxnSampledDataMaxLength
  12259. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12262. {
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12264. }
  12265. else
  12266. {
  12267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12268. }
  12269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12270. // SupportedFeatureProfiles
  12271. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12275. // SupportedFeatureProfilesMaxLength
  12276. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12280. // TransactionMessageAttempts
  12281. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12284. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12286. // TransactionMessageRetryInterval
  12287. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12290. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12292. // UnlockConnectorOnEVSideDisconnect
  12293. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12297. // WebSocketPingInterval
  12298. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12302. // QueueOffLineStartTransactionMessage
  12303. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12307. // AuthorizationKey
  12308. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12312. // SecurityProfile
  12313. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12317. // DefaultPrice
  12318. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12322. // CustomDisplayCostAndPrice
  12323. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12327. // CustomIdleFeeAfterStop
  12328. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12332. // TimeOffset
  12333. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12337. // NextTimeOffsetTransitionDateTime
  12338. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12342. // TimeOffsetNextTransition
  12343. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12347. // Configuration Version
  12348. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12352. //* Local Auth List Management Profile*/
  12353. #if 0
  12354. //For OCTT Test Case
  12355. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12358. #endif
  12359. #if 1
  12360. //LocalAuthListEnabled
  12361. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12365. #endif
  12366. //LocalAuthListMaxLength
  12367. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12371. //SendLocalListMaxLength
  12372. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12376. //ReserveConnectorZeroSupported
  12377. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12381. //* Smart Charging Profile */
  12382. //ChargeProfileMaxStackLevel
  12383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12387. // ChargingScheduleAllowedChargingRateUnit
  12388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12392. // ChargingScheduleMaxPeriods
  12393. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12397. // ConnectorSwitch3to1PhaseSupported
  12398. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12402. // MaxChargingProfilesInstalled
  12403. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12407. fclose(outfile);
  12408. }
  12409. else
  12410. {
  12411. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12412. char keystr[60]={0};
  12413. char readonlystr[10]={0};
  12414. char valuestr[256]={0};
  12415. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12416. if(fp == NULL) {
  12417. DEBUG_INFO("Error opening file");
  12418. return FALSE;
  12419. }
  12420. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12421. {
  12422. //DEBUG_INFO("Get Configuration \n");
  12423. if(strlen(str) > 0)
  12424. {
  12425. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12426. //*************************key*********************************/
  12427. if(strstr(str, "key") != NULL)
  12428. {
  12429. loc = strstr(str, "key");
  12430. c = 0;
  12431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12432. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12433. {
  12434. sstr[c] = loc[strlen("key")+3+c];
  12435. c++;
  12436. }
  12437. sstr[c] = '\0';
  12438. strcpy(keystr,sstr);
  12439. }
  12440. //*************************readonly*********************************/
  12441. if(strstr(str, "readonly") != NULL)
  12442. {
  12443. loc = strstr(str, "readonly");
  12444. c = 0;
  12445. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12446. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12447. {
  12448. sstr[c] = loc[strlen("readonly")+2+c];
  12449. c++;
  12450. }
  12451. sstr[c] = '\0';
  12452. strcpy(readonlystr,sstr);
  12453. }
  12454. //*************************value*********************************/
  12455. if(strstr(str, "value") != NULL)
  12456. {
  12457. loc = strstr(str, "value");
  12458. c = 0;
  12459. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12460. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12461. {
  12462. sstr[c] = loc[strlen("value")+3+c];
  12463. c++;
  12464. }
  12465. sstr[c] = '\0';
  12466. strcpy(valuestr,sstr);
  12467. }
  12468. // DEBUG_INFO("keystr=%s\n",keystr);
  12469. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12470. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12471. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12472. {
  12473. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12474. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12476. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12477. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12478. }
  12479. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12480. {
  12481. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12482. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12484. }
  12485. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12486. {
  12487. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12489. }
  12490. if(strcmp(keystr, "BlinkRepeat") == 0)
  12491. {
  12492. //Charger.BlinkRepeat = Integer.parseInt(value);
  12493. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12495. }
  12496. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12497. {
  12498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12500. }
  12501. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12502. {
  12503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12505. }
  12506. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12507. {
  12508. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12510. }
  12511. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12512. {
  12513. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12515. HeartBeatWaitTime = atoi(valuestr);
  12516. }
  12517. if(strcmp(keystr, "LightIntensity") == 0)
  12518. {
  12519. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12521. }
  12522. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12523. {
  12524. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12526. }
  12527. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12528. {
  12529. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12531. }
  12532. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12533. {
  12534. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12536. }
  12537. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12538. {
  12539. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12541. }
  12542. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12543. {
  12544. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12546. }
  12547. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12548. {
  12549. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12551. }
  12552. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12553. {
  12554. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12556. }
  12557. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12558. {
  12559. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12561. }
  12562. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12563. {
  12564. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12566. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12567. }
  12568. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12569. {
  12570. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12572. }
  12573. if(strcmp(keystr, "ResetRetries") == 0)
  12574. {
  12575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12577. }
  12578. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12579. {
  12580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12582. }
  12583. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12584. {
  12585. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12587. }
  12588. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12589. {
  12590. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12592. }
  12593. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12594. {
  12595. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12597. }
  12598. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12599. {
  12600. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12602. }
  12603. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12604. {
  12605. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12607. }
  12608. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12609. {
  12610. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12612. }
  12613. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12614. {
  12615. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12617. }
  12618. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12619. {
  12620. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12622. }
  12623. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12624. {
  12625. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12627. }
  12628. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12629. {
  12630. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12632. TransactionMessageAttemptsValue = atoi(valuestr);
  12633. }
  12634. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12635. {
  12636. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12638. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12639. }
  12640. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12641. {
  12642. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12644. }
  12645. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12646. {
  12647. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12649. }
  12650. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12651. {
  12652. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12654. }
  12655. if(strcmp(keystr, "AuthorizationKey") == 0)
  12656. {
  12657. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12658. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12660. }
  12661. if(strcmp(keystr, "SecurityProfile") == 0)
  12662. {
  12663. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12665. }
  12666. if(strcmp(keystr, "DefaultPrice") == 0)
  12667. {
  12668. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12670. }
  12671. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12672. {
  12673. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12675. }
  12676. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12677. {
  12678. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12680. }
  12681. if(strcmp(keystr, "TimeOffset") == 0)
  12682. {
  12683. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12685. }
  12686. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12687. {
  12688. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12690. }
  12691. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12692. {
  12693. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12695. }
  12696. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12697. {
  12698. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12700. }
  12701. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12702. {
  12703. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12705. }
  12706. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12707. {
  12708. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12710. }
  12711. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12712. {
  12713. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12715. }
  12716. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12717. {
  12718. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12720. }
  12721. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12722. {
  12723. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12725. }
  12726. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12727. {
  12728. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12730. }
  12731. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12732. {
  12733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12735. }
  12736. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12737. {
  12738. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12740. }
  12741. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12742. {
  12743. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12745. }
  12746. }
  12747. }
  12748. fclose(fp);
  12749. }
  12750. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12751. {
  12752. return PASS;
  12753. }
  12754. else
  12755. {
  12756. return FAIL;
  12757. }
  12758. }
  12759. void StoreConfigurationTable(void)
  12760. {
  12761. FILE *outfile;
  12762. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12763. if(outfile == NULL)
  12764. {
  12765. DEBUG_INFO("Error opening file");
  12766. return ;
  12767. }
  12768. /*Core Profile*/
  12769. //AllowOfflineTxForUnknownId
  12770. /*
  12771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12772. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12775. */
  12776. //DEBUG_INFO("data=%s\n",data);
  12777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12778. //AuthorizationCacheEnabled
  12779. /*
  12780. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12783. */
  12784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12785. //AuthorizeRemoteTxRequests
  12786. /*
  12787. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12790. */
  12791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12792. //BlinkRepeat
  12793. /*
  12794. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12797. */
  12798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12799. //ClockAlignedDataInterval
  12800. /*
  12801. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12804. */
  12805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12806. //ConnectionTimeOut
  12807. /*
  12808. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12811. */
  12812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12813. //GetConfigurationMaxKeys
  12814. /*
  12815. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12818. */
  12819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12820. // HeartbeatInterval
  12821. /*
  12822. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12825. */
  12826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12827. // LightIntensity
  12828. /*
  12829. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12832. */
  12833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12834. // LocalAuthorizeOffline
  12835. /*
  12836. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12839. */
  12840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12841. // LocalPreAuthorize
  12842. /*
  12843. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12846. */
  12847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12848. // MaxEnergyOnInvalidId
  12849. /*
  12850. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12853. */
  12854. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12856. // MeterValuesAlignedData
  12857. /*
  12858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12861. */
  12862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12863. // MeterValuesAlignedDataMaxLength
  12864. /*
  12865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12868. */
  12869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12870. // MeterValuesSampledData
  12871. /*
  12872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12875. */
  12876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12877. // MeterValuesSampledDataMaxLength
  12878. /*
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12882. */
  12883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12884. // MeterValueSampleInterval
  12885. /*
  12886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12889. */
  12890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12891. // MinimumStatusDuration
  12892. /*
  12893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12896. */
  12897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12898. // NumberOfConnectors
  12899. /*
  12900. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12903. {
  12904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12905. }
  12906. else
  12907. {
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12909. }
  12910. */
  12911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12912. // ResetRetries
  12913. /*
  12914. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12917. */
  12918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12919. // ConnectorPhaseRotation
  12920. /*
  12921. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12924. */
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12926. // ConnectorPhaseRotationMaxLength
  12927. /*
  12928. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12931. */
  12932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12933. // StopTransactionOnEVSideDisconnect
  12934. /*
  12935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12938. */
  12939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12940. // StopTransactionOnInvalidId
  12941. /*
  12942. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12945. */
  12946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12947. // StopTxnAlignedData
  12948. /*
  12949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12952. */
  12953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12954. // StopTxnAlignedDataMaxLength
  12955. /*
  12956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12959. */
  12960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12961. // StopTxnSampledData
  12962. /*
  12963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12966. */
  12967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12968. // StopTxnSampledDataMaxLength
  12969. /*
  12970. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12973. */
  12974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12975. // SupportedFeatureProfiles
  12976. /*
  12977. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12980. */
  12981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12982. // SupportedFeatureProfilesMaxLength
  12983. /*
  12984. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12987. */
  12988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12989. // TransactionMessageAttempts
  12990. /*
  12991. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12994. */
  12995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12996. // TransactionMessageRetryInterval
  12997. /*
  12998. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13001. */
  13002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13003. // UnlockConnectorOnEVSideDisconnect
  13004. /*
  13005. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13008. */
  13009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13010. // WebSocketPingInterval
  13011. /*
  13012. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13015. */
  13016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13017. // QueueOffLineStartTransactionMessage
  13018. /*
  13019. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13022. */
  13023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13024. // AuthorizationKey
  13025. /*
  13026. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13029. */
  13030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13031. // SecurityProfile
  13032. /*
  13033. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13036. */
  13037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13038. // DefaultPrice
  13039. /*
  13040. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13043. */
  13044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13045. // CustomDisplayCostAndPrice
  13046. /*
  13047. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13050. */
  13051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13052. // CustomIdleFeeAfterStop
  13053. /*
  13054. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13057. */
  13058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13059. // TimeOffset
  13060. /*
  13061. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13064. */
  13065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13066. // NextTimeOffsetTransitionDateTime
  13067. /*
  13068. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13071. */
  13072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13073. // TimeOffsetNextTransition
  13074. /*
  13075. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13078. */
  13079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13080. // ConfigurationVersion
  13081. /*
  13082. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13085. */
  13086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13087. //* Local Auth List Management Profile*/
  13088. //LocalAuthListEnabled
  13089. /*
  13090. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13093. */
  13094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13095. //LocalAuthListMaxLength
  13096. /*
  13097. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13100. */
  13101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13102. //SendLocalListMaxLength
  13103. /*
  13104. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13107. */
  13108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13109. //ReserveConnectorZeroSupported
  13110. /*
  13111. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13114. */
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13116. //* Smart Charging Profile */
  13117. //ChargeProfileMaxStackLevel
  13118. /*
  13119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13122. */
  13123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13124. // ChargingScheduleAllowedChargingRateUnit
  13125. /*
  13126. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13129. */
  13130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13131. // ChargingScheduleMaxPeriods
  13132. /*
  13133. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13136. */
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13138. // ConnectorSwitch3to1PhaseSupported
  13139. /*
  13140. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13143. */
  13144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13145. // MaxChargingProfilesInstalled
  13146. /*
  13147. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13150. */
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13152. fclose(outfile);
  13153. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13154. }
  13155. void getKeyValue(char *keyReq)
  13156. {
  13157. int isEmpty = FALSE;
  13158. int isKnowKey = FALSE;
  13159. DEBUG_INFO("keyReq = %s\n", keyReq);
  13160. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13161. isEmpty = TRUE;
  13162. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13163. {
  13164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13167. {
  13168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13169. }
  13170. else
  13171. {
  13172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13173. }
  13174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13175. isKnowKey = TRUE;
  13176. }
  13177. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13178. {
  13179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13182. {
  13183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13184. }
  13185. else
  13186. {
  13187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13188. }
  13189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13190. isKnowKey = TRUE;
  13191. }
  13192. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13193. {
  13194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13197. {
  13198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13199. }
  13200. else
  13201. {
  13202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13203. }
  13204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13205. isKnowKey = TRUE;
  13206. }
  13207. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13208. {
  13209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13212. {
  13213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13214. }
  13215. else
  13216. {
  13217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13218. }
  13219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13220. isKnowKey = TRUE;
  13221. }
  13222. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13223. {
  13224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13227. {
  13228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13229. }
  13230. else
  13231. {
  13232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13233. }
  13234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13235. isKnowKey = TRUE;
  13236. }
  13237. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13238. {
  13239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13242. {
  13243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13244. }
  13245. else
  13246. {
  13247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13248. }
  13249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13250. isKnowKey = TRUE;
  13251. }
  13252. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13253. {
  13254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13257. {
  13258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13259. }
  13260. else
  13261. {
  13262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13263. }
  13264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13265. isKnowKey = TRUE;
  13266. }
  13267. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13268. {
  13269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13272. {
  13273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13274. }
  13275. else
  13276. {
  13277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13278. }
  13279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13280. isKnowKey = TRUE;
  13281. }
  13282. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13283. {
  13284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13287. {
  13288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13289. }
  13290. else
  13291. {
  13292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13293. }
  13294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13295. isKnowKey = TRUE;
  13296. }
  13297. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13298. {
  13299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13302. {
  13303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13304. }
  13305. else
  13306. {
  13307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13308. }
  13309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13310. isKnowKey = TRUE;
  13311. }
  13312. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13313. {
  13314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13317. {
  13318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13319. }
  13320. else
  13321. {
  13322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13323. }
  13324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13325. isKnowKey = TRUE;
  13326. }
  13327. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13328. {
  13329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13332. {
  13333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13334. }
  13335. else
  13336. {
  13337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13338. }
  13339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13340. isKnowKey = TRUE;
  13341. }
  13342. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13343. {
  13344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13347. {
  13348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13349. }
  13350. else
  13351. {
  13352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13353. }
  13354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13355. isKnowKey = TRUE;
  13356. }
  13357. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13358. {
  13359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13362. {
  13363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13364. }
  13365. else
  13366. {
  13367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13368. }
  13369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13370. isKnowKey = TRUE;
  13371. }
  13372. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13373. {
  13374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13377. {
  13378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13379. }
  13380. else
  13381. {
  13382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13383. }
  13384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13385. isKnowKey = TRUE;
  13386. }
  13387. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13388. {
  13389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13392. {
  13393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13394. }
  13395. else
  13396. {
  13397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13398. }
  13399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13400. isKnowKey = TRUE;
  13401. }
  13402. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13403. {
  13404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13407. {
  13408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13409. }
  13410. else
  13411. {
  13412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13413. }
  13414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13415. isKnowKey = TRUE;
  13416. }
  13417. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13418. {
  13419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13422. {
  13423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13424. }
  13425. else
  13426. {
  13427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13428. }
  13429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13430. isKnowKey = TRUE;
  13431. }
  13432. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13433. {
  13434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13437. {
  13438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13439. }
  13440. else
  13441. {
  13442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13443. }
  13444. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13446. isKnowKey = TRUE;
  13447. }
  13448. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13449. {
  13450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13453. {
  13454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13455. }
  13456. else
  13457. {
  13458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13459. }
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13461. isKnowKey = TRUE;
  13462. }
  13463. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13464. {
  13465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13468. {
  13469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13470. }
  13471. else
  13472. {
  13473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13474. }
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13476. isKnowKey = TRUE;
  13477. }
  13478. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13479. {
  13480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13483. {
  13484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13485. }
  13486. else
  13487. {
  13488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13489. }
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13491. isKnowKey = TRUE;
  13492. }
  13493. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13494. {
  13495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13498. {
  13499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13500. }
  13501. else
  13502. {
  13503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13504. }
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13506. isKnowKey = TRUE;
  13507. }
  13508. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13509. {
  13510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13513. {
  13514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13515. }
  13516. else
  13517. {
  13518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13519. }
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13521. isKnowKey = TRUE;
  13522. }
  13523. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13524. {
  13525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13528. {
  13529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13530. }
  13531. else
  13532. {
  13533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13534. }
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13536. isKnowKey = TRUE;
  13537. }
  13538. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13539. {
  13540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13543. {
  13544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13545. }
  13546. else
  13547. {
  13548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13549. }
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13551. isKnowKey = TRUE;
  13552. }
  13553. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13554. {
  13555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13558. {
  13559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13560. }
  13561. else
  13562. {
  13563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13564. }
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13566. isKnowKey = TRUE;
  13567. }
  13568. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13569. {
  13570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13573. {
  13574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13575. }
  13576. else
  13577. {
  13578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13579. }
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13581. isKnowKey = TRUE;
  13582. }
  13583. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13584. {
  13585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13588. {
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13590. }
  13591. else
  13592. {
  13593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13594. }
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13596. isKnowKey = TRUE;
  13597. }
  13598. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13599. {
  13600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13603. {
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13605. }
  13606. else
  13607. {
  13608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13609. }
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13611. isKnowKey = TRUE;
  13612. }
  13613. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13614. {
  13615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13618. {
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13620. }
  13621. else
  13622. {
  13623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13624. }
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13626. isKnowKey = TRUE;
  13627. }
  13628. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13629. {
  13630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13633. {
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13635. }
  13636. else
  13637. {
  13638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13639. }
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13641. isKnowKey = TRUE;
  13642. }
  13643. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13644. {
  13645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13648. {
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13650. }
  13651. else
  13652. {
  13653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13654. }
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13656. isKnowKey = TRUE;
  13657. }
  13658. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13659. {
  13660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13663. {
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13665. }
  13666. else
  13667. {
  13668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13669. }
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13671. isKnowKey = TRUE;
  13672. }
  13673. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13674. {
  13675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13678. {
  13679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13680. }
  13681. else
  13682. {
  13683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13684. }
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13686. isKnowKey = TRUE;
  13687. }
  13688. /*
  13689. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13690. {
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13694. {
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13696. }
  13697. else
  13698. {
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13700. }
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13702. isKnowKey = TRUE;
  13703. }*/
  13704. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13705. {
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13709. {
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13711. }
  13712. else
  13713. {
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13715. }
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13717. isKnowKey = TRUE;
  13718. }
  13719. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13720. {
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13724. {
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13726. }
  13727. else
  13728. {
  13729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13730. }
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13732. isKnowKey = TRUE;
  13733. }
  13734. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13735. {
  13736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13739. {
  13740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13741. }
  13742. else
  13743. {
  13744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13745. }
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13747. isKnowKey = TRUE;
  13748. }
  13749. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13750. {
  13751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13754. {
  13755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13756. }
  13757. else
  13758. {
  13759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13760. }
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13762. isKnowKey = TRUE;
  13763. }
  13764. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13765. {
  13766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13769. {
  13770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13771. }
  13772. else
  13773. {
  13774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13775. }
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13777. isKnowKey = TRUE;
  13778. }
  13779. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13780. {
  13781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13784. {
  13785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13786. }
  13787. else
  13788. {
  13789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13790. }
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13792. isKnowKey = TRUE;
  13793. }
  13794. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13795. {
  13796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13799. {
  13800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13801. }
  13802. else
  13803. {
  13804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13805. }
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13807. isKnowKey = TRUE;
  13808. }
  13809. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13810. {
  13811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13814. {
  13815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13816. }
  13817. else
  13818. {
  13819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13820. }
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13822. isKnowKey = TRUE;
  13823. }
  13824. #if 1
  13825. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13826. {
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13829. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13830. {
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13832. }
  13833. else
  13834. {
  13835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13836. }
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13838. isKnowKey = TRUE;
  13839. }
  13840. #endif
  13841. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13845. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13848. }
  13849. else
  13850. {
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13852. }
  13853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13854. isKnowKey = TRUE;
  13855. }
  13856. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13860. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13863. }
  13864. else
  13865. {
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13867. }
  13868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13869. isKnowKey = TRUE;
  13870. }
  13871. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13872. {
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13875. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13876. {
  13877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13878. }
  13879. else
  13880. {
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13882. }
  13883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13884. isKnowKey = TRUE;
  13885. }
  13886. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13887. {
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13890. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13891. {
  13892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13893. }
  13894. else
  13895. {
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13897. }
  13898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13899. isKnowKey = TRUE;
  13900. }
  13901. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13902. {
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13905. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13906. {
  13907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13908. }
  13909. else
  13910. {
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13912. }
  13913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13914. isKnowKey = TRUE;
  13915. }
  13916. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13917. {
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13920. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13921. {
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13923. }
  13924. else
  13925. {
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13927. }
  13928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13929. isKnowKey = TRUE;
  13930. }
  13931. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13932. {
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13935. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13936. {
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13938. }
  13939. else
  13940. {
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13942. }
  13943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13944. isKnowKey = TRUE;
  13945. }
  13946. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13947. {
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13950. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13951. {
  13952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13953. }
  13954. else
  13955. {
  13956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13957. }
  13958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13959. isKnowKey = TRUE;
  13960. }
  13961. //=========================================================
  13962. if(!isEmpty && !isKnowKey)
  13963. {
  13964. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13965. strcpy(unknownkey[UnknownKeynum], keyReq);
  13966. UnknownKeynum = UnknownKeynum + 1;
  13967. }
  13968. }
  13969. void processUnkownKey(void)
  13970. {
  13971. DEBUG_INFO("processUnkownKey...\n");
  13972. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13973. for(int index=0; index < UnknownKeynum; index++)
  13974. {
  13975. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13976. {
  13977. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13978. }
  13979. }
  13980. }
  13981. int setKeyValue(char *key, char *value)
  13982. {
  13983. int isSuccess = NotSupported;
  13984. int check_ascii=0;
  13985. char str[256]={0};
  13986. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13987. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13988. {
  13989. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13991. {
  13992. strcpy(str, (const char*)value);
  13993. for(int i = 0; str[i]; i++){
  13994. str[i] = tolower(str[i]);
  13995. }
  13996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13997. isSuccess = ConfigurationStatus_Accepted;
  13998. }
  13999. else
  14000. {
  14001. isSuccess = ConfigurationStatus_Rejected;
  14002. }
  14003. }
  14004. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14005. {
  14006. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14008. {
  14009. strcpy(str, (const char*)value);
  14010. for(int i = 0; str[i]; i++){
  14011. str[i] = tolower(str[i]);
  14012. }
  14013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14014. isSuccess = ConfigurationStatus_Accepted;
  14015. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14016. }
  14017. else
  14018. {
  14019. isSuccess = ConfigurationStatus_Rejected;
  14020. }
  14021. }
  14022. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14023. {
  14024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14025. {
  14026. strcpy(str, (const char*)value);
  14027. for(int i = 0; str[i]; i++)
  14028. {
  14029. str[i] = tolower(str[i]);
  14030. }
  14031. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14033. isSuccess = ConfigurationStatus_Accepted;
  14034. }
  14035. else
  14036. {
  14037. isSuccess = ConfigurationStatus_Rejected;
  14038. }
  14039. }
  14040. if(strcmp(key, "BlinkRepeat") == 0)
  14041. {
  14042. //Charger.BlinkRepeat = Integer.parseInt(value);
  14043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14044. {
  14045. check_ascii = value[0];
  14046. if( (check_ascii < 48) || (check_ascii > 57) )
  14047. {
  14048. isSuccess = ConfigurationStatus_Rejected;
  14049. }
  14050. else
  14051. {
  14052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14053. isSuccess = ConfigurationStatus_Accepted;
  14054. }
  14055. }
  14056. else
  14057. {
  14058. isSuccess = ConfigurationStatus_Rejected;
  14059. }
  14060. }
  14061. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14062. {
  14063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14064. {
  14065. check_ascii = value[0];
  14066. if( (check_ascii < 48) || (check_ascii > 57) )
  14067. {
  14068. isSuccess = ConfigurationStatus_Rejected;
  14069. }
  14070. else
  14071. {
  14072. if((atoi(value) == 0) || (atoi(value) >= 10))
  14073. {
  14074. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14076. isSuccess = ConfigurationStatus_Accepted;
  14077. }
  14078. else
  14079. isSuccess = ConfigurationStatus_Rejected;
  14080. }
  14081. }
  14082. else
  14083. {
  14084. isSuccess = ConfigurationStatus_Rejected;
  14085. }
  14086. }
  14087. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14088. {
  14089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14090. {
  14091. check_ascii = value[0];
  14092. if( (check_ascii < 48) || (check_ascii > 57) )
  14093. {
  14094. isSuccess = ConfigurationStatus_Rejected;
  14095. }
  14096. else
  14097. {
  14098. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14100. isSuccess = ConfigurationStatus_Accepted;
  14101. }
  14102. }
  14103. else
  14104. {
  14105. isSuccess = ConfigurationStatus_Rejected;
  14106. }
  14107. }
  14108. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14109. {
  14110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14111. {
  14112. check_ascii = value[0];
  14113. if( (check_ascii < 48) || (check_ascii > 57) )
  14114. {
  14115. isSuccess = ConfigurationStatus_Rejected;
  14116. }
  14117. else
  14118. {
  14119. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14121. isSuccess = ConfigurationStatus_Accepted;
  14122. }
  14123. }
  14124. else
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. }
  14129. if(strcmp(key, "HeartbeatInterval") == 0)
  14130. {
  14131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14132. {
  14133. check_ascii = value[0];
  14134. if( (check_ascii < 48) || (check_ascii > 57) )
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. else
  14139. {
  14140. if((atoi(value) == 0) || (atoi(value) >= 10))
  14141. {
  14142. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14144. HeartBeatWaitTime = atoi(value);
  14145. isSuccess = ConfigurationStatus_Accepted;
  14146. }
  14147. else
  14148. {
  14149. isSuccess = ConfigurationStatus_Rejected;
  14150. }
  14151. }
  14152. }
  14153. else
  14154. {
  14155. isSuccess = ConfigurationStatus_Rejected;
  14156. }
  14157. }
  14158. if(strcmp(key, "LightIntensity") == 0)
  14159. {
  14160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14161. {
  14162. check_ascii = value[0];
  14163. if( (check_ascii < 48) || (check_ascii > 57) )
  14164. {
  14165. isSuccess = ConfigurationStatus_Rejected;
  14166. }
  14167. else
  14168. {
  14169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14170. isSuccess = ConfigurationStatus_Accepted;
  14171. }
  14172. }
  14173. else
  14174. {
  14175. isSuccess = ConfigurationStatus_Rejected;
  14176. }
  14177. }
  14178. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14179. {
  14180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14181. {
  14182. strcpy(str, (const char*)value);
  14183. for(int i = 0; str[i]; i++)
  14184. {
  14185. str[i] = tolower(str[i]);
  14186. }
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14188. isSuccess = ConfigurationStatus_Accepted;
  14189. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14190. }
  14191. else
  14192. {
  14193. isSuccess = ConfigurationStatus_Rejected;
  14194. }
  14195. }
  14196. if(strcmp(key, "LocalPreAuthorize") == 0)
  14197. {
  14198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14199. {
  14200. strcpy(str, (const char*)value);
  14201. for(int i = 0; str[i]; i++)
  14202. {
  14203. str[i] = tolower(str[i]);
  14204. }
  14205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14206. isSuccess = ConfigurationStatus_Accepted;
  14207. }
  14208. else
  14209. {
  14210. isSuccess = ConfigurationStatus_Rejected;
  14211. }
  14212. }
  14213. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14214. {
  14215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14216. {
  14217. check_ascii = value[0];
  14218. if( (check_ascii < 48) || (check_ascii > 57) )
  14219. {
  14220. isSuccess = ConfigurationStatus_Rejected;
  14221. }
  14222. else
  14223. {
  14224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14225. isSuccess = ConfigurationStatus_Accepted;
  14226. }
  14227. }
  14228. else
  14229. {
  14230. isSuccess = ConfigurationStatus_Rejected;
  14231. }
  14232. }
  14233. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14234. {
  14235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14236. {
  14237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14238. isSuccess = ConfigurationStatus_Accepted;
  14239. }
  14240. else
  14241. {
  14242. isSuccess = ConfigurationStatus_Rejected;
  14243. }
  14244. }
  14245. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14246. {
  14247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14248. {
  14249. check_ascii = value[0];
  14250. if( (check_ascii < 48) || (check_ascii > 57) )
  14251. {
  14252. isSuccess = ConfigurationStatus_Rejected;
  14253. }
  14254. else
  14255. {
  14256. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14258. isSuccess = ConfigurationStatus_Accepted;
  14259. }
  14260. }
  14261. else
  14262. {
  14263. isSuccess = ConfigurationStatus_Rejected;
  14264. }
  14265. }
  14266. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14267. {
  14268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14269. {
  14270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14271. isSuccess = ConfigurationStatus_Accepted;
  14272. }
  14273. else
  14274. {
  14275. isSuccess = ConfigurationStatus_Rejected;
  14276. }
  14277. }
  14278. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14279. {
  14280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14281. {
  14282. check_ascii = value[0];
  14283. if( (check_ascii < 48) || (check_ascii > 57) )
  14284. {
  14285. isSuccess = ConfigurationStatus_Rejected;
  14286. }
  14287. else
  14288. {
  14289. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14291. isSuccess = ConfigurationStatus_Accepted;
  14292. }
  14293. }
  14294. else
  14295. {
  14296. isSuccess = ConfigurationStatus_Rejected;
  14297. }
  14298. }
  14299. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14300. {
  14301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14302. {
  14303. check_ascii = value[0];
  14304. if( (check_ascii < 48) || (check_ascii > 57) )
  14305. {
  14306. isSuccess = ConfigurationStatus_Rejected;
  14307. }
  14308. else
  14309. {
  14310. if((atoi(value) == 0) || (atoi(value) >= 10))
  14311. {
  14312. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14314. isSuccess = ConfigurationStatus_Accepted;
  14315. }
  14316. else
  14317. {
  14318. isSuccess = ConfigurationStatus_Rejected;
  14319. }
  14320. }
  14321. }
  14322. else
  14323. {
  14324. isSuccess = ConfigurationStatus_Rejected;
  14325. }
  14326. }
  14327. if(strcmp(key, "MinimumStatusDuration") == 0)
  14328. {
  14329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14330. {
  14331. check_ascii = value[0];
  14332. if( (check_ascii < 48) || (check_ascii > 57) )
  14333. {
  14334. isSuccess = ConfigurationStatus_Rejected;
  14335. }
  14336. else
  14337. {
  14338. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14339. {
  14340. isSuccess = ConfigurationStatus_Rejected;
  14341. }
  14342. else
  14343. {
  14344. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14346. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14347. isSuccess = ConfigurationStatus_Accepted;
  14348. }
  14349. }
  14350. }
  14351. else
  14352. {
  14353. isSuccess = ConfigurationStatus_Rejected;
  14354. }
  14355. }
  14356. if(strcmp(key, "NumberOfConnectors") == 0)
  14357. {
  14358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14359. {
  14360. check_ascii = value[0];
  14361. if( (check_ascii < 48) || (check_ascii > 57) )
  14362. {
  14363. isSuccess = ConfigurationStatus_Rejected;
  14364. }
  14365. else
  14366. {
  14367. //Charger.ResetRetries = Integer.parseInt(value);
  14368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14369. isSuccess = ConfigurationStatus_Accepted;
  14370. }
  14371. }
  14372. else
  14373. {
  14374. isSuccess = ConfigurationStatus_Rejected;
  14375. }
  14376. }
  14377. if(strcmp(key, "ResetRetries") == 0)
  14378. {
  14379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14380. {
  14381. check_ascii = value[0];
  14382. if( (check_ascii < 48) || (check_ascii > 57) )
  14383. {
  14384. isSuccess = ConfigurationStatus_Rejected;
  14385. }
  14386. else
  14387. {
  14388. //Charger.ResetRetries = Integer.parseInt(value);
  14389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14390. isSuccess = ConfigurationStatus_Accepted;
  14391. }
  14392. }
  14393. else
  14394. {
  14395. isSuccess = ConfigurationStatus_Rejected;
  14396. }
  14397. }
  14398. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14399. {
  14400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14401. {
  14402. strcpy(str, (const char*)value);
  14403. for(int i = 0; str[i]; i++)
  14404. {
  14405. str[i] = tolower(str[i]);
  14406. }
  14407. if(strcmp(str, "notapplicable")== 0)
  14408. {
  14409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14410. isSuccess = ConfigurationStatus_Accepted;
  14411. }
  14412. else if(strcmp(str, "unknown")== 0)
  14413. {
  14414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14415. isSuccess = ConfigurationStatus_Accepted;
  14416. }
  14417. else if(strcmp(str, "rst")== 0)
  14418. {
  14419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14420. isSuccess = ConfigurationStatus_Accepted;
  14421. }
  14422. else if(strcmp(str, "rts")== 0)
  14423. {
  14424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14425. isSuccess = ConfigurationStatus_Accepted;
  14426. }
  14427. else if(strcmp(str, "srt")== 0)
  14428. {
  14429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14430. isSuccess = ConfigurationStatus_Accepted;
  14431. }
  14432. else if(strcmp(str, "str")== 0)
  14433. {
  14434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14435. isSuccess = ConfigurationStatus_Accepted;
  14436. }
  14437. else if(strcmp(str, "trs")== 0)
  14438. {
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14440. isSuccess = ConfigurationStatus_Accepted;
  14441. }
  14442. else if(strcmp(str, "tsr")== 0)
  14443. {
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14445. isSuccess = ConfigurationStatus_Accepted;
  14446. }
  14447. else
  14448. {
  14449. isSuccess = ConfigurationStatus_Rejected;
  14450. }
  14451. }
  14452. else
  14453. {
  14454. isSuccess = ConfigurationStatus_Rejected;
  14455. }
  14456. }
  14457. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14458. {
  14459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14460. {
  14461. check_ascii = value[0];
  14462. if( (check_ascii < 48) || (check_ascii > 57) )
  14463. {
  14464. isSuccess = ConfigurationStatus_Rejected;
  14465. }
  14466. else
  14467. {
  14468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14469. isSuccess = ConfigurationStatus_Accepted;
  14470. }
  14471. }
  14472. else
  14473. {
  14474. isSuccess = ConfigurationStatus_Rejected;
  14475. }
  14476. }
  14477. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14478. {
  14479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14480. {
  14481. strcpy(str, (const char*)value);
  14482. for(int i = 0; str[i]; i++)
  14483. {
  14484. str[i] = tolower(str[i]);
  14485. }
  14486. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14488. isSuccess = ConfigurationStatus_Accepted;
  14489. }
  14490. else
  14491. {
  14492. isSuccess = ConfigurationStatus_Rejected;
  14493. }
  14494. }
  14495. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14496. {
  14497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14498. {
  14499. strcpy(str, (const char*)value);
  14500. for(int i = 0; str[i]; i++)
  14501. {
  14502. str[i] = tolower(str[i]);
  14503. }
  14504. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14506. isSuccess = ConfigurationStatus_Accepted;
  14507. }
  14508. else
  14509. {
  14510. isSuccess = ConfigurationStatus_Rejected;
  14511. }
  14512. }
  14513. if(strcmp(key, "StopTxnAlignedData") == 0)
  14514. {
  14515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14516. {
  14517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14518. isSuccess = ConfigurationStatus_Accepted;
  14519. }
  14520. else
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. }
  14525. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14526. {
  14527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14528. {
  14529. check_ascii = value[0];
  14530. if( (check_ascii < 48) || (check_ascii > 57) )
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. else
  14535. {
  14536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14537. isSuccess = ConfigurationStatus_Accepted;
  14538. }
  14539. }
  14540. else
  14541. {
  14542. isSuccess = ConfigurationStatus_Rejected;
  14543. }
  14544. }
  14545. if(strcmp(key, "StopTxnSampledData") == 0)
  14546. {
  14547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14548. {
  14549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14550. isSuccess = ConfigurationStatus_Accepted;
  14551. }
  14552. else
  14553. {
  14554. isSuccess = ConfigurationStatus_Rejected;
  14555. }
  14556. }
  14557. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14558. {
  14559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14560. {
  14561. check_ascii = value[0];
  14562. if( (check_ascii < 48) || (check_ascii > 57) )
  14563. {
  14564. isSuccess = ConfigurationStatus_Rejected;
  14565. }
  14566. else
  14567. {
  14568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14569. isSuccess = ConfigurationStatus_Accepted;
  14570. }
  14571. }
  14572. else
  14573. {
  14574. isSuccess = ConfigurationStatus_Rejected;
  14575. }
  14576. }
  14577. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14578. {
  14579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14580. {
  14581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14582. isSuccess = ConfigurationStatus_Accepted;
  14583. }
  14584. else
  14585. {
  14586. isSuccess = ConfigurationStatus_Rejected;
  14587. }
  14588. }
  14589. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14590. {
  14591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14592. {
  14593. check_ascii = value[0];
  14594. if( (check_ascii < 48) || (check_ascii > 57) )
  14595. {
  14596. isSuccess = ConfigurationStatus_Rejected;
  14597. }
  14598. else
  14599. {
  14600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14601. isSuccess = ConfigurationStatus_Accepted;
  14602. }
  14603. }
  14604. else
  14605. {
  14606. isSuccess = ConfigurationStatus_Rejected;
  14607. }
  14608. }
  14609. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14610. {
  14611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14612. {
  14613. check_ascii = value[0];
  14614. if( (check_ascii < 48) || (check_ascii > 57) )
  14615. {
  14616. isSuccess = ConfigurationStatus_Rejected;
  14617. }
  14618. else
  14619. {
  14620. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14622. TransactionMessageAttemptsValue = atoi(value);
  14623. isSuccess = ConfigurationStatus_Accepted;
  14624. }
  14625. }
  14626. else
  14627. {
  14628. isSuccess = ConfigurationStatus_Rejected;
  14629. }
  14630. }
  14631. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14632. {
  14633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14634. {
  14635. check_ascii = value[0];
  14636. if( (check_ascii < 48) || (check_ascii > 57) )
  14637. {
  14638. isSuccess = ConfigurationStatus_Rejected;
  14639. }
  14640. else
  14641. {
  14642. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14644. TransactionMessageRetryIntervalValue = atoi(value);
  14645. isSuccess = ConfigurationStatus_Accepted;
  14646. }
  14647. }
  14648. else
  14649. {
  14650. isSuccess = ConfigurationStatus_Rejected;
  14651. }
  14652. }
  14653. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14654. {
  14655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14656. {
  14657. strcpy(str, (const char*)value);
  14658. for(int i = 0; str[i]; i++)
  14659. {
  14660. str[i] = tolower(str[i]);
  14661. }
  14662. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14664. isSuccess = ConfigurationStatus_Accepted;
  14665. }
  14666. else
  14667. {
  14668. isSuccess = ConfigurationStatus_Rejected;
  14669. }
  14670. }
  14671. if(strcmp(key, "WebSocketPingInterval") == 0)
  14672. {
  14673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14674. {
  14675. check_ascii = value[0];
  14676. if( (check_ascii < 48) || (check_ascii > 57) )
  14677. {
  14678. isSuccess = ConfigurationStatus_Rejected;
  14679. }
  14680. else
  14681. {
  14682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14683. isSuccess = ConfigurationStatus_Accepted;
  14684. }
  14685. }
  14686. else
  14687. {
  14688. isSuccess = ConfigurationStatus_Rejected;
  14689. }
  14690. }
  14691. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14692. {
  14693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14694. {
  14695. strcpy(str, (const char*)value);
  14696. for(int i = 0; str[i]; i++)
  14697. {
  14698. str[i] = tolower(str[i]);
  14699. }
  14700. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14702. isSuccess = ConfigurationStatus_Accepted;
  14703. }
  14704. else
  14705. {
  14706. isSuccess = ConfigurationStatus_Rejected;
  14707. }
  14708. }
  14709. if(strcmp(key, "AuthorizationKey") == 0)
  14710. {
  14711. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14712. {
  14713. strcpy(str, (const char*)value);
  14714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14715. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14716. isSuccess = ConfigurationStatus_Accepted;
  14717. }
  14718. else
  14719. {
  14720. isSuccess = ConfigurationStatus_Rejected;
  14721. }
  14722. }
  14723. if(strcmp(key, "SecurityProfile") == 0)
  14724. {
  14725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14726. {
  14727. check_ascii = value[0];
  14728. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14729. {
  14730. isSuccess = ConfigurationStatus_Rejected;
  14731. }
  14732. else if(check_ascii == 0x33)
  14733. {
  14734. isSuccess = NotSupported;
  14735. }
  14736. else
  14737. {
  14738. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14739. {
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14741. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14742. isSuccess = ConfigurationStatus_Accepted;
  14743. }
  14744. else
  14745. isSuccess = ConfigurationStatus_Rejected;
  14746. }
  14747. }
  14748. else
  14749. {
  14750. isSuccess = ConfigurationStatus_Rejected;
  14751. }
  14752. }
  14753. if(strcmp(key, "DefaultPrice") == 0)
  14754. {
  14755. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14756. {
  14757. strcpy(str, (const char*)value);
  14758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14759. isSuccess = ConfigurationStatus_Accepted;
  14760. }
  14761. else
  14762. {
  14763. isSuccess = ConfigurationStatus_Rejected;
  14764. }
  14765. }
  14766. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14767. {
  14768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14769. {
  14770. strcpy(str, (const char*)value);
  14771. for(int i = 0; str[i]; i++)
  14772. {
  14773. str[i] = tolower(str[i]);
  14774. }
  14775. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14777. isSuccess = ConfigurationStatus_Accepted;
  14778. }
  14779. else
  14780. {
  14781. isSuccess = ConfigurationStatus_Rejected;
  14782. }
  14783. }
  14784. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14785. {
  14786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14787. {
  14788. strcpy(str, (const char*)value);
  14789. for(int i = 0; str[i]; i++)
  14790. {
  14791. str[i] = tolower(str[i]);
  14792. }
  14793. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14795. isSuccess = ConfigurationStatus_Accepted;
  14796. }
  14797. else
  14798. {
  14799. isSuccess = ConfigurationStatus_Rejected;
  14800. }
  14801. }
  14802. if(strcmp(key, "TimeOffset") == 0)
  14803. {
  14804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14805. {
  14806. strcpy(str, (const char*)value);
  14807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14808. isSuccess = ConfigurationStatus_Accepted;
  14809. }
  14810. else
  14811. {
  14812. isSuccess = ConfigurationStatus_Rejected;
  14813. }
  14814. }
  14815. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14816. {
  14817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14818. {
  14819. strcpy(str, (const char*)value);
  14820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14821. isSuccess = ConfigurationStatus_Accepted;
  14822. }
  14823. else
  14824. {
  14825. isSuccess = ConfigurationStatus_Rejected;
  14826. }
  14827. }
  14828. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14829. {
  14830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14831. {
  14832. strcpy(str, (const char*)value);
  14833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14834. isSuccess = ConfigurationStatus_Accepted;
  14835. }
  14836. else
  14837. {
  14838. isSuccess = ConfigurationStatus_Rejected;
  14839. }
  14840. }
  14841. #if 0
  14842. //For OCPP Test Case
  14843. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14844. {
  14845. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14846. {
  14847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14848. isSuccess = ConfigurationStatus_Accepted;
  14849. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14850. }
  14851. else
  14852. {
  14853. isSuccess = ConfigurationStatus_Rejected;
  14854. }
  14855. }
  14856. #endif
  14857. #if 1
  14858. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14859. {
  14860. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14861. {
  14862. strcpy(str, (const char*)value);
  14863. for(int i = 0; str[i]; i++)
  14864. {
  14865. str[i] = tolower(str[i]);
  14866. }
  14867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14868. isSuccess = ConfigurationStatus_Accepted;
  14869. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14870. }
  14871. else
  14872. {
  14873. isSuccess = ConfigurationStatus_Rejected;
  14874. }
  14875. }
  14876. #endif
  14877. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14878. {
  14879. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14880. {
  14881. check_ascii = value[0];
  14882. if( (check_ascii < 48) || (check_ascii > 57) )
  14883. {
  14884. isSuccess = ConfigurationStatus_Rejected;
  14885. }
  14886. else
  14887. {
  14888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14889. isSuccess = ConfigurationStatus_Accepted;
  14890. }
  14891. }
  14892. else
  14893. {
  14894. isSuccess = ConfigurationStatus_Rejected;
  14895. }
  14896. }
  14897. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14898. {
  14899. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14900. {
  14901. check_ascii = value[0];
  14902. if( (check_ascii < 48) || (check_ascii > 57) )
  14903. {
  14904. isSuccess = ConfigurationStatus_Rejected;
  14905. }
  14906. else
  14907. {
  14908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14909. isSuccess = ConfigurationStatus_Accepted;
  14910. }
  14911. }
  14912. else
  14913. {
  14914. isSuccess = ConfigurationStatus_Rejected;
  14915. }
  14916. }
  14917. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14918. {
  14919. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14920. {
  14921. strcpy(str, (const char*)value);
  14922. for(int i = 0; str[i]; i++)
  14923. {
  14924. str[i] = tolower(str[i]);
  14925. }
  14926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14927. isSuccess = ConfigurationStatus_Accepted;
  14928. }
  14929. else
  14930. {
  14931. isSuccess = ConfigurationStatus_Rejected;
  14932. }
  14933. }
  14934. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14935. {
  14936. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14937. {
  14938. check_ascii = value[0];
  14939. if( (check_ascii < 48) || (check_ascii > 57) )
  14940. {
  14941. isSuccess = ConfigurationStatus_Rejected;
  14942. }
  14943. else
  14944. {
  14945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14946. isSuccess = ConfigurationStatus_Accepted;
  14947. }
  14948. }
  14949. else
  14950. {
  14951. isSuccess = ConfigurationStatus_Rejected;
  14952. }
  14953. }
  14954. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14955. {
  14956. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14957. {
  14958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14959. isSuccess = ConfigurationStatus_Accepted;
  14960. }
  14961. else
  14962. {
  14963. isSuccess = ConfigurationStatus_Rejected;
  14964. }
  14965. }
  14966. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14967. {
  14968. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14969. {
  14970. check_ascii = value[0];
  14971. if( (check_ascii < 48) || (check_ascii > 57) )
  14972. {
  14973. isSuccess = ConfigurationStatus_Rejected;
  14974. }
  14975. else
  14976. {
  14977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14978. isSuccess = ConfigurationStatus_Accepted;
  14979. }
  14980. }
  14981. else
  14982. {
  14983. isSuccess = ConfigurationStatus_Rejected;
  14984. }
  14985. }
  14986. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14987. {
  14988. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14989. {
  14990. strcpy(str, (const char*)value);
  14991. for(int i = 0; str[i]; i++)
  14992. {
  14993. str[i] = tolower(str[i]);
  14994. }
  14995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14996. isSuccess = ConfigurationStatus_Accepted;
  14997. }
  14998. else
  14999. {
  15000. isSuccess = ConfigurationStatus_Rejected;
  15001. }
  15002. }
  15003. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15004. {
  15005. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15006. {
  15007. check_ascii = value[0];
  15008. if( (check_ascii < 48) || (check_ascii > 57) )
  15009. {
  15010. isSuccess = ConfigurationStatus_Rejected;
  15011. }
  15012. else
  15013. {
  15014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15015. isSuccess = ConfigurationStatus_Accepted;
  15016. }
  15017. }
  15018. else
  15019. {
  15020. isSuccess = ConfigurationStatus_Rejected;
  15021. }
  15022. }
  15023. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15024. return isSuccess;
  15025. }
  15026. int TransactionMessageAttemptsGet(void)
  15027. {
  15028. return TransactionMessageAttemptsValue;
  15029. }
  15030. int FirstHeartBeatResponse(void)
  15031. {
  15032. return FirstHeartBeat;
  15033. }
  15034. int TransactionMessageRetryIntervalGet(void)
  15035. {
  15036. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15037. }
  15038. int ReadHttpStatus(int sock)
  15039. {
  15040. //char c;
  15041. char buff[1024]="",*ptr=buff+1;
  15042. int bytes_received, status;
  15043. DEBUG_INFO("Begin Response ..\n");
  15044. while((bytes_received = recv(sock, ptr, 1, 0))){
  15045. if(bytes_received==-1){
  15046. perror("ReadHttpStatus");
  15047. exit(1);
  15048. }
  15049. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15050. ptr++;
  15051. }
  15052. *ptr=0;
  15053. ptr=buff+1;
  15054. sscanf(ptr,"%*s %d ", &status);
  15055. DEBUG_INFO("%s\n",ptr);
  15056. DEBUG_INFO("status=%d\n",status);
  15057. DEBUG_INFO("End Response ..\n");
  15058. return (bytes_received>0)?status:0;
  15059. }
  15060. //the only filed that it parsed is 'Content-Length'
  15061. int ParseHeader(int sock)
  15062. {
  15063. //char c;
  15064. char buff[1024]="",*ptr=buff+4;
  15065. int bytes_received;
  15066. DEBUG_INFO("Begin HEADER ..\n");
  15067. while((bytes_received = recv(sock, ptr, 1, 0))){
  15068. if(bytes_received==-1){
  15069. perror("Parse Header");
  15070. exit(1);
  15071. }
  15072. if(
  15073. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15074. (ptr[-1]=='\r') && (*ptr=='\n' )
  15075. ) break;
  15076. ptr++;
  15077. }
  15078. *ptr=0;
  15079. ptr=buff+4;
  15080. //printf("%s",ptr);
  15081. if(bytes_received){
  15082. ptr=strstr(ptr,"Content-Length:");
  15083. if(ptr){
  15084. sscanf(ptr,"%*s %d",&bytes_received);
  15085. }else
  15086. bytes_received=-1; //unknown size
  15087. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15088. }
  15089. DEBUG_INFO("End HEADER ..\n");
  15090. return bytes_received ;
  15091. }
  15092. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15093. {
  15094. int result = TRUE;
  15095. char rmFileCmd[100]={0};
  15096. char FilePath[100]={0};
  15097. char ftpbuf[200];
  15098. int systemresult;
  15099. //DEBUG_INFO("filename=%s\n",filename);
  15100. //DEBUG_INFO("url=%s\n",url);
  15101. sprintf(FilePath,"/mnt/%s",filename);
  15102. system("ping 8.8.8.8 &");
  15103. if((access(FilePath,F_OK))!=-1)
  15104. {
  15105. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15106. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15107. system(rmFileCmd);
  15108. }
  15109. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15110. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15111. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15112. systemresult = system(ftpbuf);
  15113. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15114. if(systemresult != 0)
  15115. {
  15116. DEBUG_INFO("http DownLoad error!\n");
  15117. result = FALSE;
  15118. }
  15119. system("pkill ping");
  15120. return result;
  15121. }
  15122. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15123. {
  15124. int result = TRUE;
  15125. char rmFileCmd[100]={0};
  15126. char FilePath[100]={0};
  15127. char ftpbuf[200];
  15128. int systemresult;
  15129. //char temp[100];
  15130. sprintf(FilePath,"/mnt/%s",filename);
  15131. system("ping 8.8.8.8 &");
  15132. if((access(FilePath,F_OK))!=-1)
  15133. {
  15134. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15135. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15136. system(rmFileCmd);
  15137. }
  15138. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15139. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15140. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15141. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15142. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15143. systemresult = system(ftpbuf);
  15144. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15145. if(systemresult != 0)
  15146. {
  15147. DEBUG_WARN("wget error!\n");
  15148. result = FALSE;
  15149. }
  15150. system("pkill ping");
  15151. return result;
  15152. }
  15153. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15154. {
  15155. char rmFileCmd[100]={0};
  15156. char FilePath[100]={0};
  15157. char buf[512];
  15158. int systemresult = 0;
  15159. //DEBUG_INFO("filename=%s\n",filename);
  15160. //DEBUG_INFO("url=%s\n",url);
  15161. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15162. if((access(FilePath,F_OK))!=-1)
  15163. {
  15164. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15165. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15166. system(rmFileCmd);
  15167. }
  15168. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15169. if(fp == NULL)
  15170. {
  15171. DEBUG_INFO("log is NULL\n");
  15172. return FALSE;
  15173. }
  15174. else
  15175. {
  15176. fprintf(fp, "%s\n", url);
  15177. fprintf(fp, "%s\n", filename);
  15178. fclose(fp);
  15179. }
  15180. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15181. if(phpFP == NULL)
  15182. {
  15183. DEBUG_INFO("PHP upload fail.\n");
  15184. return FALSE;
  15185. }
  15186. else
  15187. {
  15188. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15189. {
  15190. if(strstr(buf, "result") != NULL)
  15191. {
  15192. sscanf(buf, "result: %d", &systemresult);
  15193. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15194. }
  15195. }
  15196. pclose(phpFP);
  15197. }
  15198. if(systemresult != 1)
  15199. {
  15200. DEBUG_INFO("HTTP upload error!\n");
  15201. return FALSE;
  15202. }
  15203. return TRUE;
  15204. }
  15205. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15206. {
  15207. struct hostent* server;
  15208. char *IPbuffer;
  15209. char ftpbuf[200];
  15210. int systemresult;
  15211. // To retrieve host information
  15212. server = gethostbyname(location);
  15213. // To convert an Internet network
  15214. // address into ASCII string
  15215. IPbuffer = inet_ntoa(*((struct in_addr*)
  15216. server->h_addr_list[0]));
  15217. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15218. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15219. /* format : ftpput -u username -p passwd IP target source*/
  15220. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15221. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15222. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15223. systemresult = system(ftpbuf);
  15224. DEBUG_INFO("systemresult=%d\n",systemresult);
  15225. if(systemresult != 0)
  15226. {
  15227. DEBUG_INFO("ftpput error!\n");
  15228. return FALSE;
  15229. }
  15230. return TRUE;
  15231. }
  15232. int GetOcppServerURL()
  15233. {
  15234. int result = FALSE;
  15235. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15236. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15237. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15238. struct yuarel url;
  15239. char urlStr[512];
  15240. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15241. {
  15242. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15243. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15244. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15245. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15246. if(yuarel_parse(&url, urlStr) != -1)
  15247. {
  15248. sprintf(OcppProtocol, "%s", url.scheme);
  15249. sprintf(OcppHost, "%s", url.host);
  15250. if(url.path == NULL)
  15251. OcppTempPath[0] = '\0';
  15252. else
  15253. {
  15254. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15255. {
  15256. sprintf(OcppTempPath, "%s/", url.path);
  15257. }
  15258. else
  15259. {
  15260. sprintf(OcppTempPath, "%s", url.path);
  15261. }
  15262. }
  15263. if(url.port == 0)
  15264. {
  15265. if(strcmp(OcppProtocol, "wss") == 0)
  15266. OcppPort = 443;
  15267. else
  15268. OcppPort = 80;
  15269. }
  15270. else
  15271. OcppPort = url.port;
  15272. result = TRUE;
  15273. }
  15274. }
  15275. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15276. {
  15277. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15278. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15279. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15280. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15281. if(yuarel_parse(&url, urlStr) != -1)
  15282. {
  15283. sprintf(OcppProtocol, "%s", url.scheme);
  15284. sprintf(OcppHost, "%s", url.host);
  15285. if(url.path == NULL)
  15286. OcppTempPath[0] = '\0';
  15287. else
  15288. sprintf(OcppTempPath, "%s", url.path);
  15289. if(url.port == 0)
  15290. {
  15291. if(strcmp(OcppProtocol, "wss") == 0)
  15292. OcppPort = 443;
  15293. else
  15294. OcppPort = 80;
  15295. }
  15296. else
  15297. OcppPort = url.port;
  15298. result = TRUE;
  15299. }
  15300. }
  15301. else
  15302. {
  15303. strcpy(OcppHost,"");
  15304. }
  15305. return result;
  15306. }
  15307. int GetOcppPath()
  15308. {
  15309. int result = FALSE;
  15310. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15311. {
  15312. if(OcppTempPath == NULL)
  15313. {
  15314. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15315. }
  15316. else
  15317. {
  15318. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15319. }
  15320. result = TRUE;
  15321. goto End;
  15322. }
  15323. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15324. {
  15325. if(OcppTempPath == NULL)
  15326. {
  15327. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15328. }
  15329. else
  15330. {
  15331. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15332. }
  15333. result = TRUE;
  15334. goto End;
  15335. }
  15336. else
  15337. {
  15338. strcpy(OcppPath,"");
  15339. }
  15340. End:
  15341. return result;
  15342. }
  15343. int GetOcppPort()
  15344. {
  15345. return OcppPort;
  15346. }
  15347. int GetOcppConnStatus(void)
  15348. {
  15349. return ShmOCPP16Data->OcppConnStatus;
  15350. }
  15351. void SetOcppConnStatus(uint8_t status)
  15352. {
  15353. ShmOCPP16Data->OcppConnStatus = status;
  15354. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15355. }
  15356. int GetHeartBeatWithNOResponse(void)
  15357. {
  15358. return HeartBeatWithNOResponse;
  15359. }
  15360. void SetHeartBeatWithNOResponse(void)
  15361. {
  15362. HeartBeatWithNOResponse = 0;
  15363. }
  15364. void GetStartTransactionIdTag(int gun_index)
  15365. {
  15366. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15367. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15368. }
  15369. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15370. {
  15371. char ch;
  15372. FILE *fptr1;
  15373. int temptransactionId;
  15374. char str[100]={0};
  15375. temptransactionId = 0;
  15376. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15377. {
  15378. DEBUG_INFO("IdTag is empty.\n");
  15379. return temptransactionId;
  15380. }
  15381. /*------ Read the file ----------------*/
  15382. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15383. if (!fptr1)
  15384. {
  15385. DEBUG_INFO("QueueTransactionId file open error.\n");
  15386. //printf(" File not found or unable to open the input file!!\n");
  15387. return temptransactionId;
  15388. }
  15389. ch=fgetc(fptr1);
  15390. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15391. rewind(fptr1);
  15392. if(ch!=EOF)
  15393. {
  15394. // printf("%c",ch);
  15395. while (fgets(str, 100, fptr1) != NULL)
  15396. {
  15397. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15398. if(str[0]=='\0')
  15399. {
  15400. break;
  15401. }
  15402. char *revbuf[8] = {0}; // Variable store string split
  15403. int num = 0;// Quantity after string split
  15404. DEBUG_INFO("Transaction queue data= %s\n", str);
  15405. splitstring(str,",",revbuf,&num); // String split
  15406. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15407. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15408. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15409. DEBUG_INFO("------------------------------\n");
  15410. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15411. {
  15412. if(isStopTransaction)
  15413. {
  15414. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15415. {
  15416. temptransactionId = atoi(revbuf[2]);
  15417. //break;
  15418. }
  15419. }
  15420. else
  15421. {
  15422. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15423. {
  15424. temptransactionId = atoi(revbuf[2]);
  15425. //break;
  15426. }
  15427. }
  15428. }
  15429. }
  15430. }
  15431. else
  15432. DEBUG_INFO("EOF\n");
  15433. fclose(fptr1);
  15434. /*------- End of reading ---------------*/
  15435. return temptransactionId;
  15436. }
  15437. void SetTransactionIdZero(int transactionId)
  15438. {
  15439. char ch;
  15440. FILE *fptr1, *fptr2;
  15441. int temptransactionId = 0;
  15442. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15443. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15444. if (!fptr1)
  15445. {
  15446. //printf(" File not found or unable to open the input file!!\n");
  15447. return ;
  15448. }
  15449. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15450. if (!fptr2)
  15451. {
  15452. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15453. fclose(fptr1);
  15454. return ;
  15455. }
  15456. ch=fgetc(fptr1);
  15457. rewind(fptr1);
  15458. if(ch!=EOF)
  15459. {
  15460. // copy all contents to the temporary file except the specific line
  15461. while (fgets(str, 100, fptr1) != NULL)
  15462. {
  15463. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15464. if(str[0]=='\0')
  15465. {
  15466. break;
  15467. }
  15468. char *revbuf[8] = {0};
  15469. int num = 0;
  15470. strcpy(strtemp, str);
  15471. splitstring(str,",",revbuf,&num);
  15472. if(revbuf[2][0] != '\0')
  15473. {
  15474. temptransactionId = atoi(revbuf[2]);
  15475. if(transactionId != temptransactionId)
  15476. {
  15477. fprintf(fptr2, "%s\n", strtemp);
  15478. }
  15479. }
  15480. }
  15481. }
  15482. fclose(fptr1);
  15483. fclose(fptr2);
  15484. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15485. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15486. /*------ Read the file ----------------*/
  15487. }
  15488. int InternetDisconnect(void)
  15489. {
  15490. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15491. }
  15492. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15493. void storeTempStopTransaction(int gun_index)
  15494. {
  15495. char guid[37]={0};
  15496. int tempIndex = 0;
  15497. char TempStopTransaction[256];
  15498. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15499. DEBUG_INFO("storeTempStopTransaction...\n");
  15500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15501. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15502. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15503. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15504. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15505. {
  15506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15507. {
  15508. tempIndex = ((gun_index==2) ? 1: 0);
  15509. }
  15510. else
  15511. {
  15512. tempIndex = gun_index;
  15513. }
  15514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15515. {
  15516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15517. {
  15518. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15519. }
  15520. }// END OF CHAdeMO_QUANTITY
  15521. }
  15522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15523. {
  15524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15525. {
  15526. tempIndex = ((gun_index==2) ? 1: 0);
  15527. }
  15528. else
  15529. {
  15530. tempIndex = gun_index;
  15531. }
  15532. for (int index = 0; index < CCS_QUANTITY; index++)
  15533. {
  15534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15535. {
  15536. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15537. }
  15538. }// END OF CCS_QUANTITY
  15539. }
  15540. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15541. {
  15542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15543. {
  15544. tempIndex = ((gun_index==2) ? 1: 0);
  15545. }
  15546. else
  15547. {
  15548. tempIndex = gun_index;
  15549. }
  15550. for (int index = 0; index < GB_QUANTITY; index++)
  15551. {
  15552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15553. {
  15554. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15555. }
  15556. }// END OF GB_QUANTITY
  15557. }
  15558. else if(gunType[gun_index] == GUN_TYPE_DO)
  15559. {
  15560. tempIndex = gun_index;
  15561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15562. {
  15563. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15564. {
  15565. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15566. }
  15567. }
  15568. }
  15569. else
  15570. {
  15571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15572. {
  15573. tempIndex = 2;
  15574. }
  15575. else
  15576. {
  15577. tempIndex = gun_index;
  15578. }
  15579. for (int index = 0; index < AC_QUANTITY; index++)
  15580. {
  15581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15582. {
  15583. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15584. }
  15585. }// END OF AC_QUANTITY
  15586. }
  15587. //Stop Transaction Time
  15588. struct timeval tmnow;
  15589. struct tm *tm;
  15590. char buf[28];//, usec_buf[6];
  15591. gettimeofday(&tmnow, NULL);
  15592. time_t t;
  15593. t = time(NULL);
  15594. /*UTC time and date*/
  15595. tm = gmtime(&t);
  15596. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15598. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15600. random_uuid(guid);
  15601. /***********************************transactionData******************************************************/
  15602. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15604. //=================================
  15605. //1. Transaction_Begin
  15606. //=================================
  15607. //============================== Energy.Active.Import.Interval ===========================================
  15608. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15609. {
  15610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15613. 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*/]);
  15614. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15615. 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))
  15616. {
  15617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15618. }
  15619. else
  15620. {
  15621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15622. }
  15623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15625. }
  15626. //=================================
  15627. //2. Transaction_End
  15628. //=================================
  15629. //2.1====================================== Current.Import L1 ==============================================
  15630. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15631. {
  15632. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15633. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15634. {
  15635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15636. {
  15637. tempIndex = ((gun_index==2) ? 1: 0);
  15638. }
  15639. else
  15640. {
  15641. tempIndex = gun_index;
  15642. }
  15643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15644. {
  15645. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15646. {
  15647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15648. }
  15649. }// End of for CHAdeMO_QUANTITY
  15650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15651. }
  15652. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15653. {
  15654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15655. {
  15656. tempIndex = ((gun_index==2) ? 1: 0);
  15657. }
  15658. else
  15659. {
  15660. tempIndex = gun_index;
  15661. }
  15662. for (int index = 0; index < CCS_QUANTITY; index++)
  15663. {
  15664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15665. {
  15666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15667. }
  15668. }// End of for CCS_QUANTITY
  15669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15670. }
  15671. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15672. {
  15673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15674. {
  15675. tempIndex = ((gun_index==2) ? 1: 0);
  15676. }
  15677. else
  15678. {
  15679. tempIndex = gun_index;
  15680. }
  15681. for (int index = 0; index < GB_QUANTITY; index++)
  15682. {
  15683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15684. {
  15685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15686. }
  15687. }// End of for GB_QUANTITY
  15688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15689. }
  15690. else if(gunType[gun_index] == GUN_TYPE_DO)
  15691. {
  15692. tempIndex = gun_index;
  15693. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15694. {
  15695. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15696. {
  15697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15698. }
  15699. }
  15700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15701. }
  15702. else
  15703. {
  15704. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15705. {
  15706. tempIndex = 2;
  15707. }
  15708. else
  15709. {
  15710. tempIndex = gun_index;
  15711. }
  15712. for (int index = 0; index < AC_QUANTITY; index++)
  15713. {
  15714. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15715. {
  15716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15717. }
  15718. }// End of for AC_QUANTITY
  15719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15720. }
  15721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15724. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15727. }
  15728. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15729. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15730. {
  15731. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15732. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15733. {
  15734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15735. {
  15736. tempIndex = ((gun_index==2) ? 1: 0);
  15737. }
  15738. else
  15739. {
  15740. tempIndex = gun_index;
  15741. }
  15742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15743. {
  15744. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15745. {
  15746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15747. }
  15748. }// END OF CHAdeMO_QUANTITY
  15749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15750. }
  15751. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15752. {
  15753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15754. {
  15755. tempIndex = ((gun_index==2) ? 1: 0);
  15756. }
  15757. else
  15758. {
  15759. tempIndex = gun_index;
  15760. }
  15761. for (int index = 0; index < CCS_QUANTITY; index++)
  15762. {
  15763. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15764. {
  15765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15766. }
  15767. }// END OF CCS_QUANTITY
  15768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15769. }
  15770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15771. {
  15772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15773. {
  15774. tempIndex = ((gun_index==2) ? 1: 0);
  15775. }
  15776. else
  15777. {
  15778. tempIndex = gun_index;
  15779. }
  15780. for (int index = 0; index < GB_QUANTITY; index++)
  15781. {
  15782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15783. {
  15784. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15785. }
  15786. }// END OF GB_QUANTITY
  15787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15788. }
  15789. else if(gunType[gun_index] == GUN_TYPE_DO)
  15790. {
  15791. tempIndex = gun_index;
  15792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15793. {
  15794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15795. {
  15796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15797. }
  15798. }
  15799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15800. }
  15801. else
  15802. {
  15803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15804. {
  15805. tempIndex = 2;
  15806. }
  15807. else
  15808. {
  15809. tempIndex = gun_index;
  15810. }
  15811. for (int index = 0; index < AC_QUANTITY; index++)
  15812. {
  15813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15814. {
  15815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15816. }
  15817. }// END OF AC_QUANTITY
  15818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15819. }
  15820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15823. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15826. }
  15827. //2.3====================================== Power.Active.Import =========================================
  15828. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15829. {
  15830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15831. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  15842. {
  15843. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15844. {
  15845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15846. }
  15847. } // End for CHAdeMO_QUANTITY
  15848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15849. }
  15850. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15851. {
  15852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15853. {
  15854. tempIndex = ((gun_index==2) ? 1: 0);
  15855. }
  15856. else
  15857. {
  15858. tempIndex = gun_index;
  15859. }
  15860. for (int index = 0; index < CCS_QUANTITY; index++)
  15861. {
  15862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15863. {
  15864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15865. }
  15866. } // END for CCS_QUANTITY
  15867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15868. }
  15869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15870. {
  15871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15872. {
  15873. tempIndex = ((gun_index==2) ? 1: 0);
  15874. }
  15875. else
  15876. {
  15877. tempIndex = gun_index;
  15878. }
  15879. for (int index = 0; index < GB_QUANTITY; index++)
  15880. {
  15881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15882. {
  15883. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15884. }
  15885. }// END for GB_QUANTITY
  15886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15887. }
  15888. else if(gunType[gun_index] == GUN_TYPE_DO)
  15889. {
  15890. tempIndex = gun_index;
  15891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15892. {
  15893. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15894. {
  15895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15896. }
  15897. }
  15898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15899. }
  15900. else
  15901. {
  15902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15903. {
  15904. tempIndex = 2;
  15905. }
  15906. else
  15907. {
  15908. tempIndex = gun_index;
  15909. }
  15910. for (int index = 0; index < AC_QUANTITY; index++)
  15911. {
  15912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15913. {
  15914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15915. }
  15916. } // END for AC_QUANTITY
  15917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15918. }
  15919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15922. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15925. }
  15926. //2.4====================================== Voltage L1 ====================================================
  15927. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15928. {
  15929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15931. {
  15932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15933. {
  15934. tempIndex = ((gun_index==2) ? 1: 0);
  15935. }
  15936. else
  15937. {
  15938. tempIndex = gun_index;
  15939. }
  15940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15941. {
  15942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15943. {
  15944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15945. }
  15946. } // END OF FOR CHAdeMO_QUANTITY
  15947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15948. }
  15949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15950. {
  15951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15952. {
  15953. tempIndex = ((gun_index==2) ? 1: 0);
  15954. }
  15955. else
  15956. {
  15957. tempIndex = gun_index;
  15958. }
  15959. for (int index = 0; index < CCS_QUANTITY; index++)
  15960. {
  15961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15962. {
  15963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15964. }
  15965. } // END OF FOR CCS_QUANTITY
  15966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15967. }
  15968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15969. {
  15970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15971. {
  15972. tempIndex = ((gun_index==2) ? 1: 0);
  15973. }
  15974. else
  15975. {
  15976. tempIndex = gun_index;
  15977. }
  15978. for (int index = 0; index < GB_QUANTITY; index++)
  15979. {
  15980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15981. {
  15982. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15983. }
  15984. } // END OF FOR GB_QUANTITY
  15985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15986. }
  15987. else if(gunType[gun_index] == GUN_TYPE_DO)
  15988. {
  15989. tempIndex = gun_index;
  15990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15991. {
  15992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15993. {
  15994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15995. }
  15996. }
  15997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15998. }
  15999. else
  16000. {
  16001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16002. {
  16003. tempIndex = 2;
  16004. }
  16005. else
  16006. {
  16007. tempIndex = gun_index;
  16008. }
  16009. for (int index = 0; index < AC_QUANTITY; index++)
  16010. {
  16011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16012. {
  16013. 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
  16014. }
  16015. } // END OF FOR AC_QUANTITY
  16016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16017. }
  16018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16021. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16024. }
  16025. //2.5============================================== End SoC =========================================================
  16026. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16027. {
  16028. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16029. 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))
  16030. {
  16031. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16032. {
  16033. tempIndex = ((gun_index==2) ? 1: 0);
  16034. }
  16035. else
  16036. {
  16037. tempIndex = gun_index;
  16038. }
  16039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16040. {
  16041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16042. {
  16043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16044. {
  16045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16046. }
  16047. }
  16048. }
  16049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16050. {
  16051. for (int index = 0; index < CCS_QUANTITY; index++)
  16052. {
  16053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16054. {
  16055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16056. }
  16057. }
  16058. }
  16059. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16060. {
  16061. for (int index = 0; index < GB_QUANTITY; index++)
  16062. {
  16063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16064. {
  16065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16066. }
  16067. }
  16068. }
  16069. else if(gunType[gun_index] == GUN_TYPE_DO)
  16070. {
  16071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16072. {
  16073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16074. {
  16075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16076. }
  16077. }
  16078. }
  16079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16085. } // END FOR DC CASE
  16086. }
  16087. //2.6====================================== Current.Import L2 ==============================================
  16088. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16089. {
  16090. // AC 3 phase L2 current
  16091. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16092. {
  16093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16094. {
  16095. tempIndex = 2;
  16096. }
  16097. else
  16098. {
  16099. tempIndex = gun_index;
  16100. }
  16101. for (int index = 0; index < AC_QUANTITY; index++)
  16102. {
  16103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16104. {
  16105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16106. }
  16107. }// End of for AC_QUANTITY
  16108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16109. }
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16115. }
  16116. //2.7====================================== Current.Import L3 ==============================================
  16117. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16118. {
  16119. // AC 3 phase L3 current
  16120. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16121. {
  16122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16123. {
  16124. tempIndex = 2;
  16125. }
  16126. else
  16127. {
  16128. tempIndex = gun_index;
  16129. }
  16130. for (int index = 0; index < AC_QUANTITY; index++)
  16131. {
  16132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16133. {
  16134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16135. }
  16136. }// End of for AC_QUANTITY
  16137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16138. }
  16139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16144. }
  16145. //2.9====================================== Voltage L2 ====================================================
  16146. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16147. {
  16148. // AC 3 phase L2 volatge
  16149. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16150. {
  16151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16152. {
  16153. tempIndex = 2;
  16154. }
  16155. else
  16156. {
  16157. tempIndex = gun_index;
  16158. }
  16159. for (int index = 0; index < AC_QUANTITY; index++)
  16160. {
  16161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16162. {
  16163. 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
  16164. }
  16165. } // END OF FOR AC_QUANTITY
  16166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16167. }
  16168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16173. }
  16174. //2.10====================================== Voltage L3 ====================================================
  16175. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16176. {
  16177. // AC 3 phase L3 volatge
  16178. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16179. {
  16180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16181. {
  16182. tempIndex = 2;
  16183. }
  16184. else
  16185. {
  16186. tempIndex = gun_index;
  16187. }
  16188. for (int index = 0; index < AC_QUANTITY; index++)
  16189. {
  16190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16191. {
  16192. 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
  16193. }
  16194. } // END OF FOR AC_QUANTITY
  16195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16196. }
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16202. }
  16203. //====================== Start SoC ================================
  16204. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16205. {
  16206. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16207. 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))
  16208. {
  16209. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16210. {
  16211. tempIndex = ((gun_index==2) ? 1: 0);
  16212. }
  16213. else
  16214. {
  16215. tempIndex = gun_index;
  16216. }
  16217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16218. {
  16219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16220. {
  16221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16222. {
  16223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16224. }
  16225. }
  16226. }
  16227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16228. {
  16229. for (int index = 0; index < CCS_QUANTITY; index++)
  16230. {
  16231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16232. {
  16233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16234. }
  16235. }
  16236. }
  16237. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16238. {
  16239. for (int index = 0; index < GB_QUANTITY; index++)
  16240. {
  16241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16242. {
  16243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16244. }
  16245. }
  16246. }
  16247. else if(gunType[gun_index] == GUN_TYPE_DO)
  16248. {
  16249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16250. {
  16251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16252. {
  16253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16254. }
  16255. }
  16256. }
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16263. } // END FOR DC CASE
  16264. }
  16265. //======================================== Message create ==============================================
  16266. json_object *StopTransaction = json_object_new_object();
  16267. json_object *transactionDatas = json_object_new_array();
  16268. json_object *sampledValues = json_object_new_array();
  16269. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16270. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16271. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16272. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16273. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16274. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16275. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16276. {
  16277. json_object *transactionData = json_object_new_object();
  16278. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16279. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16280. {
  16281. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16282. {
  16283. json_object *sampledValue = json_object_new_object();
  16284. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16286. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16287. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16288. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16289. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16290. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16291. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16292. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16293. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16294. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16295. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16296. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16297. json_object_array_add(sampledValues, sampledValue);
  16298. }
  16299. }
  16300. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16301. json_object_array_add(transactionDatas, transactionData);
  16302. }
  16303. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16304. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16305. ,MESSAGE_TYPE_CALL
  16306. ,guid
  16307. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16308. json_object_put(StopTransaction);
  16309. // Check File "TempStopTransaction" Exist
  16310. if((access(TempStopTransaction,F_OK))!=-1)
  16311. {
  16312. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16313. fclose(fopen(TempStopTransaction, "w"));
  16314. }
  16315. else
  16316. {
  16317. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16318. FILE *log = fopen(TempStopTransaction, "w+");
  16319. if(log == NULL)
  16320. {
  16321. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16322. return ;
  16323. }
  16324. else
  16325. {
  16326. fclose(log);
  16327. }
  16328. }
  16329. //Add TempStopTransaction | Update TempStopTransaction
  16330. // open file for writing
  16331. FILE *outfile;
  16332. outfile = fopen (TempStopTransaction, "a");
  16333. //DEBUG_INFO("data = %s\n", queuedata);
  16334. fputs(queuedata, outfile);
  16335. fputs("\n", outfile);
  16336. fclose (outfile);
  16337. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16338. }
  16339. void checkTempStopTransaction(int gun_index)
  16340. {
  16341. FILE *fptr1;
  16342. char ch;
  16343. char str[QUEUE_MESSAGE_LENGTH]={0};
  16344. char guid[37]={0};
  16345. char tempdata[65]={0};
  16346. char connectorStr[2]={0};
  16347. char TempStopTransaction[256];
  16348. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16349. fptr1 = fopen(TempStopTransaction, "r");
  16350. //TempStopTransaction格式: 槍號,StopTransaction封包
  16351. if (!fptr1)
  16352. {
  16353. //printf(" File not found or unable to open the input file!!\n");
  16354. return ;
  16355. }
  16356. ch=fgetc(fptr1);
  16357. //printf(" Now the content of the file %s is : \n",fname);
  16358. rewind(fptr1);
  16359. if(ch!=EOF)
  16360. {
  16361. // copy all contents to the temporary file except the specific line
  16362. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16363. {
  16364. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16365. if(str[0]=='\0')
  16366. {
  16367. break;
  16368. }
  16369. //TempStopTransaction格式: 槍號,StopTransaction封包
  16370. strncpy(connectorStr, str, 1);
  16371. if(atoi(connectorStr) != (gun_index+1))
  16372. {
  16373. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16374. fclose(fptr1);
  16375. return ;
  16376. }
  16377. //random_uuid(guid);
  16378. strncpy(guid, str+6, 36); //copy guid
  16379. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16380. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16381. {
  16382. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16383. }
  16384. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16385. OCPP_insert_transaction_msg(NO, str);
  16386. memset(str,0,ARRAY_SIZE(str));
  16387. }
  16388. }
  16389. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16390. fclose(fptr1);
  16391. remove(TempStopTransaction); // remove the original file
  16392. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16393. }
  16394. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16395. {
  16396. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16397. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16398. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16399. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16400. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16401. }
  16402. int GetWebSocketPingInterval(void)
  16403. {
  16404. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16405. }
  16406. int GetServerSign(void)
  16407. {
  16408. return server_sign;
  16409. }
  16410. uint8_t GetOcppSecurityProfile()
  16411. {
  16412. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16413. }
  16414. void GetOcppChargerBoxId(uint8_t *data)
  16415. {
  16416. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16417. }
  16418. void GetOcppSecurityPassword(uint8_t *data)
  16419. {
  16420. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16421. }
  16422. void SetOcppVersion(uint8_t *version)
  16423. {
  16424. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16425. DEBUG_INFO("ocpp version: %s\n", version);
  16426. if(strstr((char*)version, "ocpp1.6") != NULL)
  16427. {
  16428. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16429. }
  16430. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16431. {
  16432. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16433. system("pkill OcppBackend");
  16434. }
  16435. }
  16436. void SetServerSign(int value)
  16437. {
  16438. server_sign = value;
  16439. }
  16440. int GetBootNotificationInterval(void)
  16441. {
  16442. return BootNotificationInterval;
  16443. }
  16444. int GetInternetConn(void)
  16445. {
  16446. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16447. }
  16448. int GetBackendConnectionTimeout(void)
  16449. {
  16450. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16451. }
  16452. int isConnectorInitMode(int gun_index)
  16453. {
  16454. int tempIndex = 0;
  16455. int result = TRUE;
  16456. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16457. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16458. {
  16459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16460. {
  16461. tempIndex = ((gun_index==2) ? 1: 0);
  16462. }
  16463. else
  16464. {
  16465. tempIndex = gun_index;
  16466. }
  16467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16468. {
  16469. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16470. {
  16471. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16472. } //end of the same index
  16473. }//end of for CHAdeMO_QUANTITY
  16474. }
  16475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16476. {
  16477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16478. {
  16479. tempIndex = ((gun_index==2) ? 1: 0);
  16480. }
  16481. else
  16482. {
  16483. tempIndex = gun_index;
  16484. }
  16485. for (int index = 0; index < CCS_QUANTITY; index++)
  16486. {
  16487. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16488. {
  16489. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16490. } //end of the same index
  16491. } // end of for CCS_QUANTITY
  16492. }
  16493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16494. {
  16495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16496. {
  16497. tempIndex = ((gun_index==2) ? 1: 0);
  16498. }
  16499. else
  16500. {
  16501. tempIndex = gun_index;
  16502. }
  16503. for (int index = 0; index < GB_QUANTITY; index++)
  16504. {
  16505. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16506. {
  16507. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16508. } //end of the same index
  16509. } // end of for GB_QUANTITY
  16510. }
  16511. else if(gunType[gun_index] == GUN_TYPE_DO)
  16512. {
  16513. tempIndex = gun_index;
  16514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16515. {
  16516. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16517. {
  16518. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16519. } //end of the same index
  16520. }
  16521. }
  16522. else
  16523. {
  16524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16525. {
  16526. tempIndex = 2;
  16527. }
  16528. else
  16529. {
  16530. tempIndex = gun_index;
  16531. }
  16532. for (int index = 0; index < AC_QUANTITY; index++)
  16533. {
  16534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16535. {
  16536. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16537. }//end of the same index
  16538. }//end of for AC_QUANTITY
  16539. }
  16540. return result;
  16541. }
  16542. void refreshProcDogTimer()
  16543. {
  16544. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16545. }
  16546. void InitialSystemValue(void)
  16547. {
  16548. int connectorIndex = 0;
  16549. //int valueASCII = 0;
  16550. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16551. gunTotalNumber=0;
  16552. SystemInitial = 0;
  16553. locallistVersion=0;
  16554. BootNotificationInterval = 0;
  16555. authorizeRetryTimes = 0;
  16556. GunStatusInterval = 10;
  16557. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16558. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16559. //Hear Beat
  16560. HeartBeatWithNOResponse = 0;
  16561. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16562. FirstHeartBeat = 0;
  16563. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16565. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16566. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16567. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16568. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16569. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16570. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16571. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16572. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16573. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16574. memset(gunType, 0, ARRAY_SIZE(gunType));
  16575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16576. {
  16577. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16578. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16579. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16580. {
  16581. // DO series
  16582. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16583. {
  16584. SystemInitial = SystemInitial + 1;
  16585. gunTotalNumber = gunTotalNumber + 1;
  16586. gunType[connectorIndex] = GUN_TYPE_DO;
  16587. connectorIndex = connectorIndex + 1;
  16588. }
  16589. }
  16590. else
  16591. {
  16592. // DM, DW, DS series
  16593. //check connector / socket type (index: 8, 9, 10)
  16594. for(int index=7; index <10 ; index++)
  16595. {
  16596. if(index != 8)
  16597. {
  16598. // DC Connector
  16599. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16600. {
  16601. SystemInitial = SystemInitial + 1;
  16602. gunTotalNumber = gunTotalNumber + 1;
  16603. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16604. connectorIndex = connectorIndex + 1;
  16605. }
  16606. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16607. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16608. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16609. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16610. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16611. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16612. {
  16613. SystemInitial = SystemInitial + 1;
  16614. gunTotalNumber = gunTotalNumber + 1;
  16615. gunType[connectorIndex] = GUN_TYPE_CCS;
  16616. connectorIndex = connectorIndex + 1;
  16617. }
  16618. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16619. {
  16620. SystemInitial = SystemInitial + 1;
  16621. gunTotalNumber = gunTotalNumber + 1;
  16622. gunType[connectorIndex] = GUN_TYPE_GBT;
  16623. connectorIndex = connectorIndex + 1;
  16624. }
  16625. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16626. {
  16627. SystemInitial = SystemInitial + 1;
  16628. gunTotalNumber = gunTotalNumber + 1;
  16629. gunType[connectorIndex] = GUN_TYPE_DO;
  16630. connectorIndex = connectorIndex + 1;
  16631. }
  16632. }
  16633. else
  16634. {
  16635. // AC Connector
  16636. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16637. {
  16638. SystemInitial = SystemInitial + 1;
  16639. gunTotalNumber = gunTotalNumber + 1;
  16640. gunType[connectorIndex] = GUN_TYPE_AC;
  16641. connectorIndex = connectorIndex + 1;
  16642. }
  16643. }
  16644. }
  16645. }
  16646. //DEBUG_INFO("DC ...\n");
  16647. }
  16648. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16649. {
  16650. //check connector / socket type (index: 8, 9, 10)
  16651. for(int index=7; index <10 ; index++)
  16652. {
  16653. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16654. {
  16655. SystemInitial = SystemInitial + 1;
  16656. gunTotalNumber = gunTotalNumber + 1;
  16657. gunType[connectorIndex] = GUN_TYPE_AC;
  16658. connectorIndex = connectorIndex + 1;
  16659. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16660. }
  16661. }
  16662. }
  16663. //Status && ConnectorPlugIn Setting
  16664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16665. {
  16666. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16667. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16668. }
  16669. for (int index = 0; index < CCS_QUANTITY; index++)
  16670. {
  16671. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16672. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16673. }
  16674. for (int index = 0; index < GB_QUANTITY; index++)
  16675. {
  16676. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16677. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16678. }
  16679. for (int index = 0; index < AC_QUANTITY; index++)
  16680. {
  16681. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16682. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16683. }
  16684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16685. {
  16686. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16687. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16688. }
  16689. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16690. {
  16691. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16692. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16693. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16694. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16695. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16696. }
  16697. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16698. clientTime.Heartbeat=time((time_t*)NULL);
  16699. sleep(1);
  16700. }
  16701. void LWS_Send(char *str)
  16702. {
  16703. //=====================================================
  16704. // Check InternetConn 0: disconnected, 1: connected
  16705. //====================================================
  16706. if(GetOcppConnStatus() == 0)
  16707. {
  16708. DEBUG_INFO("offline now !!!\n");
  16709. return;
  16710. }
  16711. // Only disable isWebsocketSendable operation initiated by charger
  16712. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16713. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16714. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16715. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16716. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16717. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16718. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16719. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16720. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16721. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16722. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16723. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16724. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16725. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16726. {
  16727. isWebsocketSendable = 0;
  16728. }
  16729. pthread_mutex_lock(&lock_send);
  16730. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16731. sprintf((char *)SendBuffer, "%s", str);
  16732. SendBufLen = strlen(str);
  16733. pthread_mutex_unlock(&lock_send);
  16734. lws_callback_on_writable(wsi_client);
  16735. //lws_service(context, 0);
  16736. //sleep(1);
  16737. }
  16738. void LWS_SendNow(char *str)
  16739. {
  16740. //=====================================================
  16741. // Check InternetConn 0: disconnected, 1: connected
  16742. //====================================================
  16743. if(GetOcppConnStatus() == 0)
  16744. {
  16745. DEBUG_INFO("offline now !!!\n");
  16746. return;
  16747. }
  16748. // Only disable isWebsocketSendable operation initiated by charger
  16749. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16750. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16751. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16752. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16753. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16754. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16755. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16756. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16757. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16758. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16759. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16760. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16761. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16762. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16763. {
  16764. isWebsocketSendable = 0;
  16765. }
  16766. pthread_mutex_lock(&lock_send);
  16767. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16768. sprintf((char *)SendBuffer, "%s", str);
  16769. SendBufLen = strlen(str);
  16770. pthread_mutex_unlock(&lock_send);
  16771. lws_callback_on_writable(wsi_client);
  16772. lws_service(context, 0);
  16773. //sleep(1);
  16774. }