MessageHandler.c 836 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248
  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 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(sendto(udp_socket_fd, tx_buf, strlen((char*)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("Message raw: %s\n", logBuf);
  552. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  553. DEBUG_TTIA_INFO("----- Header -----\n");
  554. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  555. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  556. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  557. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  558. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  559. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  560. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  561. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  562. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  563. DEBUG_TTIA_INFO("Len: 80\n");
  564. DEBUG_TTIA_INFO("----- Payload -----\n");
  565. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  566. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  567. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  568. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  569. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  570. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  571. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  572. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  573. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  574. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  575. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  576. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  577. DEBUG_TTIA_INFO("==================================\n");
  578. sn++;
  579. result = PASS;
  580. }
  581. else
  582. {
  583. DEBUG_ERROR("UDP sent out fail.\n");
  584. }
  585. }
  586. }
  587. return result;
  588. }
  589. //=========================================
  590. // Save configuration
  591. //=========================================
  592. int runShellCmd(const char*cmd)
  593. {
  594. int result = FAIL;
  595. char buf[256];
  596. FILE *fp;
  597. fp = popen(cmd, "r");
  598. if(fp != NULL)
  599. {
  600. while(fgets(buf, sizeof(buf), fp) != NULL)
  601. {
  602. DEBUG_INFO("%s\n", buf);
  603. }
  604. result = PASS;
  605. }
  606. pclose(fp);
  607. return result;
  608. }
  609. int StoreUsrConfigData(struct SysConfigData *UsrData)
  610. {
  611. int result = PASS;
  612. int fd,wrd;
  613. unsigned int i,Chk;
  614. unsigned char *ptr, *BufTmp;
  615. int MtdBlockSize = 0x300000;
  616. Chk=0;
  617. ptr=(unsigned char *)UsrData;
  618. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  619. {
  620. memset(BufTmp,0,MtdBlockSize);
  621. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  622. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  623. Chk+=*(BufTmp+i);
  624. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  625. // Output configuration to file.
  626. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  627. if (fd < 0)
  628. {
  629. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  630. free(BufTmp);
  631. return 0;
  632. }
  633. wrd=write(fd, BufTmp, MtdBlockSize);
  634. close(fd);
  635. if(wrd<MtdBlockSize)
  636. {
  637. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  638. free(BufTmp);
  639. return 0;
  640. }
  641. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  642. DEBUG_INFO("Erase /dev/mtd10.\n");
  643. runShellCmd("flash_erase /dev/mtd10 0 0");
  644. DEBUG_INFO("Write /dev/mtd10.\n");
  645. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  646. DEBUG_INFO("Erase /dev/mtd11.\n");
  647. runShellCmd("flash_erase /dev/mtd11 0 0");
  648. DEBUG_INFO("Write /dev/mtd11.\n");
  649. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  650. system("rm -f /mnt/EvseConfig.bin");
  651. DEBUG_INFO("EvseConfig write to flash OK\n");
  652. }
  653. else
  654. {
  655. DEBUG_ERROR("alloc BlockSize NG\r\n");
  656. result = FAIL;
  657. }
  658. if(BufTmp!=NULL)
  659. free(BufTmp);
  660. return result;
  661. }
  662. //=========================================
  663. // Sqlite3 related function
  664. //=========================================
  665. static int selectSqlCount = 0;
  666. static int callback(void *data, int argc, char **argv, char **azColName){
  667. int i;
  668. //printf("%s: ", (const char*)data);
  669. selectSqlCount = argc;
  670. for(i = 0; i<argc; i++){
  671. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  672. }
  673. //printf("\n");
  674. return 0;
  675. }
  676. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  677. //int i;
  678. //printf("%s:\n", (const char*)data);
  679. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  680. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  681. return 0;
  682. }
  683. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  684. //printf("%s:\n", (const char*)data);
  685. //idTag
  686. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  687. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  688. //parentIdTag
  689. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  690. //expir_date
  691. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  692. //status
  693. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  694. //version
  695. if(columenCount > 5)
  696. idTagQuery.listVersionInt = atoi(columnValue[5]);
  697. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  698. return 0;
  699. }
  700. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  701. {
  702. // localversion = argv[5] ? atoi(argv[5]) : 0;
  703. // printf("localversion=%d\n", localversion);
  704. return 0;
  705. }
  706. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  707. {
  708. for (int i = 0; i < n_columns; i++)
  709. {
  710. DEBUG_INFO("%s\t", col_values[i]);
  711. }
  712. DEBUG_INFO("\n");
  713. return 0;
  714. }
  715. int OCPP_cleanLocalCache()
  716. {
  717. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  718. char *errMsg = 0;
  719. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  720. if (SQLITE_OK != rc)
  721. {
  722. DEBUG_INFO("SQL error: %s\n",errMsg);
  723. return FALSE;
  724. }
  725. return TRUE;
  726. }
  727. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  728. {
  729. int isSuccess = TRUE;
  730. int ret = 0;
  731. //const char* data = "Callback function called";
  732. char sql[300];
  733. char zErrMsg[200];
  734. memset(sql, 0, 300);
  735. memset(zErrMsg, 0, 200);
  736. 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);
  737. //* Execute SQL statement */
  738. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  739. if( ret != SQLITE_OK )
  740. {
  741. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  742. isSuccess = FALSE;
  743. }
  744. return isSuccess;
  745. }
  746. void OCPP_getIdTagFromLocalCache(char idTag[])
  747. {
  748. int rc = 0;
  749. char sql[100];
  750. char zErrMsg[100];
  751. memset(sql, 0, 100);
  752. memset(zErrMsg, 0, 100);
  753. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  754. memset(&idTagQuery, 0, sizeof(idTagQuery));
  755. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  756. /* Execute SQL statement */
  757. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  758. if( rc != SQLITE_OK )
  759. {
  760. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  761. }
  762. }
  763. void OCPP_getListVerion()
  764. {
  765. int rc = 0;
  766. // const char* data = "Callback function called";
  767. char sql[100];
  768. char zErrMsg[100];
  769. memset(sql, 0, 100);
  770. memset(zErrMsg, 0, 100);
  771. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  772. /* Execute SQL statement */
  773. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  774. if( rc != SQLITE_OK )
  775. {
  776. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  777. }
  778. }
  779. void OCPP_get_TableAuthlocalAllData(void)
  780. {
  781. int rc = 0;
  782. char sql[100];
  783. char zErrMsg[100];
  784. memset(sql, 0, 100);
  785. memset(zErrMsg, 0, 100);
  786. sprintf(sql,"select * from ocpp_auth_local ");
  787. /* Execute SQL statement */
  788. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  789. if( rc != SQLITE_OK )
  790. {
  791. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  792. }
  793. //return ver;
  794. }
  795. int OCPP_cleanLocalList()
  796. {
  797. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  798. char *errMsg = 0;
  799. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  800. if (SQLITE_OK != rc)
  801. {
  802. DEBUG_INFO("%s\n",errMsg);
  803. return FALSE;
  804. }
  805. return TRUE;
  806. }
  807. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  808. {
  809. int isSuccess = FALSE;
  810. int ret = 0;
  811. //const char* data = "Callback function called";
  812. char sql[300];
  813. char zErrMsg[200];
  814. memset(sql, 0, 300);
  815. memset(zErrMsg, 0, 200);
  816. 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);
  817. //* Execute SQL statement */
  818. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  819. if( ret != SQLITE_OK )
  820. {
  821. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  822. return isSuccess;
  823. }
  824. memset(sql, 0, 300);
  825. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  826. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  827. if( ret != SQLITE_OK )
  828. {
  829. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  830. return isSuccess;
  831. }
  832. isSuccess = TRUE;
  833. return isSuccess;
  834. }
  835. void OCPP_getIdTagFromLocalList(char idTag[])
  836. {
  837. int rc = 0;
  838. // const char* data = "Callback function called";
  839. char sql[100];
  840. char zErrMsg[100];
  841. memset(sql, 0, 100);
  842. memset(zErrMsg, 0, 100);
  843. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  844. memset(&idTagQuery, 0, sizeof(idTagQuery));
  845. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  846. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  847. /* Execute SQL statement */
  848. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  849. if( rc != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. }
  853. //return ver;
  854. }
  855. void OCPP_deleteIdTagFromLocalList(char idTag[])
  856. {
  857. //int ver = 0;
  858. //int isSuccess = FALSE;
  859. int rc = 0;
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  865. //* Execute SQL statement */
  866. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  867. if( rc != SQLITE_OK )
  868. {
  869. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  870. }
  871. }
  872. int getCurrentYear()
  873. {
  874. int result = 0;
  875. time_t CurrentTime;
  876. struct tm *tm;
  877. CurrentTime = time(NULL);
  878. tm=localtime(&CurrentTime);
  879. result = (tm->tm_year + 1900);
  880. return result;
  881. }
  882. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  883. {
  884. int result = PASS;
  885. char* errMsg = NULL;
  886. char sqlStr[8192];
  887. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  888. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  889. {
  890. result = FAIL;
  891. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  892. }
  893. 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));
  894. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  895. {
  896. result = FAIL;
  897. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  898. }
  899. return result;
  900. }
  901. //==========================================
  902. // Check time passed since today
  903. //==========================================
  904. long long DiffTimebWithNow(struct timeb ST)
  905. {
  906. //return milli-second
  907. struct timeb ET;
  908. long long StartTime,StopTime;
  909. ftime(&ET);
  910. StartTime=(long long)ST.time;
  911. StopTime=(long long)ET.time;
  912. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  913. }
  914. int getTimePassSinceToday(uint8_t gun_index)
  915. {
  916. int result = -1;
  917. static time_t lastTime[4];
  918. time_t t;
  919. struct tm *tmStartToday;
  920. struct timeb tbStartToday;
  921. t=time(NULL);
  922. if(difftime(t, lastTime[gun_index])>0)
  923. {
  924. tmStartToday=localtime(&t);
  925. tmStartToday->tm_hour = 0;
  926. tmStartToday->tm_min = 0;
  927. tmStartToday->tm_sec = 0;
  928. tbStartToday.time = mktime(tmStartToday);
  929. tbStartToday.millitm = 0;
  930. result = DiffTimebWithNow(tbStartToday)/1000;
  931. lastTime[gun_index] = t;
  932. }
  933. return result;
  934. }
  935. void getNowDatetime(uint8_t *data)
  936. {
  937. time_t t = time(NULL);
  938. struct tm tm = *localtime(&t);
  939. 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);
  940. }
  941. int syncDateTimeRTC(uint8_t *data)
  942. {
  943. struct ParsingResult
  944. {
  945. int result;
  946. int scanedElement;
  947. int year;
  948. int month;
  949. int mday;
  950. int hour;
  951. int min;
  952. int sec;
  953. int tz_hour;
  954. int tz_min;
  955. float minSec;
  956. }result;
  957. struct tm tmOrg;
  958. struct tm *tmTarget;
  959. struct timeb tbTarget;
  960. char buf[128];
  961. memset(&result, 0x00, sizeof(struct ParsingResult));
  962. result.result = PASS;
  963. if(strstr((char*)data, ".") != NULL)
  964. {
  965. // Original data with mini second
  966. if(strstr((char*)data, "Z") != NULL)
  967. {
  968. // Original data with Z
  969. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  970. &result.year,
  971. &result.month,
  972. &result.mday,
  973. &result.hour,
  974. &result.min,
  975. &result.sec,
  976. &result.minSec);
  977. }
  978. else
  979. {
  980. // Original data without Z
  981. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  982. &result.year,
  983. &result.month,
  984. &result.mday,
  985. &result.hour,
  986. &result.min,
  987. &result.sec,
  988. &result.minSec,
  989. &result.tz_hour,
  990. &result.tz_min);
  991. }
  992. }
  993. else
  994. {
  995. // Original data without mini second
  996. if(strstr((char*)data, "Z") != NULL)
  997. {
  998. // Original data with Z
  999. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1000. &result.year,
  1001. &result.month,
  1002. &result.mday,
  1003. &result.hour,
  1004. &result.min,
  1005. &result.sec);
  1006. }
  1007. else
  1008. {
  1009. // Original data without Z
  1010. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1011. &result.year,
  1012. &result.month,
  1013. &result.mday,
  1014. &result.hour,
  1015. &result.min,
  1016. &result.sec,
  1017. &result.tz_hour,
  1018. &result.tz_min);
  1019. }
  1020. }
  1021. tmOrg.tm_year = result.year - 1900;
  1022. tmOrg.tm_mon = result.month - 1;
  1023. tmOrg.tm_mday = result.mday;
  1024. tmOrg.tm_hour = result.hour;
  1025. tmOrg.tm_min = result.min;
  1026. tmOrg.tm_sec = result.sec;
  1027. tmOrg.tm_gmtoff = 0;
  1028. tbTarget.time = mktime(&tmOrg);
  1029. tbTarget.timezone = 0;
  1030. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1031. tmTarget = gmtime(&tbTarget.time);
  1032. 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);
  1033. //DEBUG_INFO(" org date time: %s\n", data);
  1034. //DEBUG_INFO("parse date time: %s\n", buf);
  1035. system(buf);
  1036. system("/sbin/hwclock -w --systohc");
  1037. if(result.scanedElement < 6)
  1038. result.result = FAIL;
  1039. return result.result;
  1040. }
  1041. //==========================================
  1042. // GetCompositeSchedule logic related function
  1043. //==========================================
  1044. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1045. {
  1046. //return milli-second
  1047. unsigned int StartTime,StopTime;
  1048. StartTime=(unsigned int)ST.time;
  1049. StopTime=(unsigned int)ET.time;
  1050. return (StopTime-StartTime);
  1051. }
  1052. int DiffTimebWithNowSec(struct timeb ST)
  1053. {
  1054. //return milli-second
  1055. struct timeb ET;
  1056. unsigned int StartTime,StopTime;
  1057. ftime(&ET);
  1058. StartTime=(unsigned int)ST.time;
  1059. StopTime=(unsigned int)ET.time;
  1060. return (StopTime-StartTime);
  1061. }
  1062. int getStartStop(uint8_t *start, uint8_t *stop)
  1063. {
  1064. int result = -1;
  1065. struct tm tmStart;
  1066. struct timeb tbStart;
  1067. struct tm tmStop;
  1068. struct timeb tbStop;
  1069. 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) &&
  1070. (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))
  1071. {
  1072. //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);
  1073. //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);
  1074. tmStart.tm_year -= 1900;
  1075. tmStart.tm_mon -= 1;
  1076. tbStart.time = mktime(&tmStart);
  1077. tbStart.millitm = 0;
  1078. tmStop.tm_year -= 1900;
  1079. tmStop.tm_mon -= 1;
  1080. tbStop.time = mktime(&tmStop);
  1081. tbStop.millitm = 0;
  1082. result = DiffTimebSec(tbStart, tbStop);
  1083. //DEBUG_INFO("getStartStop(): %d\n", result);
  1084. }
  1085. else
  1086. {
  1087. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1088. }
  1089. return result;
  1090. }
  1091. int isOvertNow(uint8_t *start)
  1092. {
  1093. int result = NO;
  1094. struct tm tmStart;
  1095. struct timeb tbStart;
  1096. 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))
  1097. {
  1098. //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);
  1099. tmStart.tm_year -= 1900;
  1100. tmStart.tm_mon -= 1;
  1101. tbStart.time = mktime(&tmStart);
  1102. tbStart.millitm = 0;
  1103. if(DiffTimebWithNowSec(tbStart) <= 0)
  1104. result = NO;
  1105. else
  1106. result = YES;
  1107. }
  1108. else
  1109. {
  1110. DEBUG_WARN("Start date parsing error.\n");
  1111. }
  1112. return result;
  1113. }
  1114. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1115. {
  1116. int result = -1;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. struct tm tmStop;
  1120. struct timeb tbStop;
  1121. 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) &&
  1122. (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))
  1123. {
  1124. tmStart.tm_year -= 1900;
  1125. tmStart.tm_mon -= 1;
  1126. tbStart.time = mktime(&tmStart);
  1127. tbStart.millitm = 0;
  1128. tmStop.tm_year -= 1900;
  1129. tmStop.tm_mon -= 1;
  1130. tbStop.time = mktime(&tmStop);
  1131. tbStop.millitm = 0;
  1132. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1133. }
  1134. return result;
  1135. }
  1136. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1137. {
  1138. FILE *fp;
  1139. char profileFileName[128];
  1140. char *line = NULL;
  1141. size_t len = 0;
  1142. time_t CurrentTime;
  1143. struct tm *tmComposite;
  1144. struct StructChargingProfile maxProfile;
  1145. uint8_t limitMax=0;
  1146. int compositePeriodIdx = 0;
  1147. CurrentTime = time(NULL);
  1148. tmComposite=localtime(&CurrentTime);
  1149. 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);
  1150. if(isUnitA)
  1151. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1152. else
  1153. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1154. compositeProfile->ChargingSchedule.Duration = durationReq;
  1155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1156. {
  1157. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1158. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1159. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1160. }
  1161. compositeProfile->ChargingProfileId = 0;
  1162. compositeProfile->StackLevel = 99 ;
  1163. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1164. maxProfile.ChargingProfileId = -1;
  1165. maxProfile.ChargingSchedule.Duration = -1;
  1166. system("rm -f /tmp/*.json");
  1167. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1168. // Search max profile
  1169. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1170. if((access(profileFileName, F_OK))!=-1)
  1171. {
  1172. fp = fopen(profileFileName, "r");
  1173. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1174. {
  1175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1176. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1178. }
  1179. maxProfile.ChargingProfileId = -1;
  1180. maxProfile.StackLevel = -1;
  1181. while(getline(&line, &len, fp) != -1)
  1182. {
  1183. json_object *obj = NULL;
  1184. obj = json_tokener_parse(line);
  1185. if(is_error(obj))
  1186. {
  1187. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1188. }
  1189. else
  1190. {
  1191. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1192. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1193. )
  1194. {
  1195. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1196. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1197. )
  1198. {
  1199. struct tm tmFrom, tmTo;
  1200. struct timeb tbFrom, tbTo;
  1201. 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) &&
  1202. (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))
  1203. {
  1204. tmFrom.tm_year -= 1900;
  1205. tmFrom.tm_mon -= 1;
  1206. tbFrom.time = mktime(&tmFrom);
  1207. tmTo.tm_year -= 1900;
  1208. tmTo.tm_mon -= 1;
  1209. tbTo.time = mktime(&tmTo);
  1210. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1211. {
  1212. if(maxProfile.ChargingProfileId == -1)
  1213. DEBUG_INFO("MaxProfile found.\n");
  1214. else
  1215. DEBUG_INFO("MaxProfile updated.\n");
  1216. // Required item
  1217. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1218. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1219. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1220. if(isUnitA)
  1221. {
  1222. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1223. 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++)
  1224. {
  1225. 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"));
  1226. 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?
  1227. 3:
  1228. 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")));
  1229. 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")));
  1230. }
  1231. }
  1232. else
  1233. {
  1234. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1235. 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++)
  1236. {
  1237. 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"));
  1238. 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?
  1239. 3:
  1240. 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")));
  1241. 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));
  1242. }
  1243. }
  1244. // Optional item
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1246. {
  1247. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)maxProfile.ValidFrom, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1254. {
  1255. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1256. }
  1257. else
  1258. {
  1259. sprintf((char*)maxProfile.ValidTo, " ");
  1260. }
  1261. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1262. {
  1263. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1264. }
  1265. else
  1266. {
  1267. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1268. }
  1269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1270. {
  1271. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1272. }
  1273. else
  1274. {
  1275. maxProfile.TransactionId = -1;
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.Duration = 86400;
  1284. }
  1285. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1286. {
  1287. 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")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1292. }
  1293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1294. {
  1295. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1296. }
  1297. else
  1298. {
  1299. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. else
  1305. {
  1306. if(maxProfile.ChargingProfileId == -1)
  1307. DEBUG_INFO("MaxProfile found.\n");
  1308. else
  1309. DEBUG_INFO("MaxProfile updated.\n");
  1310. // Required item
  1311. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1312. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1313. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1314. if(isUnitA)
  1315. {
  1316. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1317. 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++)
  1318. {
  1319. 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"));
  1320. 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?
  1321. 3:
  1322. 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")));
  1323. 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")));
  1324. }
  1325. }
  1326. else
  1327. {
  1328. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1329. 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++)
  1330. {
  1331. 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"));
  1332. 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?
  1333. 3:
  1334. 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")));
  1335. 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));
  1336. }
  1337. }
  1338. // Optional item
  1339. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1340. {
  1341. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1342. }
  1343. else
  1344. {
  1345. sprintf((char*)maxProfile.ValidFrom, " ");
  1346. }
  1347. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. {
  1349. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1350. }
  1351. else
  1352. {
  1353. sprintf((char*)maxProfile.ValidTo, " ");
  1354. }
  1355. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1356. {
  1357. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1358. }
  1359. else
  1360. {
  1361. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1362. }
  1363. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1364. {
  1365. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1366. }
  1367. else
  1368. {
  1369. maxProfile.TransactionId = -1;
  1370. }
  1371. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1372. {
  1373. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1374. }
  1375. else
  1376. {
  1377. maxProfile.ChargingSchedule.Duration = 86400;
  1378. }
  1379. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1380. {
  1381. 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")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1386. }
  1387. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1388. {
  1389. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1390. }
  1391. else
  1392. {
  1393. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. json_object_put(obj);
  1399. }
  1400. fclose(fp);
  1401. /*
  1402. if(maxProfile.ChargingProfileId !=-1)
  1403. {
  1404. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1405. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1406. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1407. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1408. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1409. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1410. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1411. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1412. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1413. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1414. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1416. {
  1417. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1418. {
  1419. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1420. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1421. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1422. }
  1423. }
  1424. }
  1425. else
  1426. DEBUG_INFO("MaxProfile not found.\n");
  1427. DEBUG_INFO("------------------------------------\n");*/
  1428. }
  1429. if(maxProfile.ChargingProfileId != -1)
  1430. {
  1431. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1432. {
  1433. if(maxProfile.ChargingSchedule.Duration != -1)
  1434. {
  1435. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1436. 0:
  1437. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1438. }
  1439. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1440. {
  1441. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1442. {
  1443. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1444. 0:
  1445. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1446. if(idxPeriod > 0)
  1447. {
  1448. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1449. {
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1457. {
  1458. if(maxProfile.ChargingSchedule.Duration != -1)
  1459. {
  1460. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1461. }
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1465. {
  1466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1467. if(idxPeriod > 0)
  1468. {
  1469. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1470. {
  1471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. else
  1478. {
  1479. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1480. {
  1481. if(maxProfile.ChargingSchedule.Duration != -1)
  1482. {
  1483. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1484. 0:
  1485. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1486. }
  1487. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1488. {
  1489. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1490. {
  1491. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1492. 0:
  1493. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1494. if(idxPeriod > 0)
  1495. {
  1496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1497. {
  1498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. else
  1505. {
  1506. if(maxProfile.ChargingSchedule.Duration != -1)
  1507. {
  1508. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1509. 0:
  1510. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1511. }
  1512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1513. {
  1514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1515. {
  1516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1517. 0:
  1518. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1519. if(idxPeriod > 0)
  1520. {
  1521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1522. {
  1523. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. /*
  1531. DEBUG_INFO("MaxProfile after align.\n");
  1532. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1533. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1534. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1535. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1536. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1537. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1538. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1539. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1540. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1541. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1542. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1546. {
  1547. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1548. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1549. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1550. }
  1551. }
  1552. DEBUG_INFO("------------------------------------\n");*/
  1553. }
  1554. // Find each profile period quantity
  1555. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1556. {
  1557. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1558. limitMax = idx+1;
  1559. }
  1560. if(maxProfile.ChargingProfileId != -1)
  1561. {
  1562. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1563. {
  1564. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1565. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1566. (maxProfile.ChargingSchedule.Duration > 0))
  1567. {
  1568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1569. {
  1570. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1571. compositePeriodIdx++;
  1572. }
  1573. else
  1574. {
  1575. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1576. }
  1577. }
  1578. }
  1579. }
  1580. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1581. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1582. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1583. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1585. {
  1586. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1587. {
  1588. compositeProfile->ChargingProfileId = 1;
  1589. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1590. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1591. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1592. }
  1593. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1594. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1595. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1596. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1597. }
  1598. if(line)
  1599. free(line);
  1600. }
  1601. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1602. {
  1603. FILE *fp;
  1604. char profileFileName[128];
  1605. char *line = NULL;
  1606. size_t len = 0;
  1607. time_t CurrentTime;
  1608. struct tm *tmComposite;
  1609. struct StructChargingProfile maxProfile;
  1610. struct StructChargingProfile defaultTxProfile;
  1611. struct StructChargingProfile txProfile;
  1612. struct StructChargingSchedulePeriod tmpPeriod;
  1613. uint8_t limitMax=0;
  1614. uint8_t limitDef=0;
  1615. uint8_t limitTx=0;
  1616. int compositePeriodIdx = 0;
  1617. CurrentTime = time(NULL);
  1618. tmComposite=localtime(&CurrentTime);
  1619. 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);
  1620. if(isUnitA)
  1621. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1622. else
  1623. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1624. compositeProfile->ChargingSchedule.Duration = durationReq;
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1628. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1629. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1630. }
  1631. compositeProfile->ChargingProfileId = 0;
  1632. compositeProfile->StackLevel = 99 ;
  1633. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1634. maxProfile.ChargingProfileId = -1;
  1635. defaultTxProfile.ChargingProfileId = -1;
  1636. txProfile.ChargingProfileId = -1;
  1637. maxProfile.ChargingSchedule.Duration = -1;
  1638. defaultTxProfile.ChargingSchedule.Duration = -1;
  1639. txProfile.ChargingSchedule.Duration = -1;
  1640. system("rm -f /tmp/*.json");
  1641. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1642. /*
  1643. * Search valid charging profile
  1644. */
  1645. //DEBUG_INFO("====================================\n");
  1646. // Search tx profile
  1647. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1648. if((access(profileFileName, F_OK))!=-1)
  1649. {
  1650. fp = fopen(profileFileName, "r");
  1651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1652. {
  1653. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1654. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1655. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1656. }
  1657. txProfile.ChargingProfileId = -1;
  1658. txProfile.StackLevel = -1;
  1659. while(getline(&line, &len, fp) != -1)
  1660. {
  1661. json_object *obj = NULL;
  1662. obj = json_tokener_parse(line);
  1663. if(is_error(obj))
  1664. {
  1665. DEBUG_ERROR("Parse txProfile from file error.\n");
  1666. }
  1667. else
  1668. {
  1669. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1670. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1671. )
  1672. {
  1673. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1674. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1675. )
  1676. {
  1677. struct tm tmFrom, tmTo;
  1678. struct timeb tbFrom, tbTo;
  1679. 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) &&
  1680. (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))
  1681. {
  1682. tmFrom.tm_year -= 1900;
  1683. tmFrom.tm_mon -= 1;
  1684. tbFrom.time = mktime(&tmFrom);
  1685. tmTo.tm_year -= 1900;
  1686. tmTo.tm_mon -= 1;
  1687. tbTo.time = mktime(&tmTo);
  1688. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1689. {
  1690. if(txProfile.ChargingProfileId == -1)
  1691. DEBUG_INFO("TxProfile found.\n");
  1692. else
  1693. DEBUG_INFO("TxProfile updated.\n");
  1694. // Required item
  1695. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1696. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1697. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1698. if(isUnitA)
  1699. {
  1700. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1701. 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++)
  1702. {
  1703. 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"));
  1704. 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?
  1705. 3:
  1706. 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")));
  1707. 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")));
  1708. }
  1709. }
  1710. else
  1711. {
  1712. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1713. 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++)
  1714. {
  1715. 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"));
  1716. 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?
  1717. 3:
  1718. 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")));
  1719. 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));
  1720. }
  1721. }
  1722. // Optional item
  1723. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1724. {
  1725. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1726. }
  1727. else
  1728. {
  1729. sprintf((char*)txProfile.ValidFrom, " ");
  1730. }
  1731. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1732. {
  1733. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1734. }
  1735. else
  1736. {
  1737. sprintf((char*)txProfile.ValidTo, " ");
  1738. }
  1739. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1740. {
  1741. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1742. }
  1743. else
  1744. {
  1745. sprintf((char*)txProfile.RecurrencyKind, " ");
  1746. }
  1747. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1748. {
  1749. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1750. }
  1751. else
  1752. {
  1753. txProfile.TransactionId = -1;
  1754. }
  1755. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1756. {
  1757. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1758. }
  1759. else
  1760. {
  1761. txProfile.ChargingSchedule.Duration = 86400;
  1762. }
  1763. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1764. {
  1765. 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")));
  1766. }
  1767. else
  1768. {
  1769. 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));
  1770. }
  1771. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1772. {
  1773. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1774. }
  1775. else
  1776. {
  1777. txProfile.ChargingSchedule.MinChargingRate = -1;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. else
  1783. {
  1784. if(txProfile.ChargingProfileId == -1)
  1785. DEBUG_INFO("TxProfile found.\n");
  1786. else
  1787. DEBUG_INFO("TxProfile updated.\n");
  1788. // Required item
  1789. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1790. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1791. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1792. if(isUnitA)
  1793. {
  1794. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1795. 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++)
  1796. {
  1797. 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"));
  1798. 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?
  1799. 3:
  1800. 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")));
  1801. 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")));
  1802. }
  1803. }
  1804. else
  1805. {
  1806. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1807. 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++)
  1808. {
  1809. 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"));
  1810. 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?
  1811. 3:
  1812. 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")));
  1813. 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));
  1814. }
  1815. }
  1816. // Optional item
  1817. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1818. {
  1819. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1820. }
  1821. else
  1822. {
  1823. sprintf((char*)txProfile.ValidFrom, " ");
  1824. }
  1825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1826. {
  1827. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1828. }
  1829. else
  1830. {
  1831. sprintf((char*)txProfile.ValidTo, " ");
  1832. }
  1833. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1834. {
  1835. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1836. }
  1837. else
  1838. {
  1839. sprintf((char*)txProfile.RecurrencyKind, " ");
  1840. }
  1841. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1842. {
  1843. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1844. }
  1845. else
  1846. {
  1847. txProfile.TransactionId = -1;
  1848. }
  1849. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1850. {
  1851. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1852. }
  1853. else
  1854. {
  1855. txProfile.ChargingSchedule.Duration = 86400;
  1856. }
  1857. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1858. {
  1859. 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")));
  1860. }
  1861. else
  1862. {
  1863. 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));
  1864. }
  1865. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1866. {
  1867. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1868. }
  1869. else
  1870. {
  1871. txProfile.ChargingSchedule.MinChargingRate = -1;
  1872. }
  1873. }
  1874. }
  1875. }
  1876. json_object_put(obj);
  1877. }
  1878. fclose(fp);
  1879. /*
  1880. if(txProfile.ChargingProfileId != -1)
  1881. {
  1882. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1883. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1884. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1885. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1886. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1887. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1888. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1889. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1890. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1891. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1892. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1896. {
  1897. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1898. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1899. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1900. }
  1901. }
  1902. }
  1903. else
  1904. DEBUG_INFO("TxProfile not found.\n");*/
  1905. }
  1906. // Search default tx profile
  1907. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1908. if((access(profileFileName, F_OK))==-1)
  1909. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1910. if((access(profileFileName, F_OK))!=-1)
  1911. {
  1912. fp = fopen(profileFileName, "r");
  1913. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1917. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1918. }
  1919. defaultTxProfile.ChargingProfileId = -1;
  1920. defaultTxProfile.StackLevel = -1;
  1921. while(getline(&line, &len, fp) != -1)
  1922. {
  1923. json_object *obj = NULL;
  1924. obj = json_tokener_parse(line);
  1925. if(is_error(obj))
  1926. {
  1927. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1928. }
  1929. else
  1930. {
  1931. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1932. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1933. )
  1934. {
  1935. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1936. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1937. )
  1938. {
  1939. struct tm tmFrom, tmTo;
  1940. struct timeb tbFrom, tbTo;
  1941. 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) &&
  1942. (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))
  1943. {
  1944. tmFrom.tm_year -= 1900;
  1945. tmFrom.tm_mon -= 1;
  1946. tbFrom.time = mktime(&tmFrom);
  1947. tmTo.tm_year -= 1900;
  1948. tmTo.tm_mon -= 1;
  1949. tbTo.time = mktime(&tmTo);
  1950. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1951. {
  1952. if(defaultTxProfile.ChargingProfileId == -1)
  1953. DEBUG_INFO("TxDefaultProfile found.\n");
  1954. else
  1955. DEBUG_INFO("TxDefaultProfile updated.\n");
  1956. // Required item
  1957. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1958. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1959. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1960. if(isUnitA)
  1961. {
  1962. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1963. 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++)
  1964. {
  1965. 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"));
  1966. 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?
  1967. 3:
  1968. 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")));
  1969. 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")));
  1970. }
  1971. }
  1972. else
  1973. {
  1974. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1975. 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++)
  1976. {
  1977. 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"));
  1978. 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?
  1979. 3:
  1980. 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")));
  1981. 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));
  1982. }
  1983. }
  1984. // Optional item
  1985. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1986. {
  1987. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1988. }
  1989. else
  1990. {
  1991. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1992. }
  1993. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1994. {
  1995. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2000. }
  2001. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2002. {
  2003. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2004. }
  2005. else
  2006. {
  2007. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2008. }
  2009. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2010. {
  2011. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2012. }
  2013. else
  2014. {
  2015. defaultTxProfile.TransactionId = -1;
  2016. }
  2017. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2018. {
  2019. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2020. }
  2021. else
  2022. {
  2023. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2024. }
  2025. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2026. {
  2027. 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")));
  2028. }
  2029. else
  2030. {
  2031. 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));
  2032. }
  2033. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2034. {
  2035. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2036. }
  2037. else
  2038. {
  2039. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2040. }
  2041. }
  2042. }
  2043. }
  2044. else
  2045. {
  2046. if(defaultTxProfile.ChargingProfileId == -1)
  2047. DEBUG_INFO("TxDefaultProfile found.\n");
  2048. else
  2049. DEBUG_INFO("TxDefaultProfile updated.\n");
  2050. // Required item
  2051. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2052. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2053. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2054. if(isUnitA)
  2055. {
  2056. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2057. 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++)
  2058. {
  2059. 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"));
  2060. 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?
  2061. 3:
  2062. 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")));
  2063. 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")));
  2064. }
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2069. 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++)
  2070. {
  2071. 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"));
  2072. 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?
  2073. 3:
  2074. 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")));
  2075. 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));
  2076. }
  2077. }
  2078. // Optional item
  2079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2080. {
  2081. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2082. }
  2083. else
  2084. {
  2085. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2086. }
  2087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2088. {
  2089. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2090. }
  2091. else
  2092. {
  2093. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2094. }
  2095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2096. {
  2097. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2102. }
  2103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2104. {
  2105. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2106. }
  2107. else
  2108. {
  2109. defaultTxProfile.TransactionId = -1;
  2110. }
  2111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2112. {
  2113. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2114. }
  2115. else
  2116. {
  2117. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2118. }
  2119. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2120. {
  2121. 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")));
  2122. }
  2123. else
  2124. {
  2125. 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));
  2126. }
  2127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2128. {
  2129. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2130. }
  2131. else
  2132. {
  2133. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. json_object_put(obj);
  2139. }
  2140. fclose(fp);
  2141. /*
  2142. if(defaultTxProfile.ChargingProfileId != -1)
  2143. {
  2144. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2145. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2146. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2147. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2148. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2149. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2150. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2151. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2152. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2153. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2154. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2156. {
  2157. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2158. {
  2159. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2160. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2161. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2162. }
  2163. }
  2164. }
  2165. else
  2166. DEBUG_INFO("TxDefaultProfile not found.\n");
  2167. DEBUG_INFO("------------------------------------\n");*/
  2168. }
  2169. // Search max profile
  2170. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2171. if((access(profileFileName, F_OK))!=-1)
  2172. {
  2173. fp = fopen(profileFileName, "r");
  2174. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2175. {
  2176. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2179. }
  2180. maxProfile.ChargingProfileId = -1;
  2181. maxProfile.StackLevel = -1;
  2182. while(getline(&line, &len, fp) != -1)
  2183. {
  2184. json_object *obj = NULL;
  2185. obj = json_tokener_parse(line);
  2186. if(is_error(obj))
  2187. {
  2188. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2189. }
  2190. else
  2191. {
  2192. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2193. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2194. )
  2195. {
  2196. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2197. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2198. )
  2199. {
  2200. struct tm tmFrom, tmTo;
  2201. struct timeb tbFrom, tbTo;
  2202. 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) &&
  2203. (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))
  2204. {
  2205. tmFrom.tm_year -= 1900;
  2206. tmFrom.tm_mon -= 1;
  2207. tbFrom.time = mktime(&tmFrom);
  2208. tmTo.tm_year -= 1900;
  2209. tmTo.tm_mon -= 1;
  2210. tbTo.time = mktime(&tmTo);
  2211. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2212. {
  2213. if(maxProfile.ChargingProfileId == -1)
  2214. DEBUG_INFO("MaxProfile found.\n");
  2215. else
  2216. DEBUG_INFO("MaxProfile updated.\n");
  2217. // Required item
  2218. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2219. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2220. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2221. if(isUnitA)
  2222. {
  2223. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2224. 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++)
  2225. {
  2226. 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"));
  2227. 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?
  2228. 3:
  2229. 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")));
  2230. 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")));
  2231. }
  2232. }
  2233. else
  2234. {
  2235. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2236. 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++)
  2237. {
  2238. 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"));
  2239. 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?
  2240. 3:
  2241. 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")));
  2242. 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));
  2243. }
  2244. }
  2245. // Optional item
  2246. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2247. {
  2248. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2249. }
  2250. else
  2251. {
  2252. sprintf((char*)maxProfile.ValidFrom, " ");
  2253. }
  2254. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2255. {
  2256. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2257. }
  2258. else
  2259. {
  2260. sprintf((char*)maxProfile.ValidTo, " ");
  2261. }
  2262. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2263. {
  2264. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2265. }
  2266. else
  2267. {
  2268. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2269. }
  2270. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2271. {
  2272. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2273. }
  2274. else
  2275. {
  2276. maxProfile.TransactionId = -1;
  2277. }
  2278. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2279. {
  2280. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2281. }
  2282. else
  2283. {
  2284. maxProfile.ChargingSchedule.Duration = 86400;
  2285. }
  2286. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2287. {
  2288. 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")));
  2289. }
  2290. else
  2291. {
  2292. 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));
  2293. }
  2294. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2295. {
  2296. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2297. }
  2298. else
  2299. {
  2300. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2301. }
  2302. }
  2303. }
  2304. }
  2305. else
  2306. {
  2307. if(maxProfile.ChargingProfileId == -1)
  2308. DEBUG_INFO("MaxProfile found.\n");
  2309. else
  2310. DEBUG_INFO("MaxProfile updated.\n");
  2311. // Required item
  2312. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2313. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2314. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2315. if(isUnitA)
  2316. {
  2317. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2318. 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++)
  2319. {
  2320. 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"));
  2321. 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?
  2322. 3:
  2323. 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")));
  2324. 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")));
  2325. }
  2326. }
  2327. else
  2328. {
  2329. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2330. 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++)
  2331. {
  2332. 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"));
  2333. 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?
  2334. 3:
  2335. 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")));
  2336. 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));
  2337. }
  2338. }
  2339. // Optional item
  2340. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2341. {
  2342. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2343. }
  2344. else
  2345. {
  2346. sprintf((char*)maxProfile.ValidFrom, " ");
  2347. }
  2348. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2349. {
  2350. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2351. }
  2352. else
  2353. {
  2354. sprintf((char*)maxProfile.ValidTo, " ");
  2355. }
  2356. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2357. {
  2358. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2359. }
  2360. else
  2361. {
  2362. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2363. }
  2364. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2365. {
  2366. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2367. }
  2368. else
  2369. {
  2370. maxProfile.TransactionId = -1;
  2371. }
  2372. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2373. {
  2374. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2375. }
  2376. else
  2377. {
  2378. maxProfile.ChargingSchedule.Duration = 86400;
  2379. }
  2380. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2381. {
  2382. 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")));
  2383. }
  2384. else
  2385. {
  2386. 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));
  2387. }
  2388. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2389. {
  2390. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2391. }
  2392. else
  2393. {
  2394. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2395. }
  2396. }
  2397. }
  2398. }
  2399. json_object_put(obj);
  2400. }
  2401. fclose(fp);
  2402. /*
  2403. if(maxProfile.ChargingProfileId !=-1)
  2404. {
  2405. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2406. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2407. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2408. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2409. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2410. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2411. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2412. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2414. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2415. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. }
  2425. }
  2426. else
  2427. DEBUG_INFO("MaxProfile not found.\n");
  2428. DEBUG_INFO("------------------------------------\n");*/
  2429. }
  2430. /*
  2431. * Align found profile start schedule & periods
  2432. */
  2433. //DEBUG_INFO("====================================\n");
  2434. /*
  2435. // For local test usage, force modify found profile start schedule info
  2436. 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);
  2437. 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);
  2438. 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);
  2439. */
  2440. if(txProfile.ChargingProfileId != -1)
  2441. {
  2442. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2443. {
  2444. if(txProfile.ChargingSchedule.Duration != -1)
  2445. {
  2446. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2447. 0:
  2448. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2449. }
  2450. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2451. {
  2452. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2453. {
  2454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2455. 0:
  2456. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2457. if(idxPeriod > 0)
  2458. {
  2459. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2460. {
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2462. }
  2463. }
  2464. }
  2465. }
  2466. }
  2467. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2468. {
  2469. if(txProfile.ChargingSchedule.Duration != -1)
  2470. {
  2471. 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?
  2472. 0:
  2473. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2474. }
  2475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2476. {
  2477. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2478. {
  2479. 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?
  2480. 0:
  2481. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2482. if(idxPeriod > 0)
  2483. {
  2484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2485. {
  2486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. }
  2492. else
  2493. {
  2494. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2495. {
  2496. if(txProfile.ChargingSchedule.Duration != -1)
  2497. {
  2498. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2499. 0:
  2500. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2501. }
  2502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2503. {
  2504. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2505. {
  2506. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2507. 0:
  2508. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2509. if(idxPeriod > 0)
  2510. {
  2511. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2512. {
  2513. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. else
  2520. {
  2521. if(txProfile.ChargingSchedule.Duration != -1)
  2522. {
  2523. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2524. 0:
  2525. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2526. }
  2527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2528. {
  2529. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2530. {
  2531. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2532. 0:
  2533. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2534. if(idxPeriod > 0)
  2535. {
  2536. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2537. {
  2538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2539. }
  2540. }
  2541. }
  2542. }
  2543. }
  2544. }
  2545. /*
  2546. DEBUG_INFO("txProfile after align.\n");
  2547. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2548. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2549. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2550. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2551. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2552. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2553. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2554. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2555. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2556. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2557. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2558. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2559. {
  2560. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2561. {
  2562. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2563. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2564. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2565. }
  2566. }*/
  2567. }
  2568. if(defaultTxProfile.ChargingProfileId != -1)
  2569. {
  2570. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2571. {
  2572. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2575. 0:
  2576. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2583. 0:
  2584. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2585. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2586. {
  2587. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2588. }
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2600. {
  2601. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. 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?
  2604. 0:
  2605. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. 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?
  2612. 0:
  2613. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2614. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2615. {
  2616. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2617. }
  2618. if(idxPeriod > 0)
  2619. {
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2621. {
  2622. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. else
  2629. {
  2630. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2631. {
  2632. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2633. {
  2634. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2635. 0:
  2636. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2637. }
  2638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2639. {
  2640. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2641. {
  2642. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2643. 0:
  2644. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2645. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2646. {
  2647. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2648. }
  2649. if(idxPeriod > 0)
  2650. {
  2651. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2652. {
  2653. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. else
  2660. {
  2661. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2662. {
  2663. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2664. 0:
  2665. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2666. }
  2667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2668. {
  2669. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2670. {
  2671. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2672. 0:
  2673. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2674. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2675. {
  2676. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2677. }
  2678. if(idxPeriod > 0)
  2679. {
  2680. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2681. {
  2682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. /*
  2690. DEBUG_INFO("defaultTxProfile after align.\n");
  2691. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2692. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2693. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2694. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2695. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2696. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2697. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2698. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2699. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2700. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2701. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2702. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2703. {
  2704. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2705. {
  2706. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2707. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2708. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2709. }
  2710. }
  2711. DEBUG_INFO("------------------------------------\n");*/
  2712. }
  2713. if(maxProfile.ChargingProfileId != -1)
  2714. {
  2715. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2716. {
  2717. if(maxProfile.ChargingSchedule.Duration != -1)
  2718. {
  2719. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2720. 0:
  2721. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2722. }
  2723. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2726. {
  2727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2728. 0:
  2729. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2730. if(idxPeriod > 0)
  2731. {
  2732. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2733. {
  2734. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2735. }
  2736. }
  2737. }
  2738. }
  2739. }
  2740. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2741. {
  2742. if(maxProfile.ChargingSchedule.Duration != -1)
  2743. {
  2744. 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?
  2745. 0:
  2746. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2747. }
  2748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2749. {
  2750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2751. {
  2752. 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?
  2753. 0:
  2754. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2755. if(idxPeriod > 0)
  2756. {
  2757. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2758. {
  2759. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2768. {
  2769. if(maxProfile.ChargingSchedule.Duration != -1)
  2770. {
  2771. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2772. 0:
  2773. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2774. }
  2775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2776. {
  2777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2778. {
  2779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2780. 0:
  2781. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2782. if(idxPeriod > 0)
  2783. {
  2784. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2785. {
  2786. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2787. }
  2788. }
  2789. }
  2790. }
  2791. }
  2792. else
  2793. {
  2794. if(maxProfile.ChargingSchedule.Duration != -1)
  2795. {
  2796. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2797. 0:
  2798. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2799. }
  2800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2801. {
  2802. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2803. {
  2804. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2805. 0:
  2806. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2807. if(idxPeriod > 0)
  2808. {
  2809. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2810. {
  2811. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. /*
  2819. DEBUG_INFO("MaxProfile after align.\n");
  2820. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2821. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2822. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2823. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2824. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2825. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2826. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2827. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2828. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2829. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2830. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2832. {
  2833. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2834. {
  2835. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2836. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2837. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2838. }
  2839. }
  2840. DEBUG_INFO("------------------------------------\n");*/
  2841. }
  2842. /*
  2843. * Merge to conposite schedule
  2844. */
  2845. //DEBUG_INFO("====================================\n");
  2846. // Find each profile period quantity
  2847. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2848. {
  2849. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2850. limitMax = idx+1;
  2851. }
  2852. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2853. {
  2854. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2855. limitDef = idx+1;
  2856. }
  2857. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2858. {
  2859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2860. limitTx = idx+1;
  2861. }
  2862. // TxProfile found, composite schedule based on it
  2863. if(txProfile.ChargingProfileId != -1)
  2864. {
  2865. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2866. {
  2867. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2868. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2869. (txProfile.ChargingSchedule.Duration > 0))
  2870. {
  2871. if(maxProfile.ChargingProfileId != -1)
  2872. {
  2873. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2874. {
  2875. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2876. {
  2877. if((maxProfile.ChargingSchedule.Duration > 0))
  2878. {
  2879. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2880. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2881. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2882. }
  2883. else
  2884. {
  2885. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2886. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2887. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2888. }
  2889. }
  2890. if(idxMaxPeriod == (limitMax-1))
  2891. {
  2892. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2893. {
  2894. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2895. {
  2896. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2897. compositePeriodIdx++;
  2898. }
  2899. else
  2900. {
  2901. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2902. }
  2903. }
  2904. }
  2905. }
  2906. }
  2907. else
  2908. {
  2909. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2910. {
  2911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2912. compositePeriodIdx++;
  2913. }
  2914. else
  2915. {
  2916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2917. }
  2918. }
  2919. }
  2920. if(idxTxPeriod == (limitTx-1))
  2921. {
  2922. if(defaultTxProfile.ChargingProfileId != -1)
  2923. {
  2924. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2925. {
  2926. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2927. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2928. (defaultTxProfile.ChargingSchedule.Duration>0))
  2929. {
  2930. if(maxProfile.ChargingProfileId != -1)
  2931. {
  2932. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2935. {
  2936. if((maxProfile.ChargingSchedule.Duration > 0))
  2937. {
  2938. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2939. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2940. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2941. }
  2942. else
  2943. {
  2944. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2945. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2946. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2947. }
  2948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2949. {
  2950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2951. {
  2952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2953. compositePeriodIdx++;
  2954. }
  2955. else
  2956. {
  2957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2958. }
  2959. }
  2960. // Delete duplicate period
  2961. if(compositePeriodIdx > 1)
  2962. {
  2963. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2964. {
  2965. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2966. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2967. compositePeriodIdx -= 1;
  2968. }
  2969. }
  2970. }
  2971. else
  2972. break;
  2973. }
  2974. }
  2975. else
  2976. {
  2977. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2978. {
  2979. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2980. compositePeriodIdx++;
  2981. }
  2982. else
  2983. {
  2984. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2985. }
  2986. }
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2994. else if(defaultTxProfile.ChargingProfileId != -1)
  2995. {
  2996. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2997. {
  2998. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2999. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3000. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3001. {
  3002. if(maxProfile.ChargingProfileId != -1)
  3003. {
  3004. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3005. {
  3006. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3007. {
  3008. if((maxProfile.ChargingSchedule.Duration > 0))
  3009. {
  3010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3012. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3013. }
  3014. else
  3015. {
  3016. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3017. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3018. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3019. }
  3020. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3021. {
  3022. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3023. {
  3024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3025. compositePeriodIdx++;
  3026. }
  3027. else
  3028. {
  3029. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3030. }
  3031. }
  3032. // Delete duplicate period
  3033. if(compositePeriodIdx > 1)
  3034. {
  3035. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3036. {
  3037. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3038. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3039. compositePeriodIdx -= 1;
  3040. }
  3041. }
  3042. }
  3043. else
  3044. break;
  3045. }
  3046. }
  3047. else
  3048. {
  3049. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3050. {
  3051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3052. compositePeriodIdx++;
  3053. }
  3054. else
  3055. {
  3056. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. // Fill other period by MaxProfile
  3063. if(maxProfile.ChargingProfileId != -1)
  3064. {
  3065. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3066. {
  3067. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3068. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3069. (maxProfile.ChargingSchedule.Duration > 0))
  3070. {
  3071. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3072. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3073. {
  3074. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3075. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3076. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3077. }
  3078. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3079. {
  3080. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3081. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3082. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3083. }
  3084. if(tmpPeriod.Limit != -1)
  3085. {
  3086. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3087. {
  3088. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3089. {
  3090. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3091. compositePeriodIdx++;
  3092. }
  3093. else
  3094. {
  3095. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3096. }
  3097. }
  3098. // Delete duplicate period
  3099. if(compositePeriodIdx > 1)
  3100. {
  3101. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3102. {
  3103. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3104. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3105. compositePeriodIdx -= 1;
  3106. }
  3107. }
  3108. }
  3109. }
  3110. }
  3111. }
  3112. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3113. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3114. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3115. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3119. {
  3120. compositeProfile->ChargingProfileId = 1;
  3121. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3122. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3123. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3124. }
  3125. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3126. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3127. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3128. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3129. }
  3130. if(line)
  3131. free(line);
  3132. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3133. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3134. }
  3135. //==========================================
  3136. // Init all share memory
  3137. //==========================================
  3138. int InitShareMemory()
  3139. {
  3140. int result = PASS;
  3141. int MeterSMId;
  3142. //creat ShmSysConfigAndInfo
  3143. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3144. {
  3145. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3146. result = FAIL;
  3147. }
  3148. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3149. {
  3150. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3151. result = FAIL;
  3152. }
  3153. else
  3154. {}
  3155. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3156. {
  3157. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3158. result = FAIL;
  3159. }
  3160. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3161. {
  3162. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3163. result = FAIL;
  3164. }
  3165. else
  3166. {}
  3167. //creat ShmPsuData
  3168. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3169. {
  3170. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3171. result = FAIL;
  3172. }
  3173. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3174. {
  3175. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3176. result = FAIL;
  3177. }
  3178. else
  3179. {}
  3180. //creat ShmOCPP16Data
  3181. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3182. {
  3183. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3184. result = FAIL;
  3185. }
  3186. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3187. {
  3188. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3189. result = FAIL;
  3190. }
  3191. else
  3192. {}
  3193. /****************************** For Initial Settings************************************************/
  3194. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3195. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3196. // allocate Configuration memory address
  3197. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3198. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3199. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3200. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3201. //offline MeterValue Interval
  3202. TempMeterValueInterval = 0;
  3203. return result;
  3204. }
  3205. int ProcessShareMemory()
  3206. {
  3207. if(InitShareMemory() == FAIL)
  3208. {
  3209. DEBUG_ERROR("InitShareMemory NG\n");
  3210. if(ShmStatusCodeData!=NULL)
  3211. {
  3212. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3213. }
  3214. sleep(5);
  3215. return FAIL;
  3216. }
  3217. return PASS;
  3218. }
  3219. void CheckSystemValue(void)
  3220. {
  3221. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3222. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3223. char filenmae[100]={0};
  3224. char str[100]={0};
  3225. int tempIndex = 0;
  3226. //===============================
  3227. // send Heartbeat
  3228. //===============================
  3229. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3230. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3231. {
  3232. clientTime.Heartbeat=time((time_t*)NULL);
  3233. if(server_sign == TRUE)
  3234. {
  3235. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3236. }
  3237. else
  3238. {
  3239. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3240. }
  3241. }
  3242. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3243. {
  3244. //parameter for test
  3245. sendHeartbeatRequest(0);
  3246. //==============================================
  3247. // Reset Waiting Time
  3248. //==============================================
  3249. HeartBeatWithNOResponse += 1;
  3250. }
  3251. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3252. {
  3253. //==========================================
  3254. // csu trigger DataTransferReq
  3255. //==========================================
  3256. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3257. {
  3258. sendDataTransferRequest(gun_index);
  3259. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3260. }
  3261. //===============================
  3262. // CSU Trigger Authorize Request
  3263. //===============================
  3264. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3265. {
  3266. sendAuthorizeRequest(0);
  3267. authorizeRetryTimes = authorizeRetryTimes + 1;
  3268. if(authorizeRetryTimes < 3)
  3269. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3270. }
  3271. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3272. {
  3273. authorizeRetryTimes = 0;
  3274. SetOcppConnStatus(FALSE);
  3275. server_sign = FALSE;
  3276. }
  3277. 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))
  3278. {
  3279. sendAuthorizeRequest(0);
  3280. }
  3281. //==============================================
  3282. // Charger start transaction
  3283. //==============================================
  3284. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3285. {
  3286. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3287. sendStartTransactionRequest(gun_index);
  3288. clientTime.StartTransaction = time((time_t*)NULL);
  3289. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3290. storeTempStopTransaction(gun_index);
  3291. }
  3292. //==============================================
  3293. // Charger stop transaction
  3294. //==============================================
  3295. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3296. {
  3297. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3298. sendStopTransactionRequest(gun_index);
  3299. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3300. clientTime.StopTransaction = time((time_t*)NULL);
  3301. }
  3302. //==============================================
  3303. // Charger status report
  3304. //==============================================
  3305. //--- Check Mode Change ---//
  3306. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3308. {
  3309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3310. {
  3311. tempIndex = ((gun_index==2) ? 1: 0);
  3312. }
  3313. else
  3314. {
  3315. tempIndex = gun_index;
  3316. }
  3317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3318. {
  3319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3320. {
  3321. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3322. {
  3323. // Sent unplug message for California pricing logic
  3324. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3325. {
  3326. uint8_t ts[20];
  3327. getNowDatetime(ts);
  3328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3331. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3332. }
  3333. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3334. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3336. }
  3337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3338. {
  3339. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3340. if((access(filenmae,F_OK))!=-1)
  3341. {
  3342. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3343. sprintf(str,"rm -f %s",filenmae);
  3344. system(str);
  3345. }
  3346. }
  3347. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3348. #if 1 // for TempStopTransaction
  3349. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3350. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3351. {
  3352. checkTempStopTransaction(gun_index);
  3353. }
  3354. #endif
  3355. }
  3356. }
  3357. }
  3358. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3361. {
  3362. tempIndex = ((gun_index==2) ? 1: 0);
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < CCS_QUANTITY; index++)
  3369. {
  3370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3371. {
  3372. 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]*/ )
  3373. {
  3374. // Sent unplug message for California pricing logic
  3375. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3376. {
  3377. uint8_t ts[20];
  3378. getNowDatetime(ts);
  3379. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3380. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3381. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3382. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3383. }
  3384. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3385. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3386. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3387. }
  3388. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3389. {
  3390. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3391. if((access(filenmae,F_OK))!=-1)
  3392. {
  3393. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3394. sprintf(str,"rm -f %s",filenmae);
  3395. system(str);
  3396. }
  3397. }
  3398. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3399. #if 1 // for TempStopTransaction
  3400. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3401. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3402. {
  3403. checkTempStopTransaction(gun_index);
  3404. }
  3405. #endif
  3406. }
  3407. }
  3408. }
  3409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3410. {
  3411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3412. {
  3413. tempIndex = ((gun_index==2) ? 1: 0);
  3414. }
  3415. else
  3416. {
  3417. tempIndex = gun_index;
  3418. }
  3419. for (int index = 0; index < GB_QUANTITY; index++)
  3420. {
  3421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3422. {
  3423. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3424. {
  3425. // Sent unplug message for California pricing logic
  3426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3427. {
  3428. uint8_t ts[20];
  3429. getNowDatetime(ts);
  3430. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3431. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3432. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3433. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3434. }
  3435. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3436. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3437. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3438. }
  3439. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3440. {
  3441. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3442. if((access(filenmae,F_OK))!=-1)
  3443. {
  3444. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3445. sprintf(str,"rm -f %s",filenmae);
  3446. system(str);
  3447. }
  3448. }
  3449. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3450. #if 1 // for TempStopTransaction
  3451. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3452. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3453. {
  3454. checkTempStopTransaction(gun_index);
  3455. }
  3456. #endif
  3457. }
  3458. }
  3459. }
  3460. else if(gunType[gun_index] == GUN_TYPE_DO)
  3461. {
  3462. tempIndex = gun_index;
  3463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3464. {
  3465. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3466. {
  3467. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3468. {
  3469. // Sent unplug message for California pricing logic
  3470. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3471. {
  3472. uint8_t ts[20];
  3473. getNowDatetime(ts);
  3474. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3475. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3476. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3477. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3478. }
  3479. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3480. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3481. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3482. }
  3483. 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
  3484. {
  3485. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3486. if((access(filenmae,F_OK))!=-1)
  3487. {
  3488. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3489. sprintf(str,"rm -f %s",filenmae);
  3490. system(str);
  3491. }
  3492. }
  3493. 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);
  3494. #if 1 // for TempStopTransaction
  3495. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3496. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3497. {
  3498. checkTempStopTransaction(gun_index);
  3499. }
  3500. #endif
  3501. }
  3502. }
  3503. }
  3504. else
  3505. {
  3506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3507. {
  3508. tempIndex = 2;
  3509. }
  3510. else
  3511. {
  3512. tempIndex = gun_index;
  3513. }
  3514. for (int index = 0; index < AC_QUANTITY; index++)
  3515. {
  3516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3517. {
  3518. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3519. {
  3520. // Sent unplug message for California pricing logic
  3521. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3522. {
  3523. uint8_t ts[20];
  3524. getNowDatetime(ts);
  3525. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3526. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3527. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3528. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3529. }
  3530. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3531. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3532. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3533. }
  3534. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3535. {
  3536. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3537. if((access(filenmae,F_OK))!=-1)
  3538. {
  3539. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3540. sprintf(str,"rm -f %s",filenmae);
  3541. system(str);
  3542. }
  3543. }
  3544. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3545. #if 1 // for TempStopTransaction
  3546. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3547. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3548. {
  3549. checkTempStopTransaction(gun_index);
  3550. }
  3551. #endif
  3552. }
  3553. }// END
  3554. }
  3555. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3556. (
  3557. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3558. )
  3559. )
  3560. {
  3561. if(SystemInitial > 0)
  3562. SystemInitial -= 1;
  3563. sendStatusNotificationRequest(gun_index);
  3564. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3565. }
  3566. //==============================================
  3567. // CSU Trigger Smart Charging Profilw
  3568. //==============================================
  3569. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3570. {
  3571. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3572. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3573. }
  3574. //==============================================
  3575. // Meter report
  3576. //==============================================
  3577. // Trigger MeterValue
  3578. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3579. {
  3580. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3581. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3582. }
  3583. // ClockAlign MeterValue
  3584. 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))
  3585. {
  3586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3587. {
  3588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3589. {
  3590. tempIndex = ((gun_index==2) ? 1: 0);
  3591. }
  3592. else
  3593. {
  3594. tempIndex = gun_index;
  3595. }
  3596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3597. {
  3598. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3599. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3600. {
  3601. reqClockAlignMeter[gun_index] = 1;
  3602. }
  3603. }// End for CHAdeMO
  3604. }
  3605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3606. {
  3607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3608. {
  3609. tempIndex = ((gun_index==2) ? 1: 0);
  3610. }
  3611. else
  3612. {
  3613. tempIndex = gun_index;
  3614. }
  3615. for (int index = 0; index < CCS_QUANTITY; index++)
  3616. {
  3617. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3619. {
  3620. reqClockAlignMeter[gun_index] = 1;
  3621. }
  3622. } // End for CCS
  3623. }
  3624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < GB_QUANTITY; index++)
  3635. {
  3636. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3637. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3638. {
  3639. reqClockAlignMeter[gun_index] = 1;
  3640. }
  3641. }// End for GB
  3642. }
  3643. else if(gunType[gun_index] == GUN_TYPE_DO)
  3644. {
  3645. tempIndex = gun_index;
  3646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3647. {
  3648. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3649. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3650. {
  3651. reqClockAlignMeter[gun_index] = 1;
  3652. }
  3653. }
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3668. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3669. {
  3670. reqClockAlignMeter[gun_index] = 1;
  3671. }
  3672. }//End for AC
  3673. }
  3674. if(reqClockAlignMeter[gun_index] == 1)
  3675. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3676. }
  3677. // Sample period MeterValue
  3678. 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))))
  3679. {
  3680. //check Transaction active
  3681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3692. {
  3693. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3694. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3697. {
  3698. reqSampleMeter[gun_index] = 1;
  3699. }
  3700. }
  3701. }// End for CHAdeMO
  3702. }
  3703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3716. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3719. {
  3720. reqSampleMeter[gun_index] = 1;
  3721. }
  3722. }
  3723. } // End for CCS
  3724. }
  3725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3726. {
  3727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3728. {
  3729. tempIndex = ((gun_index==2) ? 1: 0);
  3730. }
  3731. else
  3732. {
  3733. tempIndex = gun_index;
  3734. }
  3735. for (int index = 0; index < GB_QUANTITY; index++)
  3736. {
  3737. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3738. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3739. {
  3740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3741. {
  3742. reqSampleMeter[gun_index] = 1;
  3743. }
  3744. }
  3745. }// End for GB
  3746. }
  3747. else if(gunType[gun_index] == GUN_TYPE_DO)
  3748. {
  3749. tempIndex = gun_index;
  3750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3751. {
  3752. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3753. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3756. {
  3757. reqSampleMeter[gun_index] = 1;
  3758. }
  3759. }
  3760. }
  3761. }
  3762. else
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3765. {
  3766. tempIndex = 2;
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < AC_QUANTITY; index++)
  3773. {
  3774. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3775. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3776. {
  3777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3778. {
  3779. reqSampleMeter[gun_index] = 1;
  3780. }
  3781. }
  3782. }//End for AC
  3783. }
  3784. if(reqSampleMeter[gun_index] == 1)
  3785. {
  3786. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3787. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3788. storeTempStopTransaction(gun_index);
  3789. }
  3790. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3791. }
  3792. //==============================================
  3793. // Check Connector reserved
  3794. //==============================================
  3795. //===============================
  3796. // Check if Reserve is expired
  3797. //===============================
  3798. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3799. {
  3800. double diff_t;
  3801. struct tm tp;
  3802. // current time
  3803. time_t t = time(NULL);
  3804. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3805. tp.tm_isdst = -1;
  3806. time_t utc = mktime(&tp);
  3807. diff_t = difftime(utc, t);
  3808. if(diff_t <= 0)
  3809. {
  3810. DEBUG_INFO("reserve expired.\n");
  3811. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3812. }
  3813. }//END OF Check if Reserve is expired
  3814. //==========================================
  3815. // csu trigger FirmwareStatusNotificationReq
  3816. //==========================================
  3817. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3818. {
  3819. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3820. }
  3821. //==========================================
  3822. // csu trigger DiagnosticsStatusNotificationReq
  3823. //==========================================
  3824. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3825. {
  3826. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3827. }
  3828. //==========================================
  3829. // csu trigger CancelReservationConf
  3830. //==========================================
  3831. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3832. {
  3833. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3834. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3835. }
  3836. //==========================================
  3837. // csu trigger ChangeAvailabilityConf
  3838. //==========================================
  3839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3840. {
  3841. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3842. }
  3843. //==========================================
  3844. // csu trigger UnlockConnectorConf
  3845. //==========================================
  3846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3847. {
  3848. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3849. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3850. }
  3851. //==========================================
  3852. // csu trigger ReserveNowConf
  3853. //==========================================
  3854. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3855. {
  3856. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3857. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3858. }
  3859. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3860. {
  3861. sendSignCertificateRequest();
  3862. }
  3863. }
  3864. }
  3865. //==========================================
  3866. // send request routine
  3867. //==========================================
  3868. int sendAuthorizeRequest(int gun_index)
  3869. {
  3870. mtrace();
  3871. int result = FAIL;
  3872. char message[100]={0};
  3873. char guid[37];
  3874. char tempdata[65]={0};
  3875. DEBUG_INFO("sendAuthorizeRequest...\n");
  3876. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3877. //Local Authorize
  3878. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3879. {
  3880. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3881. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3882. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3883. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3884. result = PASS;
  3885. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3886. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3887. authorizeRetryTimes = 0;
  3888. return result;
  3889. }
  3890. 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))||
  3891. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3892. {
  3893. // Query from cache
  3894. DEBUG_INFO("Authorize from cache.\n");
  3895. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3896. // Query from list
  3897. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3898. {
  3899. DEBUG_INFO("Authorize from list.\n");
  3900. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3901. }
  3902. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3903. {
  3904. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3905. {
  3906. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3907. }
  3908. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3909. {
  3910. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3911. }
  3912. if(!GetOcppConnStatus())
  3913. {
  3914. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3915. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3916. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3917. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3918. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3919. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3920. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3921. authorizeRetryTimes = 0;
  3922. return result;
  3923. }
  3924. }
  3925. else
  3926. {
  3927. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3928. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3929. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3930. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3931. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3932. else
  3933. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3934. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3935. result = PASS;
  3936. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3937. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3938. authorizeRetryTimes = 0;
  3939. return result;
  3940. }
  3941. }
  3942. //initialize struct Authorize
  3943. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3944. //get data from shared memory
  3945. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3946. random_uuid(guid);
  3947. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3948. LWS_Send(message);
  3949. sprintf(tempdata, "Authorize,%d", gun_index);
  3950. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3951. {
  3952. result = PASS;
  3953. DEBUG_INFO("Authorize mapItem pass\n");
  3954. }
  3955. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3956. return result;
  3957. }
  3958. int sendBootNotificationRequest(void)
  3959. {
  3960. mtrace();
  3961. int result = FAIL;
  3962. char message[500]={0}, payload[700]={0};
  3963. char guid[37]={0};
  3964. char tempdata[65]={0};
  3965. // Fill BootNotification fields
  3966. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3967. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3968. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3969. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3970. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3971. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3972. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3973. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3974. ShmOCPP16Data->ChargeBoxId
  3975. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3976. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3977. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3978. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3979. ,ShmOCPP16Data->BootNotification.CpIccid
  3980. ,ShmOCPP16Data->BootNotification.CpImsi);
  3981. random_uuid(guid);
  3982. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3983. LWS_Send(message);
  3984. sprintf(tempdata, "BootNotification,0");
  3985. 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*/)
  3986. {
  3987. result = PASS;
  3988. }
  3989. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3990. strcpy(queuedata,message);
  3991. return result;
  3992. }
  3993. int sendDataTransferRequest(int gun_index)
  3994. {
  3995. mtrace();
  3996. char message[1000]={0};
  3997. char guid[37]={0};
  3998. char tempdata[65]={0};
  3999. int result = FAIL;
  4000. random_uuid(guid);
  4001. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4002. MESSAGE_TYPE_CALL,
  4003. guid,
  4004. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4005. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4006. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4007. LWS_Send(message);
  4008. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4009. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4010. {
  4011. result = PASS;
  4012. DEBUG_INFO("DataTransfer mapItem pass\n");
  4013. }
  4014. return result;
  4015. }
  4016. int sendDiagnosticsStatusNotificationRequest(char *status)
  4017. {
  4018. mtrace();
  4019. int result = FAIL;
  4020. char message[110]={0};
  4021. char guid[37]={0};
  4022. char tempdata[65]={0};
  4023. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4024. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4025. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4026. random_uuid(guid);
  4027. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4028. LWS_SendNow(message);
  4029. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4030. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4031. {
  4032. result = PASS;
  4033. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4034. }
  4035. //#ifdef SystemLogMessage
  4036. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4037. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4038. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4039. //#endif
  4040. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4041. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4042. //record status
  4043. if(strcmp(status,"Idle")==0)
  4044. {
  4045. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4046. }
  4047. else if(strcmp(status,"Uploaded")==0)
  4048. {
  4049. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4050. }
  4051. else if(strcmp(status,"UploadFailed")==0)
  4052. {
  4053. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4054. }
  4055. else if(strcmp(status,"Uploading")==0)
  4056. {
  4057. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4058. }
  4059. return result;
  4060. }
  4061. int sendFirmwareStatusNotificationRequest(char *status)
  4062. {
  4063. mtrace();
  4064. int result = FAIL;
  4065. char message[110]={0};
  4066. char guid[37]={0};
  4067. char tempdata[65]={0};
  4068. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4069. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4070. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4071. random_uuid(guid);
  4072. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4073. LWS_SendNow(message);
  4074. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4075. 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*/)
  4076. {
  4077. result = PASS;
  4078. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4079. }
  4080. //#ifdef SystemLogMessage
  4081. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4082. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4083. //#endif
  4084. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4085. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4086. //record status
  4087. if(strcmp(status,"Downloaded")==0)
  4088. {
  4089. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4090. }
  4091. else if(strcmp(status,"DownloadFailed")==0)
  4092. {
  4093. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4094. }
  4095. else if(strcmp(status,"Downloading")==0)
  4096. {
  4097. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4098. }
  4099. else if(strcmp(status,"Idle")==0)
  4100. {
  4101. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4102. }
  4103. else if(strcmp(status,"InstallationFailed")==0)
  4104. {
  4105. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4106. }
  4107. else if(strcmp(status,"Installing")==0)
  4108. {
  4109. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4110. }
  4111. else if(strcmp(status,"Installed")==0)
  4112. {
  4113. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4114. }
  4115. return result;
  4116. }
  4117. int sendHeartbeatRequest(int gun_index)
  4118. {
  4119. mtrace();
  4120. int result = FAIL;
  4121. char message[80]={0};
  4122. char guid[37]={0};
  4123. char tempdata[65]={0};
  4124. random_uuid(guid);
  4125. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4126. , MESSAGE_TYPE_CALL
  4127. , guid );
  4128. LWS_Send(message);
  4129. sprintf(tempdata, "Heartbeat,%d", 0);
  4130. 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*/)
  4131. {
  4132. result = PASS;
  4133. }
  4134. return result;
  4135. }
  4136. int sendStartTransactionRequest(int gun_index)
  4137. {
  4138. mtrace();
  4139. int result = FAIL;
  4140. char message[250]={0};
  4141. char guid[37]={0};
  4142. struct timeval tmnow;
  4143. struct tm *tm;
  4144. char buf[28];//, usec_buf[6];
  4145. char tempdata[65]={0};
  4146. int tempIndex = 0;
  4147. DEBUG_INFO("sendStartTransactionRequest...\n");
  4148. gettimeofday(&tmnow, NULL);
  4149. time_t t;
  4150. t = time(NULL);
  4151. /*UTC time and date*/
  4152. tm = gmtime(&t);
  4153. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4154. #if 0 // remove temporally
  4155. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4156. strcat(buf,".");
  4157. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4158. strcat(buf,usec_buf);
  4159. #endif
  4160. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4161. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4162. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4163. // clear StartTransaction Response
  4164. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4165. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4166. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4167. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4168. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4171. {
  4172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4173. {
  4174. tempIndex = ((gun_index==2) ? 1: 0);
  4175. }
  4176. else
  4177. {
  4178. tempIndex = gun_index;
  4179. }
  4180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4183. {
  4184. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4185. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4186. }
  4187. }
  4188. }
  4189. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4190. {
  4191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4192. {
  4193. tempIndex = ((gun_index==2) ? 1: 0);
  4194. }
  4195. else
  4196. {
  4197. tempIndex = gun_index;
  4198. }
  4199. for (int index = 0; index < CCS_QUANTITY; index++)
  4200. {
  4201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4202. {
  4203. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4204. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4205. }
  4206. }
  4207. }
  4208. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4211. {
  4212. tempIndex = ((gun_index==2) ? 1: 0);
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < GB_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4221. {
  4222. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4223. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4224. }
  4225. }
  4226. }
  4227. else if(gunType[gun_index] == GUN_TYPE_DO)
  4228. {
  4229. tempIndex = gun_index;
  4230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4231. {
  4232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4233. {
  4234. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4235. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4236. }
  4237. }
  4238. }
  4239. else
  4240. {
  4241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4242. {
  4243. tempIndex = 2;
  4244. }
  4245. else
  4246. {
  4247. tempIndex = gun_index;
  4248. }
  4249. for (int index = 0; index < AC_QUANTITY; index++)
  4250. {
  4251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4252. {
  4253. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4254. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4255. }
  4256. }
  4257. }
  4258. random_uuid(guid);
  4259. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4260. {
  4261. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4262. , gun_index +1
  4263. , MESSAGE_TYPE_CALL
  4264. , guid
  4265. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4266. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4267. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4268. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4269. }
  4270. else
  4271. {
  4272. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4273. , gun_index +1
  4274. , MESSAGE_TYPE_CALL
  4275. , guid
  4276. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4277. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4278. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4279. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4280. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4281. }
  4282. #if 1
  4283. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4284. 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*/)
  4285. {
  4286. result = PASS;
  4287. }
  4288. #endif
  4289. strcpy(queuedata, message);
  4290. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4291. OCPP_insert_transaction_msg(YES, queuedata);
  4292. return result;
  4293. }
  4294. int sendStatusNotificationRequest(int gun_index)
  4295. {
  4296. mtrace();
  4297. int result = FAIL;
  4298. char message[600]={0};
  4299. char guid[37];
  4300. int currentStatus = 0;
  4301. struct timeval tmnow;
  4302. struct tm *tm;
  4303. char buf[28];//, usec_buf[6];
  4304. char tempdata[65]={0};
  4305. int tempIndex = 0;
  4306. uint8_t isStateChanged = TRUE;
  4307. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4308. gettimeofday(&tmnow, NULL);
  4309. time_t t;
  4310. t = time(NULL);
  4311. /*UTC time and date*/
  4312. tm = gmtime(&t);
  4313. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4314. #if 0 // remove temporally
  4315. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4316. strcat(buf,".");
  4317. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4318. strcat(buf,usec_buf);
  4319. #endif
  4320. //printf("%s",buf);
  4321. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4322. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4323. // it's option
  4324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4325. /*
  4326. enum _SYSTEM_STATUS
  4327. {
  4328. S_BOOTING = 0,
  4329. S_IDLE, = 1
  4330. S_AUTHORIZING, =2
  4331. S_REASSIGN_CHECK, =3
  4332. S_REASSIGN, =4
  4333. S_PRECHARGE, =5
  4334. S_PREPARING_FOR_EV, =6
  4335. S_PREPARING_FOR_EVSE, =7
  4336. S_CHARGING, =8
  4337. S_TERMINATING, =9
  4338. S_COMPLETE, =10
  4339. S_ALARM, =11
  4340. S_FAULT =12
  4341. }
  4342. */
  4343. //check Transaction active
  4344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4345. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4356. {
  4357. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4358. {
  4359. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4360. {
  4361. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4362. {
  4363. currentStatus = Preparing; //OCPP Status: Preparing
  4364. }
  4365. else
  4366. {
  4367. currentStatus = Available; //OCPP Status: Available
  4368. }
  4369. }
  4370. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4371. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4372. ) //S_PRECHARGE
  4373. {
  4374. currentStatus = Preparing; //OCPP Status: Preparing
  4375. }
  4376. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4377. {
  4378. currentStatus = Charging; //OCPP Status: Charging
  4379. }
  4380. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4381. {
  4382. currentStatus = Finishing; //OCPP Status: Finishing
  4383. }
  4384. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4385. {
  4386. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4387. }
  4388. 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
  4389. {
  4390. currentStatus = Unavailable; //OCPP Status: Unavailable
  4391. }
  4392. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4393. {
  4394. currentStatus = Faulted; //OCPP Status: Faulted
  4395. }
  4396. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4397. {
  4398. currentStatus = Reserved; //OCPP Status: Reserved
  4399. }
  4400. } //end of the same index
  4401. }//end of for CHAdeMO_QUANTITY
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CCS_QUANTITY; index++)
  4414. {
  4415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4420. {
  4421. currentStatus = Preparing; //OCPP Status: Preparing
  4422. }
  4423. else
  4424. {
  4425. currentStatus = Available; //OCPP Status: Available
  4426. }
  4427. }
  4428. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4429. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4430. ) //S_PRECHARGE
  4431. {
  4432. currentStatus = Preparing; //OCPP Status: Preparing
  4433. }
  4434. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4435. {
  4436. currentStatus = Charging; //OCPP Status: Charging
  4437. }
  4438. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4439. {
  4440. currentStatus = Finishing; //OCPP Status: Finishing
  4441. }
  4442. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4443. {
  4444. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4445. }
  4446. 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
  4447. {
  4448. currentStatus = Unavailable; //OCPP Status : Unavailable
  4449. }
  4450. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4451. {
  4452. currentStatus = Faulted; //OCPP Status: Faulted
  4453. }
  4454. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4455. {
  4456. currentStatus = Reserved; //OCPP Status: Reserved
  4457. }
  4458. } //end of the same index
  4459. } // end of for CCS_QUANTITY
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4464. {
  4465. tempIndex = ((gun_index==2) ? 1: 0);
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < GB_QUANTITY; index++)
  4472. {
  4473. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4474. {
  4475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4476. {
  4477. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4478. {
  4479. currentStatus = Preparing; //OCPP Status: Preparing
  4480. }
  4481. else
  4482. {
  4483. currentStatus = Available; //OCPP Status: Available
  4484. }
  4485. }
  4486. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4487. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4488. ) //S_PRECHARGE
  4489. {
  4490. currentStatus = Preparing; //OCPP Status: Preparing
  4491. }
  4492. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4493. {
  4494. currentStatus = Charging; //OCPP Status: Charging
  4495. }
  4496. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4497. {
  4498. currentStatus = Finishing; //OCPP Status: Finishing
  4499. }
  4500. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4501. {
  4502. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4503. }
  4504. 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
  4505. {
  4506. currentStatus = Unavailable; //OCPP Status: Unavailable
  4507. }
  4508. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4509. {
  4510. currentStatus = Faulted; //OCPP Status: Faulted
  4511. }
  4512. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4513. {
  4514. currentStatus = Reserved; //OCPP Status: Reserved
  4515. }
  4516. } //end of the same index
  4517. } // end of for GB_QUANTITY
  4518. }
  4519. else if(gunType[gun_index] == GUN_TYPE_DO)
  4520. {
  4521. tempIndex = gun_index;
  4522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4527. {
  4528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4529. {
  4530. currentStatus = Preparing; //OCPP Status: Preparing
  4531. }
  4532. else
  4533. {
  4534. currentStatus = Available; //OCPP Status: Available
  4535. }
  4536. }
  4537. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4538. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4539. ) //S_PRECHARGE
  4540. {
  4541. currentStatus = Preparing; //OCPP Status: Preparing
  4542. }
  4543. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4544. {
  4545. currentStatus = Charging; //OCPP Status: Charging
  4546. }
  4547. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4548. {
  4549. currentStatus = Finishing; //OCPP Status: Finishing
  4550. }
  4551. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4552. {
  4553. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4554. }
  4555. 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
  4556. {
  4557. currentStatus = Unavailable; //OCPP Status: Unavailable
  4558. }
  4559. 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
  4560. {
  4561. currentStatus = Faulted; //OCPP Status: Faulted
  4562. }
  4563. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4564. {
  4565. currentStatus = Reserved; //OCPP Status: Reserved
  4566. }
  4567. } //end of the same index
  4568. }
  4569. }
  4570. else
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4573. {
  4574. tempIndex = 2;
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < AC_QUANTITY; index++)
  4581. {
  4582. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4583. {
  4584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4585. {
  4586. 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))
  4587. {
  4588. currentStatus = Preparing; //OCPP Status: Preparing
  4589. }
  4590. else
  4591. {
  4592. currentStatus = Available; //OCPP Status: Available
  4593. }
  4594. }
  4595. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4596. {
  4597. currentStatus = Preparing; //OCPP Status: Preparing
  4598. }
  4599. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4600. {
  4601. currentStatus = Charging; //OCPP Status: Charging
  4602. }
  4603. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4604. {
  4605. currentStatus = Finishing; //OCPP Status: Finishing
  4606. }
  4607. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4608. {
  4609. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4610. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4611. else
  4612. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4613. }
  4614. 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
  4615. {
  4616. currentStatus = Unavailable; //OCPP Status: Unavailable
  4617. }
  4618. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4619. {
  4620. currentStatus = Faulted; //OCPP Status: Faulted
  4621. }
  4622. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4623. {
  4624. currentStatus = Reserved; //OCPP Status: Reserved
  4625. }
  4626. }//end of the same index
  4627. }//end of for AC_QUANTITY
  4628. }
  4629. //it's option
  4630. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4631. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4632. {
  4633. isStateChanged = FALSE;
  4634. }
  4635. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4636. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4637. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4639. random_uuid(guid);
  4640. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4641. , MESSAGE_TYPE_CALL
  4642. , guid
  4643. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4644. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4645. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4646. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4647. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4648. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4649. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4650. if((server_sign == TRUE) && isStateChanged)
  4651. {
  4652. LWS_Send(message);
  4653. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4654. 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*/)
  4655. {
  4656. //DEBUG_ERROR("statusNotification mapitem pass");
  4657. result = PASS;
  4658. }
  4659. }
  4660. else
  4661. {
  4662. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4663. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4664. result = PASS;
  4665. }
  4666. return result;
  4667. }
  4668. int sendStopTransactionRequest(int gun_index)
  4669. {
  4670. mtrace();
  4671. int result = FAIL;
  4672. //char message[1500]={0};
  4673. char guid[37]={0};
  4674. char tempdata[65]={0};
  4675. int tempIndex = 0;
  4676. char TempStopTransaction[256];
  4677. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4678. //int idx_sample=0;
  4679. DEBUG_INFO("sendStopTransactionRequest \n");
  4680. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4681. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4682. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4697. {
  4698. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4699. }
  4700. }// END OF CHAdeMO_QUANTITY
  4701. }
  4702. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4703. {
  4704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4705. {
  4706. tempIndex = ((gun_index==2) ? 1: 0);
  4707. }
  4708. else
  4709. {
  4710. tempIndex = gun_index;
  4711. }
  4712. for (int index = 0; index < CCS_QUANTITY; index++)
  4713. {
  4714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4715. {
  4716. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4717. }
  4718. }// END OF CCS_QUANTITY
  4719. }
  4720. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4721. {
  4722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4723. {
  4724. tempIndex = ((gun_index==2) ? 1: 0);
  4725. }
  4726. else
  4727. {
  4728. tempIndex = gun_index;
  4729. }
  4730. for (int index = 0; index < GB_QUANTITY; index++)
  4731. {
  4732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4733. {
  4734. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4735. }
  4736. }// END OF GB_QUANTITY
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_DO)
  4739. {
  4740. tempIndex = gun_index;
  4741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4744. {
  4745. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4746. }
  4747. }// END OF GB_QUANTITY
  4748. }
  4749. else
  4750. {
  4751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4752. {
  4753. tempIndex = 2;
  4754. }
  4755. else
  4756. {
  4757. tempIndex = gun_index;
  4758. }
  4759. for (int index = 0; index < AC_QUANTITY; index++)
  4760. {
  4761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4762. {
  4763. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4764. }
  4765. }// END OF AC_QUANTITY
  4766. }
  4767. //====================================== Stop Transaction Time =====================================================
  4768. struct timeval tmnow;
  4769. struct tm *tm;
  4770. char buf[28];//, usec_buf[6];
  4771. gettimeofday(&tmnow, NULL);
  4772. time_t t;
  4773. t = time(NULL);
  4774. /*UTC time and date*/
  4775. tm = gmtime(&t);
  4776. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4778. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4779. random_uuid(guid);
  4780. /***********************************transactionData******************************************************/
  4781. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4783. //=================================
  4784. // Transaction_Begin
  4785. //=================================
  4786. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4787. {
  4788. //============================================ Energy.Active.Import.Interval ================================
  4789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4792. 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*/]);
  4793. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4794. 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))
  4795. {
  4796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4797. }
  4798. else
  4799. {
  4800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4801. }
  4802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4804. }
  4805. //=================================
  4806. // Transaction_End
  4807. //=================================
  4808. // ================================= Current.Import L1 ===============================================
  4809. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4810. {
  4811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4812. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4815. {
  4816. tempIndex = ((gun_index==2) ? 1: 0);
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4825. {
  4826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4827. }
  4828. }// End of for CHAdeMO_QUANTITY
  4829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4830. }
  4831. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4832. {
  4833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4834. {
  4835. tempIndex = ((gun_index==2) ? 1: 0);
  4836. }
  4837. else
  4838. {
  4839. tempIndex = gun_index;
  4840. }
  4841. for (int index = 0; index < CCS_QUANTITY; index++)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4844. {
  4845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4846. }
  4847. }// End of for CCS_QUANTITY
  4848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4849. }
  4850. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < GB_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4863. {
  4864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4865. }
  4866. }// End of for GB_QUANTITY
  4867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_DO)
  4870. {
  4871. tempIndex = gun_index;
  4872. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4873. {
  4874. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4875. {
  4876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4877. }
  4878. }
  4879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4880. }
  4881. else
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4884. {
  4885. tempIndex = 2;
  4886. }
  4887. else
  4888. {
  4889. tempIndex = gun_index;
  4890. }
  4891. for (int index = 0; index < AC_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4896. }
  4897. }// End of for AC_QUANTITY
  4898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4899. }
  4900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4905. }
  4906. // ================================= Energy.Active.Import.Interval ==============================================
  4907. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4908. {
  4909. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4910. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4911. {
  4912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4913. {
  4914. tempIndex = ((gun_index==2) ? 1: 0);
  4915. }
  4916. else
  4917. {
  4918. tempIndex = gun_index;
  4919. }
  4920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4921. {
  4922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4923. {
  4924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4925. }
  4926. }// END OF CHAdeMO_QUANTITY
  4927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4928. }
  4929. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4930. {
  4931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4932. {
  4933. tempIndex = ((gun_index==2) ? 1: 0);
  4934. }
  4935. else
  4936. {
  4937. tempIndex = gun_index;
  4938. }
  4939. for (int index = 0; index < CCS_QUANTITY; index++)
  4940. {
  4941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4942. {
  4943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4944. }
  4945. }// END OF CCS_QUANTITY
  4946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4947. }
  4948. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4949. {
  4950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4951. {
  4952. tempIndex = ((gun_index==2) ? 1: 0);
  4953. }
  4954. else
  4955. {
  4956. tempIndex = gun_index;
  4957. }
  4958. for (int index = 0; index < GB_QUANTITY; index++)
  4959. {
  4960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4961. {
  4962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4963. }
  4964. }// END OF GB_QUANTITY
  4965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4966. }
  4967. else if(gunType[gun_index] == GUN_TYPE_DO)
  4968. {
  4969. tempIndex = gun_index;
  4970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4971. {
  4972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4973. {
  4974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4975. }
  4976. }
  4977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4978. }
  4979. else
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4982. {
  4983. tempIndex = 2;
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < AC_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4992. {
  4993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4994. }
  4995. }// END OF AC_QUANTITY
  4996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4997. }
  4998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5003. }
  5004. //=================================== Power.Active.Import ==================================================
  5005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5006. {
  5007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5011. {
  5012. tempIndex = ((gun_index==2) ? 1: 0);
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5023. }
  5024. } // End for CHAdeMO_QUANTITY
  5025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5026. }
  5027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5028. {
  5029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5030. {
  5031. tempIndex = ((gun_index==2) ? 1: 0);
  5032. }
  5033. else
  5034. {
  5035. tempIndex = gun_index;
  5036. }
  5037. for (int index = 0; index < CCS_QUANTITY; index++)
  5038. {
  5039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5040. {
  5041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5042. }
  5043. } // END for CCS_QUANTITY
  5044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5045. }
  5046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5047. {
  5048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5049. {
  5050. tempIndex = ((gun_index==2) ? 1: 0);
  5051. }
  5052. else
  5053. {
  5054. tempIndex = gun_index;
  5055. }
  5056. for (int index = 0; index < GB_QUANTITY; index++)
  5057. {
  5058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5059. {
  5060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5061. }
  5062. }// END for GB_QUANTITY
  5063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5064. }
  5065. else if(gunType[gun_index] == GUN_TYPE_DO)
  5066. {
  5067. tempIndex = gun_index;
  5068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5073. }
  5074. }
  5075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5076. }
  5077. else
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5080. {
  5081. tempIndex = 2;
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < AC_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5092. }
  5093. } // END for AC_QUANTITY
  5094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5095. }
  5096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5101. }
  5102. //============================ Voltage L1 ====================================
  5103. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5104. {
  5105. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5106. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5107. {
  5108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5109. {
  5110. tempIndex = ((gun_index==2) ? 1: 0);
  5111. }
  5112. else
  5113. {
  5114. tempIndex = gun_index;
  5115. }
  5116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5117. {
  5118. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5119. {
  5120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5121. }
  5122. } // END OF FOR CHAdeMO_QUANTITY
  5123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5124. }
  5125. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5126. {
  5127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5128. {
  5129. tempIndex = ((gun_index==2) ? 1: 0);
  5130. }
  5131. else
  5132. {
  5133. tempIndex = gun_index;
  5134. }
  5135. for (int index = 0; index < CCS_QUANTITY; index++)
  5136. {
  5137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5138. {
  5139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5140. }
  5141. } // END OF FOR CCS_QUANTITY
  5142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5143. }
  5144. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5145. {
  5146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5147. {
  5148. tempIndex = ((gun_index==2) ? 1: 0);
  5149. }
  5150. else
  5151. {
  5152. tempIndex = gun_index;
  5153. }
  5154. for (int index = 0; index < GB_QUANTITY; index++)
  5155. {
  5156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5157. {
  5158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5159. }
  5160. } // END OF FOR GB_QUANTITY
  5161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5162. }
  5163. else if(gunType[gun_index] == GUN_TYPE_DO)
  5164. {
  5165. tempIndex = gun_index;
  5166. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5167. {
  5168. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5169. {
  5170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5171. }
  5172. }
  5173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5174. }
  5175. else
  5176. {
  5177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5178. {
  5179. tempIndex = 2;
  5180. }
  5181. else
  5182. {
  5183. tempIndex = gun_index;
  5184. }
  5185. for (int index = 0; index < AC_QUANTITY; index++)
  5186. {
  5187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5188. {
  5189. 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
  5190. }
  5191. } // END OF FOR AC_QUANTITY
  5192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5193. }
  5194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5199. }
  5200. //====================== End SoC ================================
  5201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5202. {
  5203. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5204. 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))
  5205. {
  5206. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5207. {
  5208. tempIndex = ((gun_index==2) ? 1: 0);
  5209. }
  5210. else
  5211. {
  5212. tempIndex = gun_index;
  5213. }
  5214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5215. {
  5216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5219. {
  5220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5221. }
  5222. }
  5223. }
  5224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5225. {
  5226. for (int index = 0; index < CCS_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5229. {
  5230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5231. }
  5232. }
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5235. {
  5236. for (int index = 0; index < GB_QUANTITY; index++)
  5237. {
  5238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5239. {
  5240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5241. }
  5242. }
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5249. {
  5250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5251. }
  5252. }
  5253. }
  5254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5260. } // END FOR DC CASE
  5261. }
  5262. // ================================= Current.Import L2 ===============================================
  5263. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5264. {
  5265. // AC 3 phse L2 current
  5266. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5269. {
  5270. tempIndex = 2;
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < AC_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5281. }
  5282. }// End of for AC_QUANTITY
  5283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5284. }
  5285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5290. }
  5291. // ================================= Current.Import L3 ===============================================
  5292. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5293. {
  5294. // AC 3 phse L3 current
  5295. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5296. {
  5297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5298. {
  5299. tempIndex = 2;
  5300. }
  5301. else
  5302. {
  5303. tempIndex = gun_index;
  5304. }
  5305. for (int index = 0; index < AC_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5308. {
  5309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5310. }
  5311. }// End of for AC_QUANTITY
  5312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5313. }
  5314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5319. }
  5320. //============================ Voltage L2 ====================================
  5321. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5322. {
  5323. // AC 3 phse L2 voltage
  5324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5325. {
  5326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5327. {
  5328. tempIndex = 2;
  5329. }
  5330. else
  5331. {
  5332. tempIndex = gun_index;
  5333. }
  5334. for (int index = 0; index < AC_QUANTITY; index++)
  5335. {
  5336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5337. {
  5338. 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
  5339. }
  5340. } // END OF FOR AC_QUANTITY
  5341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5342. }
  5343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5348. }
  5349. //============================ Voltage L3 ====================================
  5350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5351. {
  5352. // AC 3 phse L3 voltage
  5353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5354. {
  5355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5356. {
  5357. tempIndex = 2;
  5358. }
  5359. else
  5360. {
  5361. tempIndex = gun_index;
  5362. }
  5363. for (int index = 0; index < AC_QUANTITY; index++)
  5364. {
  5365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5366. {
  5367. 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
  5368. }
  5369. } // END OF FOR AC_QUANTITY
  5370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5371. }
  5372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5377. }
  5378. //====================== Start SoC ================================
  5379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5380. {
  5381. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5382. 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))
  5383. {
  5384. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5385. {
  5386. tempIndex = ((gun_index==2) ? 1: 0);
  5387. }
  5388. else
  5389. {
  5390. tempIndex = gun_index;
  5391. }
  5392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5393. {
  5394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5395. {
  5396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5397. {
  5398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5399. }
  5400. }
  5401. }
  5402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5403. {
  5404. for (int index = 0; index < CCS_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5407. {
  5408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5409. }
  5410. }
  5411. }
  5412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5413. {
  5414. for (int index = 0; index < GB_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5419. }
  5420. }
  5421. }
  5422. else if(gunType[gun_index] == GUN_TYPE_DO)
  5423. {
  5424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5425. {
  5426. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5427. {
  5428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5429. }
  5430. }
  5431. }
  5432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5438. } // END FOR DC CASE
  5439. }
  5440. //================================================ Message create ====================================================
  5441. json_object *StopTransaction = json_object_new_object();
  5442. json_object *transactionDatas = json_object_new_array();
  5443. json_object *sampledValues = json_object_new_array();
  5444. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5445. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5446. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5447. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5448. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5449. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5450. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5451. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5452. {
  5453. json_object *transactionData = json_object_new_object();
  5454. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5455. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5456. {
  5457. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5458. {
  5459. json_object *sampledValue = json_object_new_object();
  5460. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5461. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5462. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5463. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5464. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5465. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5466. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5467. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5468. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5469. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5470. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5471. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5472. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5473. json_object_array_add(sampledValues, sampledValue);
  5474. }
  5475. }
  5476. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5477. json_object_array_add(transactionDatas, transactionData);
  5478. }
  5479. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5480. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5481. ,MESSAGE_TYPE_CALL
  5482. ,guid
  5483. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5484. json_object_put(StopTransaction);
  5485. #if 1 // for TempStopTransaction
  5486. //Delete TempStopTransaction
  5487. if((access(TempStopTransaction,F_OK))!=-1)
  5488. {
  5489. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5490. }
  5491. #endif
  5492. #if 1
  5493. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5494. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5495. {
  5496. result = PASS;
  5497. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5498. }
  5499. #endif
  5500. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5501. OCPP_insert_transaction_msg(NO, queuedata);
  5502. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5503. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5504. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5505. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5506. {
  5507. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5508. }
  5509. //for test
  5510. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5511. return result;
  5512. }
  5513. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5514. {
  5515. mtrace();
  5516. int result = FAIL;
  5517. char guid[37]={0};
  5518. char tempdata[65]={0};
  5519. int tempIndex = 0;
  5520. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5521. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5522. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5523. //set value
  5524. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5525. 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) )?
  5526. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5527. -1);
  5528. random_uuid(guid);
  5529. //UTC Date time
  5530. struct timeval tmnow;
  5531. struct tm *tm;
  5532. char buf[28];//, usec_buf[6];
  5533. gettimeofday(&tmnow, NULL);
  5534. time_t t;
  5535. t = time(NULL);
  5536. /*UTC time and date*/
  5537. tm = gmtime(&t);
  5538. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5540. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5541. //********************************(1)Current.Import L1************************************************/
  5542. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5543. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5544. (dataType == ReadingContext_Trigger))
  5545. {
  5546. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5547. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5548. {
  5549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5550. {
  5551. tempIndex = ((gun_index==2) ? 1: 0);
  5552. }
  5553. else
  5554. {
  5555. tempIndex = gun_index;
  5556. }
  5557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5562. }
  5563. }
  5564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5565. }
  5566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5569. {
  5570. tempIndex = ((gun_index==2) ? 1: 0);
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < CCS_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5581. }
  5582. }
  5583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5584. }
  5585. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5586. {
  5587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5588. {
  5589. tempIndex = ((gun_index==2) ? 1: 0);
  5590. }
  5591. else
  5592. {
  5593. tempIndex = gun_index;
  5594. }
  5595. for (int index = 0; index < GB_QUANTITY; index++)
  5596. {
  5597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5598. {
  5599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5600. }
  5601. }
  5602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5603. }
  5604. else if(gunType[gun_index] == GUN_TYPE_DO)
  5605. {
  5606. tempIndex = gun_index;
  5607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5608. {
  5609. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5610. {
  5611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5612. }
  5613. }
  5614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5615. }
  5616. else
  5617. {
  5618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5619. {
  5620. tempIndex = 2;
  5621. }
  5622. else
  5623. {
  5624. tempIndex = gun_index;
  5625. }
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5629. {
  5630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5631. }
  5632. }
  5633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5634. }
  5635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5640. }
  5641. //********************************(2)Energy.Active.Import.Register ************************************************/
  5642. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5643. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5644. (dataType == ReadingContext_Trigger))
  5645. {
  5646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5647. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5648. {
  5649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5650. {
  5651. tempIndex = ((gun_index==2) ? 1: 0);
  5652. }
  5653. else
  5654. {
  5655. tempIndex = gun_index;
  5656. }
  5657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5658. {
  5659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5660. {
  5661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5662. }
  5663. }
  5664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5665. }
  5666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5667. {
  5668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5669. {
  5670. tempIndex = ((gun_index==2) ? 1: 0);
  5671. }
  5672. else
  5673. {
  5674. tempIndex = gun_index;
  5675. }
  5676. for (int index = 0; index < CCS_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5686. {
  5687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5688. {
  5689. tempIndex = ((gun_index==2) ? 1: 0);
  5690. }
  5691. else
  5692. {
  5693. tempIndex = gun_index;
  5694. }
  5695. for (int index = 0; index < GB_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5700. }
  5701. }
  5702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5703. }
  5704. else if(gunType[gun_index] == GUN_TYPE_DO)
  5705. {
  5706. tempIndex = gun_index;
  5707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5712. }
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5715. }
  5716. else
  5717. {
  5718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5719. {
  5720. tempIndex = 2;
  5721. }
  5722. else
  5723. {
  5724. tempIndex = gun_index;
  5725. }
  5726. for (int index = 0; index < AC_QUANTITY; index++)
  5727. {
  5728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5729. {
  5730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5731. }
  5732. }
  5733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5734. }
  5735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5740. }
  5741. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5742. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5743. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5744. (dataType == ReadingContext_Trigger))
  5745. {
  5746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5747. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5762. }
  5763. } // END OF FOR CHAdeMO_QUANTITY
  5764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5767. {
  5768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5769. {
  5770. tempIndex = ((gun_index==2) ? 1: 0);
  5771. }
  5772. else
  5773. {
  5774. tempIndex = gun_index;
  5775. }
  5776. for (int index = 0; index < CCS_QUANTITY; index++)
  5777. {
  5778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5779. {
  5780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5781. }
  5782. } // END OF CCS_QUANTITY
  5783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5784. }
  5785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5786. {
  5787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5788. {
  5789. tempIndex = ((gun_index==2) ? 1: 0);
  5790. }
  5791. else
  5792. {
  5793. tempIndex = gun_index;
  5794. }
  5795. for (int index = 0; index < GB_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5798. {
  5799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5800. }
  5801. } // END OF GB_QUANTITY
  5802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5803. }
  5804. else if(gunType[gun_index] == GUN_TYPE_DO)
  5805. {
  5806. tempIndex = gun_index;
  5807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5810. {
  5811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5812. }
  5813. }
  5814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5815. }
  5816. else
  5817. {
  5818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5819. {
  5820. tempIndex = 2;
  5821. }
  5822. else
  5823. {
  5824. tempIndex = gun_index;
  5825. }
  5826. for (int index = 0; index < AC_QUANTITY; index++)
  5827. {
  5828. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5829. {
  5830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5831. }
  5832. }
  5833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5834. }
  5835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5840. }
  5841. //********************************(4)Power.Active.Import************************************************/
  5842. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5843. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5844. (dataType == ReadingContext_Trigger))
  5845. {
  5846. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5847. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5848. {
  5849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5850. {
  5851. tempIndex = ((gun_index==2) ? 1: 0);
  5852. }
  5853. else
  5854. {
  5855. tempIndex = gun_index;
  5856. }
  5857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5862. }
  5863. } // END OF FOR
  5864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5865. }
  5866. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5869. {
  5870. tempIndex = ((gun_index==2) ? 1: 0);
  5871. }
  5872. else
  5873. {
  5874. tempIndex = gun_index;
  5875. }
  5876. for (int index = 0; index < CCS_QUANTITY; index++)
  5877. {
  5878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5879. {
  5880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5881. }
  5882. }
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5884. }
  5885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5886. {
  5887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5888. {
  5889. tempIndex = ((gun_index==2) ? 1: 0);
  5890. }
  5891. else
  5892. {
  5893. tempIndex = gun_index;
  5894. }
  5895. for (int index = 0; index < GB_QUANTITY; index++)
  5896. {
  5897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5898. {
  5899. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5901. }
  5902. }
  5903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5904. }
  5905. else if(gunType[gun_index] == GUN_TYPE_DO)
  5906. {
  5907. tempIndex = gun_index;
  5908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5909. {
  5910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5911. {
  5912. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5917. }
  5918. else
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5921. {
  5922. tempIndex = 2;
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < AC_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5933. }
  5934. }
  5935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5936. }
  5937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5942. }
  5943. //***********************************************(5)VOLTAGE L1******************************************************/
  5944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5946. (dataType == ReadingContext_Trigger))
  5947. {
  5948. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5971. {
  5972. tempIndex = ((gun_index==2) ? 1: 0);
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < CCS_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5990. {
  5991. tempIndex = ((gun_index==2) ? 1: 0);
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < GB_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6002. }
  6003. }
  6004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6005. }
  6006. else if(gunType[gun_index] == GUN_TYPE_DO)
  6007. {
  6008. tempIndex = gun_index;
  6009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6017. }
  6018. else
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6021. {
  6022. tempIndex = 2;
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < AC_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6031. {
  6032. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6033. }
  6034. }
  6035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6036. }
  6037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6042. }
  6043. //***********************************************(6)SOC******************************************************/
  6044. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  6045. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  6046. (dataType == ReadingContext_Trigger))
  6047. {
  6048. 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))
  6049. {
  6050. //idx_sample=5;
  6051. //sampledValue = NULL;
  6052. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6053. {
  6054. tempIndex = ((gun_index==2) ? 1: 0);
  6055. }
  6056. else
  6057. {
  6058. tempIndex = gun_index;
  6059. }
  6060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6061. {
  6062. //tempIndex = ((gun_index==2) ? 1: 0);
  6063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6064. {
  6065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6066. {
  6067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6068. }
  6069. }
  6070. }
  6071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6072. {
  6073. //tempIndex = ((gun_index==2) ? 1: 0);
  6074. for (int index = 0; index < CCS_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6079. }
  6080. }
  6081. }
  6082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6083. {
  6084. //tempIndex = ((gun_index==2) ? 1: 0);
  6085. for (int index = 0; index < GB_QUANTITY; index++)
  6086. {
  6087. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6088. {
  6089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6090. }
  6091. }
  6092. }
  6093. else if(gunType[gun_index] == GUN_TYPE_DO)
  6094. {
  6095. //tempIndex = ((gun_index==2) ? 1: 0);
  6096. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6099. {
  6100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6101. }
  6102. }
  6103. }
  6104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6110. }
  6111. }
  6112. //********************************(7)Current.Import L2************************************************/
  6113. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6114. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6115. (dataType == ReadingContext_Trigger))
  6116. {
  6117. // Only for AC 3 phase
  6118. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6119. {
  6120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6121. {
  6122. tempIndex = 2;
  6123. }
  6124. else
  6125. {
  6126. tempIndex = gun_index;
  6127. }
  6128. for (int index = 0; index < AC_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6131. {
  6132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6133. }
  6134. }
  6135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6136. }
  6137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6142. }
  6143. //********************************(8)Current.Import L3************************************************/
  6144. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6145. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6146. (dataType == ReadingContext_Trigger))
  6147. {
  6148. // Only for AC 3 phase
  6149. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6152. {
  6153. tempIndex = 2;
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < AC_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6164. }
  6165. }
  6166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6167. }
  6168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6173. }
  6174. //***********************************************(9)VOLTAGE L2******************************************************/
  6175. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6176. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6177. (dataType == ReadingContext_Trigger))
  6178. {
  6179. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6180. {
  6181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6182. {
  6183. tempIndex = 2;
  6184. }
  6185. else
  6186. {
  6187. tempIndex = gun_index;
  6188. }
  6189. for (int index = 0; index < AC_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6192. {
  6193. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6194. }
  6195. }
  6196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6197. }
  6198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6203. }
  6204. //***********************************************(10)VOLTAGE L3******************************************************/
  6205. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6206. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6207. (dataType == ReadingContext_Trigger))
  6208. {
  6209. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6210. {
  6211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6212. {
  6213. tempIndex = 2;
  6214. }
  6215. else
  6216. {
  6217. tempIndex = gun_index;
  6218. }
  6219. for (int index = 0; index < AC_QUANTITY; index++)
  6220. {
  6221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6222. {
  6223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6224. }
  6225. }
  6226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6227. }
  6228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6233. }
  6234. // Message create ====================================================================================================
  6235. if(TRUE)
  6236. {
  6237. json_object *MeterValueReq = json_object_new_object();
  6238. json_object *MeterValues = json_object_new_array();
  6239. json_object *sampledValues = json_object_new_array();
  6240. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6241. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6242. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6243. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6244. {
  6245. json_object *MeterValue = json_object_new_object();
  6246. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6247. {
  6248. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6249. {
  6250. json_object *sampledValue = json_object_new_object();
  6251. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6252. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6253. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6254. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6255. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6256. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6257. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6258. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6259. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6260. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6261. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6262. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6263. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6264. json_object_array_add(sampledValues, sampledValue);
  6265. }
  6266. }
  6267. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6268. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6269. json_object_array_add(MeterValues, MeterValue);
  6270. }
  6271. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6272. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6273. ,gun_index + 1
  6274. ,MESSAGE_TYPE_CALL
  6275. ,guid
  6276. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6277. json_object_put(MeterValueReq);
  6278. }
  6279. // Put request guid to hash map
  6280. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6281. 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*/)
  6282. {
  6283. result = PASS;
  6284. //DEBUG_INFO("MeterValues mapitem pass\n");
  6285. }
  6286. if((dataType != ReadingContext_Trigger) &&
  6287. (dataType != ReadingContext_Sample_Clock) &&
  6288. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6289. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6290. else
  6291. {
  6292. if(FirstHeartBeat)
  6293. LWS_Send(queuedata +2);
  6294. }
  6295. return result;
  6296. }
  6297. int sendLogStatusNotificationRequest(char *status)
  6298. {
  6299. mtrace();
  6300. int result = PASS;
  6301. char message[4096]={0};
  6302. char guid[37]={0};
  6303. char tempdata[128]={0};
  6304. json_object *LogStatusNotification = json_object_new_object();
  6305. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6306. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6307. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6308. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6309. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6310. random_uuid(guid);
  6311. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6312. json_object_put(LogStatusNotification);
  6313. LWS_Send(message);
  6314. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6315. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6316. {
  6317. result = PASS;
  6318. }
  6319. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6320. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6321. return result;
  6322. }
  6323. int sendSecurityEventNotificationRequest()
  6324. {
  6325. mtrace();
  6326. int result = PASS;
  6327. char message[4096]={0};
  6328. char guid[37]={0};
  6329. char tempdata[128]={0};
  6330. json_object *SecurityEventNotification = json_object_new_object();
  6331. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6332. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6333. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6334. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6335. random_uuid(guid);
  6336. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6337. json_object_put(SecurityEventNotification);
  6338. LWS_Send(message);
  6339. sprintf(tempdata, "SecurityEventNotification,0");
  6340. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6341. {
  6342. result = PASS;
  6343. }
  6344. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6345. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6346. return result;
  6347. }
  6348. int sendSignCertificateRequest()
  6349. {
  6350. mtrace();
  6351. int result = PASS;
  6352. char message[4096]={0};
  6353. char guid[37]={0};
  6354. char tempdata[128]={0};
  6355. json_object *SignCertificate = json_object_new_object();
  6356. DEBUG_INFO("sendSignCertificateRequest...\n");
  6357. // Read csr file content
  6358. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6359. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6360. char *line = NULL;
  6361. size_t len = 0;
  6362. while(getline(&line, &len, fp) != -1)
  6363. {
  6364. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6365. {
  6366. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6367. }
  6368. }
  6369. fclose(fp);
  6370. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6371. random_uuid(guid);
  6372. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6373. json_object_put(SignCertificate);
  6374. LWS_Send(message);
  6375. sprintf(tempdata, "SignCertificate,0");
  6376. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6377. {
  6378. result = PASS;
  6379. }
  6380. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6381. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6382. return result;
  6383. }
  6384. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6385. {
  6386. mtrace();
  6387. int result = PASS;
  6388. char message[110]={0};
  6389. char guid[37]={0};
  6390. char tempdata[65]={0};
  6391. json_object *FirmwareStatusNotification = json_object_new_object();
  6392. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6393. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6394. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6395. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6396. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6397. random_uuid(guid);
  6398. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6399. json_object_put(FirmwareStatusNotification);
  6400. LWS_Send(message);
  6401. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6402. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6403. {
  6404. result = PASS;
  6405. }
  6406. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6407. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6408. return result;
  6409. }
  6410. //==========================================
  6411. // send confirm routine
  6412. //==========================================
  6413. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6414. {
  6415. mtrace();
  6416. int result = FAIL;
  6417. char message[100]={0};
  6418. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6419. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6420. LWS_Send(message);
  6421. result = TRUE;
  6422. return result;
  6423. }
  6424. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6425. {
  6426. mtrace();
  6427. int result = FAIL;
  6428. char message[100]={0};
  6429. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6430. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6431. LWS_Send(message);
  6432. result = TRUE;
  6433. return result;
  6434. }
  6435. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6436. {
  6437. mtrace();
  6438. int result = FAIL;
  6439. char message[100]={0};
  6440. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6441. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6442. LWS_Send(message);
  6443. result = TRUE;
  6444. return result;
  6445. }
  6446. int sendClearCacheConfirmation(char *uuid,char *payload)
  6447. {
  6448. mtrace();
  6449. int result = FAIL;
  6450. char message[500]={0};
  6451. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6452. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6453. LWS_Send(message);
  6454. return result;
  6455. }
  6456. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6457. {
  6458. mtrace();
  6459. int result = FAIL;
  6460. char message[500]={0};
  6461. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6462. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6463. LWS_Send(message);
  6464. return result;
  6465. }
  6466. int sendDataTransferConfirmation(char *uuid,char *payload)
  6467. {
  6468. mtrace();
  6469. char statusStr[20]={0};
  6470. char dataStr[10]={0};
  6471. char sstr[20]={0};
  6472. int c = 0;
  6473. char *loc;
  6474. int result = FAIL;
  6475. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6476. /**********************status**************************/
  6477. loc = strstr(payload, "status");
  6478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6479. c = 0;
  6480. while (loc[3+strlen("status")+c] != '\"')
  6481. {
  6482. sstr[c] = loc[3+strlen("status")+c];
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. strcpy(statusStr, sstr);
  6487. /**********************data**************************/
  6488. loc = strstr(payload, "data");
  6489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6490. c = 0;
  6491. while (loc[3+strlen("data")+c] != '\"')
  6492. {
  6493. sstr[c] = loc[3+strlen("data")+c];
  6494. c++;
  6495. }
  6496. sstr[c] = '\0';
  6497. strcpy(dataStr, sstr);
  6498. return result;
  6499. }
  6500. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6501. {
  6502. mtrace();
  6503. int result = FAIL;
  6504. char message[1000]={0};
  6505. int CompositeScheduleIndex = 0;
  6506. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6507. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6508. if(nPeriod == 0)
  6509. {
  6510. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6511. {
  6512. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6513. ,MESSAGE_TYPE_CALLRESULT
  6514. ,uuid
  6515. ,payload
  6516. ,connectorIdInt);
  6517. }
  6518. else
  6519. {
  6520. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6521. ,MESSAGE_TYPE_CALLRESULT
  6522. ,uuid
  6523. ,payload
  6524. ,connectorIdInt
  6525. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6526. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6527. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6528. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6529. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6530. }
  6531. }
  6532. else
  6533. {
  6534. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6535. ,MESSAGE_TYPE_CALLRESULT
  6536. ,uuid
  6537. ,payload
  6538. ,connectorIdInt
  6539. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6540. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6541. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6542. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6543. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6544. {
  6545. if (idx_sample == 0)
  6546. {
  6547. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6548. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6549. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6551. }
  6552. else
  6553. {
  6554. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6555. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6556. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6557. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6558. }
  6559. }
  6560. sprintf(message + strlen(message), "]}}]");
  6561. }
  6562. LWS_Send(message);
  6563. result = TRUE;
  6564. return result;
  6565. }
  6566. int sendGetConfigurationConfirmation(char *uuid)
  6567. {
  6568. mtrace();
  6569. int result = FAIL;
  6570. int MaxKeySupported = 0;
  6571. int sentConfigurationNumber= 0;
  6572. int sentunConfigurationNumber= 0;
  6573. char message[4000]={0};
  6574. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6575. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6576. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6577. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6578. ,MESSAGE_TYPE_CALLRESULT
  6579. ,uuid );
  6580. //configuration key
  6581. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6582. {
  6583. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6584. {
  6585. if (sentConfigurationNumber == 0)
  6586. {
  6587. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6588. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6589. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6590. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6591. }
  6592. else
  6593. {
  6594. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6595. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6596. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6597. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6598. }
  6599. sentConfigurationNumber = sentConfigurationNumber + 1;
  6600. }
  6601. }
  6602. sprintf(message + strlen(message), "]");
  6603. if(UnknownKeynum != 0)
  6604. {
  6605. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6606. //unkown key
  6607. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6608. {
  6609. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6610. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6611. if(sentunConfigurationNumber == 0)
  6612. {
  6613. sprintf(message + strlen(message), "\"%s\""
  6614. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6615. }
  6616. else
  6617. {
  6618. sprintf(message + strlen(message), ",\"%s\""
  6619. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6620. }
  6621. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6622. }
  6623. sprintf(message + strlen(message), "]");
  6624. }
  6625. sprintf(message + strlen(message), "}]");
  6626. LWS_Send(message);
  6627. return result;
  6628. }
  6629. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6630. {
  6631. mtrace();
  6632. int result = FAIL;
  6633. char message[400]={0};
  6634. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6635. if(strcmp(payload,"")==0)
  6636. {
  6637. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6638. }
  6639. else
  6640. {
  6641. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6642. }
  6643. LWS_Send(message);
  6644. result = TRUE;
  6645. return result;
  6646. }
  6647. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6648. {
  6649. mtrace();
  6650. int result = FAIL;
  6651. char message[80]={0};
  6652. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6653. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6654. LWS_Send(message);
  6655. result = TRUE;
  6656. return result;
  6657. }
  6658. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6659. {
  6660. mtrace();
  6661. int result = FAIL;
  6662. char message[80]={0};
  6663. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6664. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6665. LWS_Send(message);
  6666. result = TRUE;
  6667. return result;
  6668. }
  6669. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6670. {
  6671. mtrace();
  6672. int result = FAIL;
  6673. char message[80]={0};
  6674. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6675. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6676. LWS_Send(message);
  6677. result = TRUE;
  6678. return result;
  6679. }
  6680. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6681. {
  6682. mtrace();
  6683. int result = FAIL;
  6684. char message[80]={0};
  6685. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6686. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6687. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6688. LWS_Send(message);
  6689. result = TRUE;
  6690. return result;
  6691. }
  6692. int sendResetConfirmation(char *uuid,char *payload)
  6693. {
  6694. mtrace();
  6695. int result = FAIL;
  6696. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6697. char message[80]={0};
  6698. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6700. LWS_Send(message);
  6701. result = TRUE;
  6702. return result;
  6703. }
  6704. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6705. {
  6706. mtrace();
  6707. int result = FAIL;
  6708. char message[500]={0};
  6709. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6710. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6711. LWS_Send(message);
  6712. result = TRUE;
  6713. return result;
  6714. }
  6715. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6716. {
  6717. mtrace();
  6718. int result = FAIL;
  6719. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6720. char message[80]={0};
  6721. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6723. LWS_Send(message);
  6724. result = TRUE;
  6725. return result;
  6726. }
  6727. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. char message[80]={0};
  6732. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6734. LWS_Send(message);
  6735. result = TRUE;
  6736. return result;
  6737. }
  6738. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6739. {
  6740. mtrace();
  6741. int result = FAIL;
  6742. char message[80]={0};
  6743. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6744. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6745. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6746. LWS_Send(message);
  6747. result = TRUE;
  6748. return result;
  6749. }
  6750. int sendUpdateFirmwareConfirmation(char *uuid)
  6751. {
  6752. mtrace();
  6753. int result = FAIL;
  6754. char message[60]={0};
  6755. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6756. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6757. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6758. LWS_Send(message);
  6759. result = TRUE;
  6760. return result;
  6761. }
  6762. int sendCertificateSignedConfirmation(char *uuid)
  6763. {
  6764. mtrace();
  6765. int result = PASS;
  6766. char message[4096]={0};
  6767. json_object *CertificateSigned = json_object_new_object();
  6768. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6769. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6770. sprintf(message,"[%d,\"%s\",%s]"
  6771. ,MESSAGE_TYPE_CALLRESULT
  6772. ,uuid
  6773. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6774. json_object_put(CertificateSigned);
  6775. LWS_Send(message);
  6776. return result;
  6777. }
  6778. int sendDeleteCertificateConfirmation(char *uuid)
  6779. {
  6780. mtrace();
  6781. int result = PASS;
  6782. char message[4096]={0};
  6783. json_object *DeleteCertificate = json_object_new_object();
  6784. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6785. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6786. sprintf(message,"[%d,\"%s\",%s]"
  6787. ,MESSAGE_TYPE_CALLRESULT
  6788. ,uuid
  6789. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6790. json_object_put(DeleteCertificate);
  6791. LWS_Send(message);
  6792. return result;
  6793. }
  6794. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6795. {
  6796. mtrace();
  6797. int result = PASS;
  6798. char message[4096]={0};
  6799. json_object *ExtendedTriggerMessage = json_object_new_object();
  6800. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6801. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6802. sprintf(message,"[%d,\"%s\",%s]"
  6803. ,MESSAGE_TYPE_CALLRESULT
  6804. ,uuid
  6805. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6806. json_object_put(ExtendedTriggerMessage);
  6807. LWS_Send(message);
  6808. return result;
  6809. }
  6810. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6811. {
  6812. mtrace();
  6813. int result = PASS;
  6814. char message[4096]={0};
  6815. json_object *GetInstalledCertificateIds = json_object_new_object();
  6816. json_object *certificateHashDataDatas = json_object_new_array();
  6817. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6818. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6819. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6820. {
  6821. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6822. {
  6823. json_object *certificateHashData = json_object_new_object();
  6824. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6825. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6826. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6827. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6828. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6829. }
  6830. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6831. }
  6832. else
  6833. {
  6834. json_object_put(certificateHashDataDatas);
  6835. }
  6836. sprintf(message,"[%d,\"%s\",%s]"
  6837. ,MESSAGE_TYPE_CALLRESULT
  6838. ,uuid
  6839. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6840. json_object_put(GetInstalledCertificateIds);
  6841. LWS_Send(message);
  6842. return result;
  6843. }
  6844. int sendGetLogConfirmation(char *uuid)
  6845. {
  6846. mtrace();
  6847. int result = PASS;
  6848. char message[4096]={0};
  6849. json_object *GetLog = json_object_new_object();
  6850. DEBUG_INFO("sendGetLogConfirmation...\n");
  6851. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6852. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6853. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6854. sprintf(message,"[%d,\"%s\",%s]"
  6855. ,MESSAGE_TYPE_CALLRESULT
  6856. ,uuid
  6857. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6858. json_object_put(GetLog);
  6859. LWS_Send(message);
  6860. return result;
  6861. }
  6862. int sendInstallCertificateConfirmation(char *uuid)
  6863. {
  6864. mtrace();
  6865. int result = PASS;
  6866. char message[4096]={0};
  6867. json_object *InstallCertificate = json_object_new_object();
  6868. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6869. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6870. sprintf(message,"[%d,\"%s\",%s]"
  6871. ,MESSAGE_TYPE_CALLRESULT
  6872. ,uuid
  6873. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6874. json_object_put(InstallCertificate);
  6875. LWS_Send(message);
  6876. return result;
  6877. }
  6878. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6879. {
  6880. mtrace();
  6881. int result = PASS;
  6882. char message[4096]={0};
  6883. json_object *SignedUpdateFirmware = json_object_new_object();
  6884. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6885. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6886. sprintf(message,"[%d,\"%s\",%s]"
  6887. ,MESSAGE_TYPE_CALLRESULT
  6888. ,uuid
  6889. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6890. json_object_put(SignedUpdateFirmware);
  6891. LWS_Send(message);
  6892. return result;
  6893. }
  6894. int sendUnknownConfirmation(char *uuid)
  6895. {
  6896. mtrace();
  6897. int result = PASS;
  6898. char message[256]={0};
  6899. DEBUG_INFO("sendUnknownConfirmation...\n");
  6900. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6901. LWS_Send(message);
  6902. return result;
  6903. }
  6904. //==========================================
  6905. // Handle server request routine Start
  6906. //==========================================
  6907. int handleCancelReservationRequest(char *uuid, char *payload)
  6908. {
  6909. mtrace();
  6910. int result = FAIL;
  6911. int gunNO = 0;
  6912. int reservationIdInt = -1;
  6913. char comfirmstr[20];
  6914. DEBUG_INFO("handleCancelReservationRequest...\n");
  6915. json_object *CancelReservation;
  6916. CancelReservation = json_tokener_parse(payload);
  6917. if(!is_error(CancelReservation))
  6918. {
  6919. // Required data
  6920. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6921. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6922. }
  6923. json_object_put(CancelReservation);
  6924. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6925. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6926. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6927. if(reservationIdInt != -1)
  6928. {
  6929. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6930. //check Transaction active
  6931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6935. {
  6936. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6937. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6938. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6939. {
  6940. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6941. }
  6942. else
  6943. {
  6944. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6945. }
  6946. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6947. goto end;
  6948. }
  6949. }
  6950. for (int index = 0; index < CCS_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6953. {
  6954. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6955. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6956. if(gunType[2] == GUN_TYPE_CCS)
  6957. {
  6958. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6959. }
  6960. else
  6961. {
  6962. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6963. }
  6964. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6965. goto end;
  6966. }
  6967. }
  6968. for (int index = 0; index < GB_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6971. {
  6972. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6973. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6974. if(gunType[2] == GUN_TYPE_GBT)
  6975. {
  6976. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6977. }
  6978. else
  6979. {
  6980. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6981. }
  6982. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6983. goto end;
  6984. }
  6985. }
  6986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6987. {
  6988. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6989. {
  6990. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6991. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6992. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6993. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6994. goto end;
  6995. }
  6996. }
  6997. for (int index = 0; index < AC_QUANTITY; index++)
  6998. {
  6999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7000. {
  7001. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7002. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7004. {
  7005. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7006. }
  7007. else
  7008. {
  7009. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7010. }
  7011. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7012. goto end;
  7013. }
  7014. }
  7015. }
  7016. //The reservationId does NOT match the reservationId
  7017. sendCancelReservationConfirmation(uuid, comfirmstr);
  7018. end:
  7019. // Fill in ocpp packet uuid
  7020. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7021. return result;
  7022. }
  7023. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7024. {
  7025. mtrace();
  7026. int result = FAIL;
  7027. int gunIndex = 0;
  7028. char typeStr[16]={0};
  7029. char comfirmstr[20];
  7030. int specificId = FALSE;
  7031. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7032. json_object *ChangeAvailability;
  7033. ChangeAvailability = json_tokener_parse(payload);
  7034. if(!is_error(ChangeAvailability))
  7035. {
  7036. // Required data
  7037. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7038. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7039. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7040. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7041. }
  7042. json_object_put(ChangeAvailability);
  7043. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7044. {
  7045. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7046. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7047. }
  7048. else if(gunIndex == 0)
  7049. {
  7050. for(int i=0; i < gunTotalNumber; i++)
  7051. {
  7052. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7053. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7054. }
  7055. }
  7056. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7058. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7059. {
  7060. specificId = TRUE;
  7061. }
  7062. if(specificId == FALSE)
  7063. goto end;
  7064. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7065. {
  7066. //----------------------gunIndex is 0 ------------------------------------------------//
  7067. if(gunIndex == 0)
  7068. {
  7069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7070. {
  7071. for(int i=0; i < gunTotalNumber; i++)
  7072. {
  7073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7074. {
  7075. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7076. {
  7077. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7078. {
  7079. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7080. goto end;
  7081. }
  7082. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7083. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7087. {
  7088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7089. goto end;
  7090. }
  7091. }
  7092. }//END FOR CHAdeMO_QUANTITY
  7093. for (int index = 0; index < CCS_QUANTITY; index++)
  7094. {
  7095. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7096. {
  7097. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7098. {
  7099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7100. goto end;
  7101. }
  7102. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7103. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7104. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7105. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7106. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7107. {
  7108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7109. goto end;
  7110. }
  7111. }
  7112. }//END FOR CCS_QUANTITY
  7113. for (int index = 0; index < GB_QUANTITY; index++)
  7114. {
  7115. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7116. {
  7117. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7118. {
  7119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7120. goto end;
  7121. }
  7122. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7123. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7124. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7125. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7126. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7127. {
  7128. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7129. goto end;
  7130. }
  7131. }
  7132. }// END FOR GB_QUANTITY
  7133. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7134. {
  7135. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7136. {
  7137. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7138. {
  7139. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7140. goto end;
  7141. }
  7142. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7143. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7144. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7145. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7146. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7147. {
  7148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7149. goto end;
  7150. }
  7151. }
  7152. }// END FOR GENERAL_GUN_QUANTITY
  7153. for (int index = 0; index < AC_QUANTITY; index++)
  7154. {
  7155. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7156. {
  7157. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7158. {
  7159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7160. goto end;
  7161. }
  7162. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7163. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7164. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7165. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7167. {
  7168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7169. goto end;
  7170. }
  7171. }
  7172. }//END FOR AC_QUANTITY
  7173. }// END FOR gunTotalNumber
  7174. }
  7175. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7176. {
  7177. for(int i=0; i < gunTotalNumber; i++)
  7178. {
  7179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7180. {
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7182. goto end;
  7183. }
  7184. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7185. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7186. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7189. {
  7190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7191. goto end;
  7192. }
  7193. }
  7194. }
  7195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7196. goto end;
  7197. }
  7198. //----------------------gunIndex is not 0 ------------------------------------------------//
  7199. //check Transaction active
  7200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7201. {
  7202. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7203. {
  7204. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7205. {
  7206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7207. goto end;
  7208. }
  7209. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7210. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7211. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7212. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7213. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7214. {
  7215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7216. goto end;
  7217. }
  7218. else
  7219. {
  7220. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7222. goto end;
  7223. }
  7224. }
  7225. }//END FOR CHAdeMO_QUANTITY
  7226. for (int index = 0; index < CCS_QUANTITY; index++)
  7227. {
  7228. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7229. {
  7230. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7231. {
  7232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7233. goto end;
  7234. }
  7235. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7236. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7237. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7238. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7239. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7240. {
  7241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7242. goto end;
  7243. }
  7244. else
  7245. {
  7246. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7248. goto end;
  7249. }
  7250. }
  7251. }//END FOR CCS_QUANTITY
  7252. for (int index = 0; index < GB_QUANTITY; index++)
  7253. {
  7254. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7255. {
  7256. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7257. {
  7258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7259. goto end;
  7260. }
  7261. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7262. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7263. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7264. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7265. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7266. {
  7267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7268. goto end;
  7269. }
  7270. else
  7271. {
  7272. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7274. goto end;
  7275. }
  7276. }
  7277. }// END FOR GB_QUANTITY
  7278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7279. {
  7280. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7281. {
  7282. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7283. {
  7284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7285. goto end;
  7286. }
  7287. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7288. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7289. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7290. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7292. {
  7293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7294. goto end;
  7295. }
  7296. else
  7297. {
  7298. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7300. goto end;
  7301. }
  7302. }
  7303. }// END FOR GENERAL_GUN_QUANTITY
  7304. for (int index = 0; index < AC_QUANTITY; index++)
  7305. {
  7306. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7307. {
  7308. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7309. {
  7310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7311. goto end;
  7312. }
  7313. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7314. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7315. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7316. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7317. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7318. {
  7319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7320. goto end;
  7321. }
  7322. else
  7323. {
  7324. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7326. goto end;
  7327. }
  7328. }
  7329. }//END FOR AC_QUANTITY
  7330. }//END FOR AvailabilityTypeStr[Inoperative]
  7331. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7332. {
  7333. //----------------------gunIndex is 0 ------------------------------------------------//
  7334. if(gunIndex == 0)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7337. {
  7338. for(int i=0; i < gunTotalNumber; i++)
  7339. {
  7340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7341. {
  7342. 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
  7343. {
  7344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7345. goto end;
  7346. }
  7347. }//END FOR CHAdeMO_QUANTITY
  7348. for (int index = 0; index < CCS_QUANTITY; index++)
  7349. {
  7350. 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
  7351. {
  7352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7353. goto end;
  7354. }
  7355. }//END FOR CCS_QUANTITY
  7356. for (int index = 0; index < GB_QUANTITY; index++)
  7357. {
  7358. 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
  7359. {
  7360. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7362. goto end;
  7363. }
  7364. }// END FOR GB_QUANTITY
  7365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7366. {
  7367. 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
  7368. {
  7369. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7371. goto end;
  7372. }
  7373. }// END FOR GENERAL_GUN_QUANTITY
  7374. for (int index = 0; index < AC_QUANTITY; index++)
  7375. {
  7376. 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
  7377. {
  7378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7379. goto end;
  7380. }
  7381. }//END FOR CHAdeMO_QUANTITY
  7382. }// END FOR gunTotalNumber
  7383. }
  7384. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7385. {
  7386. for(int i=0; i < gunTotalNumber; i++)
  7387. {
  7388. for (int index = 0; index < AC_QUANTITY; index++)
  7389. {
  7390. 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
  7391. {
  7392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7393. goto end;
  7394. }
  7395. }//END FOR CHAdeMO_QUANTITY
  7396. } // END FOR gunTotalNumber
  7397. }
  7398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7399. goto end;
  7400. }
  7401. //----------------------gunIndex is not 0 ------------------------------------------------//
  7402. //check Transaction active
  7403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7404. {
  7405. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7406. {
  7407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7408. goto end;
  7409. }
  7410. }//END FOR CHAdeMO_QUANTITY
  7411. for (int index = 0; index < CCS_QUANTITY; index++)
  7412. {
  7413. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7414. {
  7415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7416. goto end;
  7417. }
  7418. }//END FOR CCS_QUANTITY
  7419. for (int index = 0; index < GB_QUANTITY; index++)
  7420. {
  7421. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7422. {
  7423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7424. goto end;
  7425. }
  7426. }// END FOR GB_QUANTITY
  7427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7428. {
  7429. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7430. {
  7431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7432. goto end;
  7433. }
  7434. }// END FOR GENERAL_GUN_QUANTITY
  7435. for (int index = 0; index < AC_QUANTITY; index++)
  7436. {
  7437. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7438. {
  7439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7440. goto end;
  7441. }
  7442. }//END FOR AC_QUANTITY
  7443. }//END FOR AvailabilityTypeStr[Operative]
  7444. end:
  7445. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7446. {
  7447. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7448. }
  7449. else
  7450. {
  7451. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7452. }
  7453. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7454. {
  7455. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7456. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7457. }
  7458. else if(gunIndex == 0)
  7459. {
  7460. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7461. {
  7462. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7463. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7464. }
  7465. }
  7466. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7467. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7468. return result;
  7469. }
  7470. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7471. {
  7472. mtrace();
  7473. int result = FAIL;
  7474. char keystr[40]={0};
  7475. char valuestr[256]={0};
  7476. char comfirmstr[20]={0};
  7477. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7478. json_object *ChangeConfiguration;
  7479. ChangeConfiguration = json_tokener_parse(payload);
  7480. if(!is_error(ChangeConfiguration))
  7481. {
  7482. // Required data
  7483. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7484. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7485. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7486. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7487. }
  7488. json_object_put(ChangeConfiguration);
  7489. if((uuid==NULL) || (payload ==NULL) )
  7490. {
  7491. DEBUG_ERROR("Payload is null\n");
  7492. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7493. }
  7494. else
  7495. {
  7496. int status = setKeyValue(keystr, valuestr);
  7497. switch(status)
  7498. {
  7499. case ConfigurationStatus_Accepted:
  7500. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7501. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7502. StoreConfigurationTable();
  7503. break;
  7504. case RebootRequired:
  7505. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7506. StoreConfigurationTable();
  7507. break;
  7508. case NotSupported:
  7509. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7510. break;
  7511. case ConfigurationStatus_Rejected:
  7512. default:
  7513. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7514. break;
  7515. }
  7516. }
  7517. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7518. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7519. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7520. {
  7521. ChageWebSocketPingInterval(atoi(valuestr));
  7522. }
  7523. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7524. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7525. {
  7526. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7527. SetOcppConnStatus(FALSE);
  7528. }
  7529. return result;
  7530. }
  7531. int handleClearCacheRequest(char *uuid, char *payload)
  7532. {
  7533. mtrace();
  7534. int result = FAIL;
  7535. char comfirmstr[20];
  7536. char rmFileCmd[100]={0};
  7537. struct stat stats;
  7538. DEBUG_INFO("handleClearCacheRequest...\n");
  7539. stat("/Storage/OCPP", &stats);
  7540. // Check for directory existence
  7541. if (S_ISDIR(stats.st_mode) == 1)
  7542. {}
  7543. else
  7544. {
  7545. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7546. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7547. system(rmFileCmd);
  7548. }
  7549. if(OCPP_cleanLocalCache())
  7550. {
  7551. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7552. }
  7553. else
  7554. {
  7555. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7556. }
  7557. sendClearCacheConfirmation(uuid, comfirmstr);
  7558. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7559. return result;
  7560. }
  7561. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. int resultRename;
  7566. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7567. char chargingProfilePurposeStr[26]={0};
  7568. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7569. char tempchargingProfilePurposeStr[26]={0};
  7570. char str[100]={0};
  7571. char fname[200]={0};
  7572. char comfirmstr[20]={0};
  7573. char word[1600]={0};
  7574. int clearflag = FALSE;
  7575. int chargingProfileIdIsNULL = FALSE;
  7576. int connectorIsNULL = FALSE;
  7577. int chargingProfilePurposeIsNULL = FALSE;
  7578. int stackLevelIsNULL = FALSE;
  7579. //int GotoEnd = FALSE;
  7580. FILE *fptr1, *fptr2;
  7581. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7582. int n_chargingProfile=0;
  7583. int isEmptyFile = FALSE;
  7584. char sLineWord[1600]={0};
  7585. char chargingProfiles[10][100]={0};
  7586. int ChargeProfileCount = 0;
  7587. int ch;
  7588. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7589. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7590. json_object *ClearChargingProfile;
  7591. ClearChargingProfile = json_tokener_parse(payload);
  7592. if(!is_error(ClearChargingProfile))
  7593. {
  7594. // Optional data
  7595. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7596. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7597. else
  7598. chargingProfileIdIsNULL = TRUE;
  7599. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7600. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7601. else
  7602. connectorIsNULL = TRUE;
  7603. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7604. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7605. else
  7606. chargingProfilePurposeIsNULL = TRUE;
  7607. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7608. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7609. else
  7610. stackLevelIsNULL = TRUE;
  7611. }
  7612. json_object_put(ClearChargingProfile);
  7613. if(connectorIsNULL == FALSE)
  7614. {
  7615. switch(connectorIdInt)
  7616. {
  7617. case 0:
  7618. if(chargingProfilePurposeIsNULL == TRUE)
  7619. {
  7620. int l = 0;
  7621. strcpy(fname, ChargePointMaxProfile_JSON);
  7622. if((access(fname,F_OK))!=-1)
  7623. {
  7624. strcpy(chargingProfiles[l], fname);
  7625. l = l + 1;
  7626. }
  7627. strcpy(fname, TxDefaultProfile_0_JSON);
  7628. if((access(fname,F_OK))!=-1)
  7629. {
  7630. strcpy(chargingProfiles[l], fname);
  7631. l = l + 1;
  7632. }
  7633. ChargeProfileCount = l;
  7634. }
  7635. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7636. {
  7637. strcpy(fname, ChargePointMaxProfile_JSON);
  7638. if((access(fname,F_OK))!=-1)
  7639. {
  7640. strcpy(chargingProfiles[0], fname);
  7641. ChargeProfileCount = 1;
  7642. }
  7643. }
  7644. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7645. {
  7646. strcpy(fname, TxDefaultProfile_0_JSON);
  7647. if((access(fname,F_OK))!=-1)
  7648. {
  7649. strcpy(chargingProfiles[0], fname);
  7650. ChargeProfileCount = 1;
  7651. }
  7652. }
  7653. break;
  7654. default:
  7655. if(chargingProfilePurposeIsNULL == TRUE)
  7656. {
  7657. int m = 0;
  7658. memset(fname, 0, ARRAY_SIZE(fname));
  7659. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7660. if((access(fname,F_OK))!=-1)
  7661. {
  7662. strcpy(chargingProfiles[m], fname);
  7663. m = m + 1;
  7664. }
  7665. memset(fname, 0, ARRAY_SIZE(fname));
  7666. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7667. if((access(fname,F_OK))!=-1)
  7668. {
  7669. strcpy(chargingProfiles[m], fname);
  7670. m = m + 1;
  7671. }
  7672. ChargeProfileCount = m;
  7673. }
  7674. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7675. {
  7676. //strcpy(fname, TxDefaultProfile_1_JSON);
  7677. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7678. if((access(fname,F_OK))!=-1)
  7679. {
  7680. strcpy(chargingProfiles[0], fname);
  7681. ChargeProfileCount = 1;
  7682. }
  7683. }
  7684. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7685. {
  7686. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7687. if((access(fname,F_OK))!=-1)
  7688. {
  7689. strcpy(chargingProfiles[0], fname);
  7690. ChargeProfileCount = 1;
  7691. }
  7692. //strcpy(fname, TxProfile_1_JSON);
  7693. }
  7694. //strcpy(fname, ChargePointMaxProfile_JSON );
  7695. break;
  7696. }
  7697. }
  7698. else // Check all Charging Profiles
  7699. {
  7700. int i = 0;
  7701. char fnametemp[200]={0};
  7702. ChargeProfileCount = 0;
  7703. //Check ChargePointMaxProfile.json exit
  7704. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7705. {
  7706. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7707. i = i + 1;
  7708. }
  7709. //Check TxDefaultProfile_0.json exit
  7710. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7711. {
  7712. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7713. i = i + 1;
  7714. }
  7715. //Check TxDefaultProfile_%d.json
  7716. for(int j=1; j <= gunTotalNumber; j++)
  7717. {
  7718. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7719. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7720. if((access(fnametemp,F_OK))!=-1)
  7721. {
  7722. strcpy(chargingProfiles[i], fnametemp);
  7723. i = i + 1;
  7724. }
  7725. }
  7726. //Check TxProfile_%d.json
  7727. for(int j=1; j <= gunTotalNumber; j++)
  7728. {
  7729. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7730. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7731. if((access(fnametemp,F_OK))!=-1)
  7732. {
  7733. strcpy(chargingProfiles[i], fnametemp);
  7734. i = i + 1;
  7735. }
  7736. }
  7737. ChargeProfileCount = i;
  7738. }// End connectorIsNULL is TRUE
  7739. if(ChargeProfileCount == 0)
  7740. {
  7741. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7742. goto end;
  7743. }
  7744. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7745. {
  7746. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7747. goto end;
  7748. }
  7749. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7750. {
  7751. memset(str, 0, ARRAY_SIZE(str));
  7752. // clear temp file
  7753. sprintf(str,"rm -f %s",temp);
  7754. system(str);
  7755. for(int k=0; k < ChargeProfileCount; k++)
  7756. {
  7757. memset(str, 0, ARRAY_SIZE(str));
  7758. //clear file in C
  7759. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7760. system(str);
  7761. }
  7762. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7763. goto end;
  7764. }
  7765. else if(connectorIsNULL == TRUE)
  7766. {
  7767. for(int k=0; k < ChargeProfileCount; k++)
  7768. {
  7769. fptr1 = fopen(chargingProfiles[k], "r");
  7770. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7771. //Check Charging Profile Count
  7772. while(fscanf(fptr1, "%s", word) != EOF)
  7773. {
  7774. //DEBUG_INFO("word=%s\n",word);
  7775. if(strstr(word, "chargingProfileId")!= NULL)
  7776. {
  7777. //DEBUG_INFO("test chargingProfileId \n");
  7778. n_chargingProfile = n_chargingProfile + 1;
  7779. //DEBUG_INFO("chargingProfileId Found\n");
  7780. }
  7781. }
  7782. rewind(fptr1);
  7783. //search Charging Profile Element
  7784. //int i= 0;
  7785. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7786. {
  7787. json_object *tmpProfilee;
  7788. tmpProfilee = json_tokener_parse(sLineWord);
  7789. if(!is_error(tmpProfilee))
  7790. {
  7791. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7792. {
  7793. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7794. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7795. }
  7796. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7797. {
  7798. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7799. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7800. }
  7801. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7802. {
  7803. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7804. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7805. }
  7806. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7807. {
  7808. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7809. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7810. }
  7811. }
  7812. json_object_put(tmpProfilee);
  7813. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7814. {
  7815. //------- not write to fptr2-------//
  7816. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7817. //clearflag = TRUE;
  7818. }
  7819. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7820. {
  7821. //------- not write to fptr2-------//
  7822. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7823. }
  7824. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7825. {
  7826. //------- not write to fptr2-------//
  7827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7828. }
  7829. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7830. {
  7831. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7832. }
  7833. else
  7834. {
  7835. fprintf(fptr2, sLineWord);//writing data into file
  7836. }
  7837. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7838. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7839. if(clearflag == TRUE)
  7840. {
  7841. fclose(fptr1);
  7842. fclose(fptr2);
  7843. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7844. system(str);
  7845. // clear temp file
  7846. sprintf(str,"rm -f %s",temp);
  7847. system(str);
  7848. }
  7849. else
  7850. {
  7851. fclose(fptr1);
  7852. fclose(fptr2);
  7853. memset(str, 0, ARRAY_SIZE(str));
  7854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7855. system(str);
  7856. resultRename = rename(temp, chargingProfiles[k]);
  7857. if(resultRename == 0)
  7858. {
  7859. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7864. }
  7865. if(comfirmstr[0]== 0)
  7866. {
  7867. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7868. }
  7869. //Check chargingProfile is empty file
  7870. /*------ Read the file ----------------*/
  7871. fptr1=fopen(chargingProfiles[k],"r");
  7872. ch=fgetc(fptr1);
  7873. rewind(fptr1);
  7874. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7875. if(ch!=EOF)
  7876. {
  7877. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7878. {
  7879. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7880. if(sLineWord[0]=='\0')
  7881. {
  7882. isEmptyFile = TRUE;
  7883. break;
  7884. }
  7885. else
  7886. {
  7887. isEmptyFile = FALSE;
  7888. break;
  7889. }
  7890. }
  7891. }
  7892. else
  7893. isEmptyFile = TRUE;
  7894. fclose(fptr1);
  7895. if(isEmptyFile == TRUE)
  7896. {
  7897. memset(str, 0, ARRAY_SIZE(str));
  7898. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7899. system(str);
  7900. }
  7901. }
  7902. }// End of while(int k=0; k < ChargePointCount; k++)
  7903. }
  7904. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7905. {
  7906. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7907. for(int k=0; k < ChargeProfileCount; k++)
  7908. {
  7909. fptr1 = fopen(chargingProfiles[k], "r");
  7910. fptr2 = fopen(temp, "w+");
  7911. //Check Charging Profile Count
  7912. while(fscanf(fptr1, "%s", word) != EOF)
  7913. {
  7914. //DEBUG_INFO("word=%s\n",word);
  7915. if(strstr(word, "chargingProfileId")!= NULL)
  7916. {
  7917. n_chargingProfile = n_chargingProfile + 1;
  7918. }
  7919. }
  7920. rewind(fptr1);
  7921. //search Charging Profile Element
  7922. //int i= 0;
  7923. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7924. {
  7925. json_object *tmpProfilee;
  7926. tmpProfilee = json_tokener_parse(sLineWord);
  7927. if(!is_error(tmpProfilee))
  7928. {
  7929. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7930. {
  7931. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7932. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7933. }
  7934. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7935. {
  7936. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7937. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7938. }
  7939. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7940. {
  7941. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7942. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7943. }
  7944. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7945. {
  7946. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7947. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7948. }
  7949. }
  7950. json_object_put(tmpProfilee);
  7951. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7952. {
  7953. //------- not write to fptr2-------//
  7954. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7955. //clearflag = TRUE;
  7956. }
  7957. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7958. {
  7959. //------- not write to fptr2-------//
  7960. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7961. }
  7962. else if(stackLevelIsNULL == TRUE)
  7963. {
  7964. //Clear Whole File
  7965. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7966. clearflag = TRUE;
  7967. break;
  7968. }
  7969. else
  7970. {
  7971. fprintf(fptr2, sLineWord);//writing data into file
  7972. }
  7973. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7974. }
  7975. if(clearflag == TRUE)
  7976. {
  7977. fclose(fptr1);
  7978. fclose(fptr2);
  7979. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7980. system(str);
  7981. // clear temp file
  7982. sprintf(str,"rm -f %s",temp);
  7983. system(str);
  7984. }
  7985. else
  7986. {
  7987. fclose(fptr1);
  7988. fclose(fptr2);
  7989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7990. system(str);
  7991. resultRename = rename(temp, chargingProfiles[k]);
  7992. if(resultRename == 0)
  7993. {
  7994. DEBUG_INFO("File ChargingProfile renamed successfully");
  7995. }
  7996. else
  7997. {
  7998. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7999. }
  8000. if(comfirmstr[0]== 0)
  8001. {
  8002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8003. }
  8004. //Check chargingProfile is empty file
  8005. /*------ Read the file ----------------*/
  8006. fptr1=fopen(chargingProfiles[k],"r");
  8007. ch=fgetc(fptr1);
  8008. rewind(fptr1);
  8009. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8010. if(ch!=EOF)
  8011. {
  8012. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8013. {
  8014. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8015. if(sLineWord[0]=='\0')
  8016. {
  8017. isEmptyFile = TRUE;
  8018. break;
  8019. }
  8020. else
  8021. {
  8022. isEmptyFile = FALSE;
  8023. break;
  8024. }
  8025. }
  8026. }
  8027. else
  8028. isEmptyFile = TRUE;
  8029. fclose(fptr1);
  8030. if(isEmptyFile == TRUE)
  8031. {
  8032. memset(str, 0, ARRAY_SIZE(str));
  8033. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8034. system(str);
  8035. }
  8036. /*------- End of reading ---------------*/
  8037. }
  8038. } // while(int k=0; k < ChargeProfileCount; k++)
  8039. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8040. end:
  8041. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8042. {
  8043. if(connectorIdInt == 0)
  8044. {
  8045. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8046. {
  8047. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8048. }
  8049. }
  8050. else
  8051. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8052. }
  8053. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8054. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8055. return result;
  8056. }
  8057. void createFirmwareVersionByDataTransfer(void)
  8058. {
  8059. json_object *FirmwareDataTransfer = json_object_new_object();
  8060. // AC & DC model
  8061. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8062. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8063. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8064. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8065. // DC model
  8066. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8067. {
  8068. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8069. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8070. (gunType[3] != GUN_TYPE_UNKNOWN))
  8071. {
  8072. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8073. }
  8074. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8075. {
  8076. // DS DM DW
  8077. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8078. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8079. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8080. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8081. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8082. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8083. }
  8084. else
  8085. {
  8086. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8087. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8088. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8089. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8090. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8091. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8094. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8095. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8096. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8097. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8098. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8099. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8100. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8101. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8102. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8103. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8104. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8105. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8106. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8107. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8108. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8109. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8110. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8111. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8112. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8113. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8114. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8115. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8116. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8117. }
  8118. }
  8119. // 4G model
  8120. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8121. {
  8122. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8123. }
  8124. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8125. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8126. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8127. json_object_put(FirmwareDataTransfer);
  8128. }
  8129. int handleDataTransferRequest(char *uuid, char *payload)
  8130. {
  8131. mtrace();
  8132. json_object *response = json_object_new_object();
  8133. int result = FAIL;
  8134. char tempvendorId[255]={0};
  8135. char tempmessageId[50]={0};
  8136. char tempdata[512]={0};
  8137. char message[2048]={0};
  8138. DEBUG_INFO("handleDataTransferRequest...\n");
  8139. if((uuid != NULL) && (payload != NULL))
  8140. {
  8141. json_object *DataTransfer;
  8142. DataTransfer = json_tokener_parse(payload);
  8143. if(!is_error(DataTransfer))
  8144. {
  8145. // Required data
  8146. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8147. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8148. // Optional data
  8149. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8150. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8151. if(json_object_object_get(DataTransfer, "data") != NULL)
  8152. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8153. result = PASS;
  8154. }
  8155. json_object_put(DataTransfer);
  8156. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8157. {
  8158. // Send all moudle firmware version on EVSE
  8159. createFirmwareVersionByDataTransfer();
  8160. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8161. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8162. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8163. json_object_put(response);
  8164. }
  8165. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8166. {
  8167. system("/usr/bin/run_tmate_restart.sh &");
  8168. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8169. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8170. json_object_put(response);
  8171. }
  8172. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8173. {
  8174. json_object *data;
  8175. data = json_tokener_parse(tempdata);
  8176. if(!is_error(data))
  8177. {
  8178. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8179. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8180. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8181. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8182. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8183. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8184. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8185. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8186. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8187. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8188. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8189. }
  8190. else
  8191. {
  8192. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8193. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8194. }
  8195. json_object_put(data);
  8196. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8197. json_object_put(response);
  8198. }
  8199. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8200. {
  8201. json_object *data;
  8202. data = json_tokener_parse(tempdata);
  8203. if(!is_error(data))
  8204. {
  8205. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8206. if(json_object_object_get(data, "idToken") != NULL)
  8207. {
  8208. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8209. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8210. }
  8211. if(json_object_object_get(data, "price") != NULL)
  8212. {
  8213. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8214. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8215. }
  8216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8217. }
  8218. else
  8219. {
  8220. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8221. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8222. }
  8223. json_object_put(data);
  8224. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8225. json_object_put(response);
  8226. }
  8227. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8228. {
  8229. json_object *data;
  8230. data = json_tokener_parse(tempdata);
  8231. if(!is_error(data))
  8232. {
  8233. if(json_object_object_get(data, "txId") != NULL)
  8234. {
  8235. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8236. for(int idx = 0;idx<gunTotalNumber;idx++)
  8237. {
  8238. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8239. {
  8240. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8241. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8242. if(json_object_object_get(data, "description") != NULL)
  8243. {
  8244. // California pricing V1.0
  8245. DEBUG_INFO("California pricing V1.0\n");
  8246. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8247. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8248. }
  8249. else
  8250. {
  8251. // California pricing V1.1
  8252. DEBUG_INFO("California pricing V1.1\n");
  8253. if(json_object_object_get(data, "timestamp") != NULL)
  8254. {
  8255. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8256. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8257. }
  8258. if(json_object_object_get(data, "meterValue") != NULL)
  8259. {
  8260. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8261. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8262. }
  8263. if(json_object_object_get(data, "cost") != NULL)
  8264. {
  8265. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8266. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8267. }
  8268. if(json_object_object_get(data, "state") != NULL)
  8269. {
  8270. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8271. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8272. }
  8273. if(json_object_object_get(data, "chargingPrice") != NULL)
  8274. {
  8275. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8276. {
  8277. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8278. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8279. }
  8280. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8281. {
  8282. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8283. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8284. }
  8285. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8286. {
  8287. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8288. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8289. }
  8290. }
  8291. if(json_object_object_get(data, "idlePrice") != NULL)
  8292. {
  8293. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8294. {
  8295. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8296. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8297. }
  8298. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8299. {
  8300. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8301. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8302. }
  8303. }
  8304. if(json_object_object_get(data, "nextPeriod") != NULL)
  8305. {
  8306. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8307. {
  8308. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8309. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8310. }
  8311. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8312. {
  8313. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8314. {
  8315. 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")));
  8316. 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"));
  8317. }
  8318. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8319. {
  8320. 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")));
  8321. 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"));
  8322. }
  8323. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8324. {
  8325. 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")));
  8326. 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"));
  8327. }
  8328. }
  8329. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8330. {
  8331. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8332. {
  8333. 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")));
  8334. 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"));
  8335. }
  8336. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8337. {
  8338. 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")));
  8339. 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"));
  8340. }
  8341. }
  8342. }
  8343. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8344. {
  8345. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8346. {
  8347. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8348. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8349. }
  8350. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8351. {
  8352. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8353. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8354. }
  8355. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8356. {
  8357. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8358. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8359. }
  8360. }
  8361. }
  8362. }
  8363. }
  8364. }
  8365. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8366. }
  8367. else
  8368. {
  8369. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8370. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8371. }
  8372. json_object_put(data);
  8373. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8374. json_object_put(response);
  8375. }
  8376. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8377. {
  8378. json_object *data;
  8379. data = json_tokener_parse(tempdata);
  8380. if(!is_error(data))
  8381. {
  8382. if(json_object_object_get(data, "txId") != NULL)
  8383. {
  8384. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8385. for(int idx = 0;idx<gunTotalNumber;idx++)
  8386. {
  8387. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8388. {
  8389. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8390. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8391. if(json_object_object_get(data, "description") != NULL)
  8392. {
  8393. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8394. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8395. }
  8396. }
  8397. }
  8398. }
  8399. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8400. }
  8401. else
  8402. {
  8403. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8404. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8405. }
  8406. json_object_put(data);
  8407. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8408. json_object_put(response);
  8409. }
  8410. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8411. {
  8412. json_object *data;
  8413. data = json_tokener_parse(tempdata);
  8414. if(!is_error(data))
  8415. {
  8416. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8417. if(json_object_object_get(data, "Content_Type") != NULL)
  8418. {
  8419. 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))
  8420. {
  8421. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8422. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8423. {
  8424. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8425. }
  8426. }
  8427. else
  8428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8429. }
  8430. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8431. }
  8432. else
  8433. {
  8434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8435. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8436. }
  8437. json_object_put(data);
  8438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8439. json_object_put(response);
  8440. }
  8441. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8442. {
  8443. json_object *data;
  8444. data = json_tokener_parse(tempdata);
  8445. if(!is_error(data))
  8446. {
  8447. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8448. if(json_object_object_get(data, "Page_Index") != NULL)
  8449. {
  8450. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8451. }
  8452. if(json_object_object_get(data, "Duration") != NULL)
  8453. {
  8454. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8455. }
  8456. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8457. }
  8458. else
  8459. {
  8460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8462. }
  8463. json_object_put(data);
  8464. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8465. json_object_put(response);
  8466. }
  8467. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8468. {
  8469. json_object *data;
  8470. data = json_tokener_parse(tempdata);
  8471. if(!is_error(data))
  8472. {
  8473. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8474. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8475. {
  8476. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8477. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8478. else
  8479. {
  8480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8481. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8482. }
  8483. }
  8484. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8485. {
  8486. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8487. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8488. else
  8489. {
  8490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8491. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8492. }
  8493. }
  8494. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8495. {
  8496. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8497. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8498. else
  8499. {
  8500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8502. }
  8503. }
  8504. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8505. {
  8506. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8507. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8508. else
  8509. {
  8510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8512. }
  8513. }
  8514. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8515. {
  8516. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8517. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8518. else
  8519. {
  8520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8521. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8522. }
  8523. }
  8524. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8525. {
  8526. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8527. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8528. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8529. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8530. else
  8531. {
  8532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8533. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8534. }
  8535. }
  8536. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8537. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8538. }
  8539. else
  8540. {
  8541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8542. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8543. }
  8544. json_object_put(data);
  8545. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8546. json_object_put(response);
  8547. }
  8548. else
  8549. {
  8550. // Can not find valid message id
  8551. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8552. }
  8553. }
  8554. else
  8555. {
  8556. // Payload is null
  8557. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8558. }
  8559. LWS_Send(message);
  8560. return result;
  8561. }
  8562. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8563. {
  8564. mtrace();
  8565. int result = FAIL;
  8566. int connectorIdInt, durationInt;
  8567. char chargingRateUnitStr[4]={0};
  8568. char comfirmstr[20];
  8569. int confirmPeriods = 0;
  8570. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8571. json_object *GetCompositeSchedule;
  8572. GetCompositeSchedule = json_tokener_parse(payload);
  8573. if(!is_error(GetCompositeSchedule))
  8574. {
  8575. // Required data
  8576. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8577. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8578. else
  8579. connectorIdInt = -1;
  8580. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8581. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8582. else
  8583. durationInt = 86400;
  8584. // Optional data
  8585. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8586. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8587. }
  8588. json_object_put(GetCompositeSchedule);
  8589. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8590. if((connectorIdInt == 0) ||
  8591. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8592. {
  8593. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8594. struct StructChargingProfile tmpProfile[1];
  8595. if(strstr(chargingRateUnitStr, "W") != NULL)
  8596. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8597. else
  8598. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8599. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8600. {
  8601. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8602. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8603. }
  8604. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8605. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8606. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8607. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8608. {
  8609. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8610. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8611. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8612. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8613. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8614. {
  8615. confirmPeriods = idx;
  8616. break;
  8617. }
  8618. }
  8619. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8620. {
  8621. confirmPeriods += 1;
  8622. }
  8623. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8624. }
  8625. else
  8626. {
  8627. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8628. }
  8629. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8630. return result;
  8631. }
  8632. int handleGetConfigurationRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int MaxKeySupported = 0;
  8637. int n_keys = 0;
  8638. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8639. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8640. json_object *GetConfiguration;
  8641. GetConfiguration = json_tokener_parse(payload);
  8642. if(!is_error(GetConfiguration))
  8643. {
  8644. // Optional data
  8645. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8646. {
  8647. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8648. {
  8649. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8650. n_keys = idx + 1;
  8651. }
  8652. }
  8653. }
  8654. json_object_put(GetConfiguration);
  8655. UnknownKeynum = 0;
  8656. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8657. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8658. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8659. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8660. if(n_keys != 0)
  8661. {
  8662. for(int i=0;i<n_keys;i++)
  8663. {
  8664. getKeyValue(requestKey[i]);
  8665. }
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8670. getKeyValue("");
  8671. }
  8672. processUnkownKey();
  8673. sendGetConfigurationConfirmation(uuid);
  8674. return result;
  8675. }
  8676. static char fnamePlusPath[100]={0};
  8677. static char fnamePWithNoPath[60]={0};
  8678. void checkUploadLog(void)
  8679. {
  8680. FILE *fp;
  8681. /* Open the command for reading. */
  8682. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8683. if (fp == NULL) {
  8684. DEBUG_WARN("Failed to run command\n" );
  8685. exit(1);
  8686. }
  8687. int ftppathlen = 0;
  8688. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8689. int i = 0;
  8690. /* Read the output a line at a time - output it. */
  8691. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8692. if(i==0)
  8693. {
  8694. ftppathlen = strlen(fnamePlusPath);
  8695. DEBUG_INFO("%s\n", fnamePlusPath);
  8696. fnamePlusPath[ftppathlen]='\0';
  8697. break;
  8698. }
  8699. i= i+1;
  8700. }
  8701. /* close */
  8702. pclose(fp);
  8703. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8704. {
  8705. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8706. {
  8707. fnamePlusPath[k]='\0';
  8708. }
  8709. }
  8710. i=1;
  8711. //char fname[60]={0};
  8712. while(i < ftppathlen)
  8713. {
  8714. int len=ftppathlen-i;
  8715. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8716. {
  8717. DEBUG_INFO("compare '/' all right\n");
  8718. break;
  8719. }
  8720. i=i+1;
  8721. }
  8722. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8723. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8724. fnamePWithNoPath[i+1] = '\0';
  8725. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8726. {
  8727. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8728. {
  8729. fnamePWithNoPath[j]='\0';
  8730. }
  8731. }
  8732. FILE* fp1 = fopen(fnamePlusPath, "r");
  8733. if (fp1)
  8734. {
  8735. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8736. // file exists
  8737. fclose(fp1);
  8738. }
  8739. else
  8740. {
  8741. // file doesn't exist
  8742. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8743. }
  8744. }
  8745. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8746. {
  8747. mtrace();
  8748. int result = FAIL;
  8749. time_t CurrentTime;
  8750. struct tm *tm;
  8751. pthread_t th_Status;
  8752. CurrentTime = time(NULL);
  8753. tm = localtime(&CurrentTime);
  8754. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8755. 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);
  8756. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8757. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8758. return result;
  8759. }
  8760. void* GetDiagnosticsProcess(void* data)
  8761. {
  8762. pthread_detach(pthread_self());
  8763. mtrace();
  8764. int retriesInt=0, retryIntervalInt=0;
  8765. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8766. 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};
  8767. int port=0;
  8768. int isSuccess = FALSE;
  8769. char cmdBuf[2048];
  8770. struct tm *tmNow;
  8771. time_t CurrentTime;
  8772. struct tm tmStart;
  8773. struct tm tmStop;
  8774. CurrentTime = time(NULL);
  8775. tmNow=localtime(&CurrentTime);
  8776. uint16_t targetYear, targetMonth;
  8777. json_object *GetDiagnostics;
  8778. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8779. GetDiagnostics = json_tokener_parse(data);
  8780. if(!is_error(GetDiagnostics))
  8781. {
  8782. // Required data
  8783. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8784. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8785. // Optional data
  8786. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8787. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8788. else
  8789. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8790. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8791. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8792. else
  8793. retryIntervalInt = 30;
  8794. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8795. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8796. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8797. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8798. }
  8799. json_object_put(GetDiagnostics);
  8800. // Pack log to compress file
  8801. 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) &&
  8802. (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))
  8803. {
  8804. // Pack system log
  8805. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8806. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8807. targetYear = tmStart.tm_year;
  8808. targetMonth = tmStart.tm_mon;
  8809. do
  8810. {
  8811. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8812. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8813. if(targetMonth+1>=13)
  8814. {
  8815. targetYear += 1;
  8816. targetMonth = 1;
  8817. }
  8818. else
  8819. {
  8820. targetMonth += 1;
  8821. }
  8822. }while((targetYear < (tmNow->tm_year+1900)) ||
  8823. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8824. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8825. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8826. system(cmdBuf);
  8827. // Pack charging & event log
  8828. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8829. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8830. targetYear = tmStart.tm_year;
  8831. targetMonth = tmStart.tm_mon;
  8832. do
  8833. {
  8834. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8835. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8836. if(targetMonth+1>=13)
  8837. {
  8838. targetYear += 1;
  8839. targetMonth = 1;
  8840. }
  8841. else
  8842. {
  8843. targetMonth += 1;
  8844. }
  8845. }while((targetYear < (tmNow->tm_year+1900)) ||
  8846. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8847. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8848. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8849. system(cmdBuf);
  8850. // Combine log file
  8851. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8852. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8853. }
  8854. else
  8855. {
  8856. system("exec /root/logPackTools 'log' 6");
  8857. }
  8858. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8859. system(cmdBuf);
  8860. checkUploadLog();
  8861. //****************location*******************/
  8862. if(strcmp(locationstr,"")==0)
  8863. {
  8864. DEBUG_INFO("location is <Empty>!\n");
  8865. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8866. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8867. goto end;
  8868. }
  8869. memset(protocol, 0, ARRAY_SIZE(protocol));
  8870. memset(user, 0, ARRAY_SIZE(user) );
  8871. memset(password, 0, ARRAY_SIZE(password));
  8872. memset(host, 0, ARRAY_SIZE(host));
  8873. memset(path, 0, ARRAY_SIZE(path));
  8874. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8875. memset(host1, 0, ARRAY_SIZE(host1));
  8876. memset(path1, 0, ARRAY_SIZE(path1));
  8877. /*location: ftp://user:password@host:port/path*/
  8878. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8879. if((access(fnamePlusPath,F_OK))!=-1)
  8880. {
  8881. DEBUG_INFO("fnamePlusPath exist.\n");
  8882. }
  8883. else
  8884. {
  8885. DEBUG_INFO("fnamePlusPath not exist!\n");
  8886. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8887. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8888. goto end;
  8889. }
  8890. if(strchr(locationstr,'@')==NULL)
  8891. {
  8892. sscanf(locationstr,
  8893. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8894. protocol, host, &port, path);
  8895. strcpy(user,"anonymous");
  8896. strcpy(password,"");
  8897. }
  8898. else
  8899. {
  8900. //DEBUG_INFO("pch=%s\n", pch);
  8901. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8902. protocol, user, password, host, &port, path);
  8903. }
  8904. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8905. {
  8906. DEBUG_INFO("protocol is not ftp/http ! \n");
  8907. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8909. goto end;
  8910. }
  8911. if(strncmp(locationstr,"http", 4) == 0)
  8912. {
  8913. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8914. sprintf(ftppath,"/%s", path);
  8915. do
  8916. {
  8917. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8918. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8919. sleep(3);
  8920. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8921. if(!isSuccess)
  8922. {
  8923. DEBUG_INFO("Diagnostics fail.\n");
  8924. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8925. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8926. sleep(retryIntervalInt);
  8927. }
  8928. else
  8929. {
  8930. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8931. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8932. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8933. }
  8934. retriesInt--;
  8935. }while((isSuccess == 0)&&(retriesInt >= 0));
  8936. }
  8937. else
  8938. {
  8939. sscanf(host,"%[^/]%s",host1, path1);
  8940. if(strlen(path) > 0)
  8941. sprintf(ftppath,"/%s", path);
  8942. else
  8943. sprintf(ftppath,"/%s", path1);
  8944. int ftppathlen=strlen(ftppath);
  8945. int i=1;
  8946. char filenametemp[50];
  8947. while(i < ftppathlen)
  8948. {
  8949. int len=ftppathlen-i;
  8950. if(ftppath[len]== 47) // '/' ascll code: 47
  8951. {
  8952. DEBUG_INFO("find '/' all right\n");
  8953. break;
  8954. }
  8955. i=i+1;
  8956. }
  8957. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8958. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8959. filenametemp[i+1] = 0;
  8960. if(port == 0)
  8961. port = 21;
  8962. do
  8963. {
  8964. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8965. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8966. sleep(3);
  8967. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8968. if(!isSuccess)
  8969. {
  8970. DEBUG_INFO("Diagnostics fail.\n");
  8971. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8972. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8973. sleep(retryIntervalInt);
  8974. }
  8975. else
  8976. {
  8977. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8978. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8979. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8980. }
  8981. retriesInt--;
  8982. }while((!isSuccess)&&(retriesInt >= 0));
  8983. }
  8984. end:
  8985. system("rm -f /mnt/*");
  8986. sleep(5);
  8987. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8988. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8989. pthread_exit(NULL);
  8990. }
  8991. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8992. {
  8993. mtrace();
  8994. int result = FAIL;
  8995. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8996. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8997. {
  8998. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8999. locallistVersion = -1;
  9000. }
  9001. else
  9002. {
  9003. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9004. OCPP_getListVerion();
  9005. }
  9006. //from db.OCPP_getListVerion
  9007. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9008. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9009. sendGetLocalListVersionConfirmation(uuid,"");
  9010. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9011. return result;
  9012. }
  9013. int handleRemoteStartRequest(char *uuid, char *payload)
  9014. {
  9015. mtrace();
  9016. int result = FAIL;
  9017. int connectorIdInt=0;
  9018. int tempIndex = 0;
  9019. int connectorIdIsNULL, chargingProfileIsNULL;
  9020. char comfirmstr[20]={0};
  9021. char cmdBuf[512];
  9022. json_object *RemoteStartTransaction;
  9023. FILE *fp;
  9024. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9025. if(server_pending == TRUE)
  9026. {
  9027. return 0;
  9028. }
  9029. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9030. RemoteStartTransaction = json_tokener_parse(payload);
  9031. if(!is_error(RemoteStartTransaction))
  9032. {
  9033. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9034. {
  9035. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9036. if(connectorIdInt <= gunTotalNumber)
  9037. {
  9038. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9039. // Required data
  9040. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9041. // Optional data
  9042. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9043. {
  9044. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9045. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9046. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9047. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9048. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9049. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9050. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9051. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9052. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9053. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9054. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9055. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9056. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9057. {
  9058. 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")));
  9059. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9060. 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"));
  9061. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9062. 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"));
  9063. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9064. 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")));
  9065. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9066. {
  9067. 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++)
  9068. {
  9069. 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"));
  9070. 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"));
  9071. 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)
  9072. 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"));
  9073. }
  9074. }
  9075. }
  9076. }
  9077. else
  9078. chargingProfileIsNULL = TRUE;
  9079. }
  9080. }
  9081. else
  9082. connectorIdIsNULL = TRUE;
  9083. }
  9084. else
  9085. connectorIdIsNULL = TRUE;
  9086. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9087. {
  9088. DEBUG_WARN("Connector id is NULL\n.");
  9089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9090. goto end;
  9091. }
  9092. /*
  9093. enum _SYSTEM_STATUS
  9094. {
  9095. S_BOOTING = 0,
  9096. S_IDLE, = 1
  9097. S_AUTHORIZING, = 2
  9098. S_REASSIGN_CHECK, = 3
  9099. S_REASSIGN, = 4
  9100. S_PRECHARGE, = 5
  9101. S_PREPARING_FOR_EV, = 6
  9102. S_PREPARING_FOR_EVSE, = 7
  9103. S_CHARGING, = 8
  9104. S_TERMINATING, = 9
  9105. S_COMPLETE, = 10
  9106. S_ALARM, = 11
  9107. S_FAULT = 12
  9108. }
  9109. */
  9110. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9111. {
  9112. //check Transaction active
  9113. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9114. {
  9115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9116. {
  9117. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9118. }
  9119. else
  9120. {
  9121. tempIndex = connectorIdInt -1;
  9122. }
  9123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9124. {
  9125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9126. {
  9127. 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))
  9128. {
  9129. //Reserved
  9130. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9131. }
  9132. 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))
  9133. {
  9134. //Reserved
  9135. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9136. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9137. goto end;
  9138. }
  9139. else
  9140. {
  9141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9142. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9143. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9144. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9145. {
  9146. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9148. goto end;
  9149. }
  9150. }//END FOR ELSE
  9151. }
  9152. }// END FOR CHAdeMO_QUANTITY
  9153. }
  9154. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9155. {
  9156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9157. {
  9158. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9159. }
  9160. else
  9161. {
  9162. tempIndex = connectorIdInt -1;
  9163. }
  9164. for (int index = 0; index < CCS_QUANTITY; index++)
  9165. {
  9166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9167. {
  9168. 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))
  9169. {
  9170. //Reserved
  9171. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9172. }
  9173. 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))
  9174. {
  9175. //Reserved
  9176. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9178. goto end;
  9179. }
  9180. else
  9181. {
  9182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9183. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9184. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9185. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9186. {
  9187. DEBUG_WARN("CCS connector not allow start\n.");
  9188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9189. goto end;
  9190. }
  9191. }// END FOR ELSE
  9192. }
  9193. }// END FOR CCS_QUANTITY
  9194. }
  9195. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9196. {
  9197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9198. {
  9199. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9200. }
  9201. else
  9202. {
  9203. tempIndex = connectorIdInt -1;
  9204. }
  9205. for (int index = 0; index < GB_QUANTITY; index++)
  9206. {
  9207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9208. {
  9209. 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))
  9210. {
  9211. //Reserved
  9212. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9213. }
  9214. 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))
  9215. {
  9216. //Reserved
  9217. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9219. goto end;
  9220. }
  9221. else
  9222. {
  9223. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9224. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9225. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9226. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9227. {
  9228. DEBUG_WARN("GB connector not allow start\n.");
  9229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9230. goto end;
  9231. }
  9232. }// END FOR ELSE
  9233. }
  9234. } // END FOR GB_QUANTITY
  9235. }
  9236. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9237. {
  9238. tempIndex = connectorIdInt -1;
  9239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9240. {
  9241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9242. {
  9243. 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))
  9244. {
  9245. //Reserved
  9246. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9247. }
  9248. 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))
  9249. {
  9250. //Reserved
  9251. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9252. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9253. goto end;
  9254. }
  9255. else
  9256. {
  9257. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9258. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9259. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9260. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9261. {
  9262. DEBUG_WARN("GB connector not allow start\n.");
  9263. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9264. goto end;
  9265. }
  9266. }// END FOR ELSE
  9267. }
  9268. } // END FOR GB_QUANTITY
  9269. }
  9270. else
  9271. {
  9272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9273. {
  9274. tempIndex = 2;
  9275. }
  9276. else
  9277. {
  9278. tempIndex = connectorIdInt -1;
  9279. }
  9280. for (int index = 0; index < AC_QUANTITY; index++)
  9281. {
  9282. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9283. {
  9284. 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))
  9285. {
  9286. //Reserved
  9287. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9288. }
  9289. 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))
  9290. {
  9291. //Reserved
  9292. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9294. goto end;
  9295. }
  9296. else
  9297. {
  9298. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9299. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9300. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9301. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9302. {
  9303. DEBUG_WARN("AC connector not allow start\n.");
  9304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9305. goto end;
  9306. }
  9307. }//END FOR ELSE
  9308. }
  9309. }// END FOR AC_QUANTITY
  9310. }
  9311. if(chargingProfileIsNULL == FALSE)
  9312. {
  9313. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9314. {
  9315. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9316. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9317. //memset idTag
  9318. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9319. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9320. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9321. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9322. // Save profile to file
  9323. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9324. system(cmdBuf);
  9325. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9326. fp = fopen(cmdBuf, "w");
  9327. 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));
  9328. fclose(fp);
  9329. }
  9330. else
  9331. {
  9332. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9333. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9334. }
  9335. }
  9336. else
  9337. {
  9338. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9339. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9340. //memset idTag
  9341. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9342. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9343. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9344. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9345. }
  9346. }
  9347. else
  9348. {
  9349. DEBUG_WARN("Connector id over\n.");
  9350. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9351. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9352. }
  9353. end:
  9354. json_object_put(RemoteStartTransaction);
  9355. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9356. {
  9357. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9358. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9359. }
  9360. //OCPP send RemoteStartConfirmation by first.
  9361. sendRemoteStartConfirmation(uuid, comfirmstr);
  9362. return result;
  9363. }
  9364. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9365. {
  9366. mtrace();
  9367. int result = FAIL;
  9368. int match = FALSE;
  9369. int GunNO = 0;
  9370. int tempIndex = 0;
  9371. int transactionIdInt=0;
  9372. int transactionIdIsNULL= TRUE;
  9373. char comfirmstr[20];
  9374. json_object *RemoteStopTransaction;
  9375. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9376. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9377. if(server_pending == TRUE)
  9378. {
  9379. return 0;
  9380. }
  9381. RemoteStopTransaction = json_tokener_parse(payload);
  9382. if(!is_error(RemoteStopTransaction))
  9383. {
  9384. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9385. {
  9386. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9387. transactionIdIsNULL = FALSE;
  9388. }
  9389. }
  9390. json_object_put(RemoteStopTransaction);
  9391. if(transactionIdIsNULL == FALSE)
  9392. {
  9393. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9394. {
  9395. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9396. {
  9397. //check Transaction active
  9398. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9399. {
  9400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9401. {
  9402. tempIndex = ((gun_index==2) ? 1: 0);
  9403. }
  9404. else
  9405. {
  9406. tempIndex = gun_index;
  9407. }
  9408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9409. {
  9410. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9411. {
  9412. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9413. {
  9414. match = TRUE;
  9415. GunNO = gun_index;
  9416. }
  9417. }
  9418. }// END FOR CHAdeMO_QUANTITY
  9419. }
  9420. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9421. {
  9422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9423. {
  9424. tempIndex = ((gun_index==2) ? 1: 0);
  9425. }
  9426. else
  9427. {
  9428. tempIndex = gun_index;
  9429. }
  9430. for (int index = 0; index < CCS_QUANTITY; index++)
  9431. {
  9432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9433. {
  9434. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9435. {
  9436. match = TRUE;
  9437. GunNO = gun_index;
  9438. }
  9439. }
  9440. }// END FOR CCS_QUANTITY
  9441. }
  9442. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9443. {
  9444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9445. {
  9446. tempIndex = ((gun_index==2) ? 1: 0);
  9447. }
  9448. else
  9449. {
  9450. tempIndex = gun_index;
  9451. }
  9452. for (int index = 0; index < GB_QUANTITY; index++)
  9453. {
  9454. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9455. {
  9456. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9457. {
  9458. match = TRUE;
  9459. GunNO = gun_index;
  9460. }
  9461. }
  9462. }// END FOR GB_QUANTITY
  9463. }
  9464. else if(gunType[gun_index] == GUN_TYPE_DO)
  9465. {
  9466. tempIndex = gun_index;
  9467. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9468. {
  9469. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9470. {
  9471. 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
  9472. {
  9473. match = TRUE;
  9474. GunNO = gun_index;
  9475. }
  9476. }
  9477. }// END FOR GB_QUANTITY
  9478. }
  9479. else
  9480. {
  9481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9482. {
  9483. tempIndex = 2;
  9484. }
  9485. else
  9486. {
  9487. tempIndex = gun_index;
  9488. }
  9489. for (int index = 0; index < AC_QUANTITY; index++)
  9490. {
  9491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9492. {
  9493. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9494. {
  9495. match = TRUE;
  9496. GunNO = gun_index;
  9497. }
  9498. }
  9499. }// END FOR CHAdeMO_QUANTITY
  9500. } // END FOR AC ELSE
  9501. }// CHECK IF ResponseTransactionId == transactionIdInt
  9502. }//END FOR
  9503. if( match == TRUE)
  9504. {
  9505. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9506. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9507. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9508. }
  9509. else
  9510. {
  9511. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9512. }
  9513. }
  9514. else
  9515. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9516. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9517. return result;
  9518. }
  9519. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9520. {
  9521. mtrace();
  9522. int result = FAIL;
  9523. int connectorIdInt=0, reservationIdInt=0;
  9524. int tempIndex = 0;
  9525. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9526. char comfirmstr[20]={0};
  9527. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9528. int c = 0;
  9529. char *loc;
  9530. //char *ptr;
  9531. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9532. strcpy(sstrtemp, stringtrimspace(payload));
  9533. //***(1)connectorId ****/
  9534. c=0;
  9535. loc = strstr(sstrtemp, "connectorId");
  9536. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9537. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9538. {
  9539. sstr[c] = loc[strlen("connectorId")+2+c];
  9540. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9541. c++;
  9542. }
  9543. sstr[c] = '\0';
  9544. connectorIdInt = atoi(sstr);
  9545. //***(2)expiryDate ****/
  9546. loc = strstr(sstrtemp, "expiryDate");
  9547. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9548. c = 0;
  9549. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9550. {
  9551. sstr[c] = loc[3+strlen("expiryDate")+c];
  9552. c++;
  9553. }
  9554. sstr[c] = '\0';
  9555. strcpy(expiryDatestr, sstr);
  9556. //***(3)idTag ****/
  9557. loc = strstr(sstrtemp, "idTag");
  9558. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9559. c = 0;
  9560. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9561. {
  9562. sstr[c] = loc[3+strlen("idTag")+c];
  9563. c++;
  9564. }
  9565. sstr[c] = '\0';
  9566. strcpy(idTagstr, sstr);
  9567. //***(4)parentIdTag ****/
  9568. loc = strstr(sstrtemp, "parentIdTag");
  9569. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9570. c = 0;
  9571. if(loc == NULL)
  9572. {
  9573. strcpy(parentIdTagstr, "");
  9574. }
  9575. else
  9576. {
  9577. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9578. {
  9579. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9580. c++;
  9581. }
  9582. sstr[c] = '\0';
  9583. strcpy(parentIdTagstr, sstr);
  9584. }
  9585. //***(5)reservationId ****/
  9586. c=0;
  9587. loc = strstr(sstrtemp, "reservationId");
  9588. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9589. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9590. {
  9591. sstr[c] = loc[strlen("reservationId")+2+c];
  9592. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9593. c++;
  9594. }
  9595. sstr[c] = '\0';
  9596. reservationIdInt = atoi(sstr);
  9597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9598. /*
  9599. enum SYSTEM_STATUS
  9600. {
  9601. SYS_MODE_BOOTING = 0,
  9602. SYS_MODE_IDLE = 1,
  9603. SYS_MODE_AUTHORIZING = 2,
  9604. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9605. SYS_MODE_REASSIGN = 4,
  9606. SYS_MODE_PREPARING = 5,
  9607. SYS_MODE_PREPARE_FOR_EV = 6,
  9608. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9609. SYS_MODE_CHARGING = 8,
  9610. SYS_MODE_TERMINATING = 9,
  9611. SYS_MODE_COMPLETE = 10,
  9612. SYS_MODE_ALARM = 11,
  9613. SYS_MODE_FAULT = 12,
  9614. SYS_MODE_RESERVATION = 13,
  9615. SYS_MODE_BOOKING = 14,
  9616. SYS_MODE_MAINTAIN = 15,
  9617. SYS_MODE_DEBUG = 16,
  9618. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9619. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9620. SYS_MODE_UPDATE = 19
  9621. };
  9622. */
  9623. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9624. {
  9625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9626. goto end;
  9627. }
  9628. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9629. {
  9630. //check Transaction active
  9631. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9632. {
  9633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9634. {
  9635. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9636. }
  9637. else
  9638. {
  9639. tempIndex = connectorIdInt -1;
  9640. }
  9641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9642. {
  9643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9644. {
  9645. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9646. {
  9647. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9648. {
  9649. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9650. {
  9651. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9653. }
  9654. 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'))
  9655. {
  9656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9657. }
  9658. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9659. {
  9660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9661. }
  9662. else
  9663. {
  9664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9665. }
  9666. }
  9667. 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
  9668. {
  9669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9670. }
  9671. }
  9672. else
  9673. {
  9674. //replace reservation
  9675. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9677. }
  9678. }
  9679. } // END FOR CHAdeMO_QUANTITY
  9680. }
  9681. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9682. {
  9683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9684. {
  9685. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9686. }
  9687. else
  9688. {
  9689. tempIndex = connectorIdInt -1;
  9690. }
  9691. for (int index = 0; index < CCS_QUANTITY; index++)
  9692. {
  9693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9694. {
  9695. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9696. {
  9697. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9698. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9699. {
  9700. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9701. {
  9702. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9704. }
  9705. 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'))
  9706. {
  9707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9708. }
  9709. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9710. {
  9711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9712. }
  9713. else
  9714. {
  9715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9716. }
  9717. }
  9718. 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
  9719. {
  9720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9721. }
  9722. }
  9723. else
  9724. {
  9725. //replace reservation
  9726. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9728. }
  9729. }
  9730. } // END FOR CCS_QUANTITY
  9731. }
  9732. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9733. {
  9734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9735. {
  9736. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9737. }
  9738. else
  9739. {
  9740. tempIndex = connectorIdInt -1;
  9741. }
  9742. for (int index = 0; index < GB_QUANTITY; index++)
  9743. {
  9744. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9745. {
  9746. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9747. {
  9748. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9749. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9750. {
  9751. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9752. {
  9753. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9755. }
  9756. 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'))
  9757. {
  9758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9759. }
  9760. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9761. {
  9762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9763. }
  9764. else
  9765. {
  9766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9767. }
  9768. }
  9769. 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
  9770. {
  9771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9772. }
  9773. }
  9774. else
  9775. {
  9776. //replace reservation
  9777. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9779. }
  9780. }
  9781. }// END FOR GB_QUANTITY
  9782. }
  9783. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9784. {
  9785. tempIndex = connectorIdInt -1;
  9786. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9787. {
  9788. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9789. {
  9790. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9791. {
  9792. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9793. 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
  9794. {
  9795. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9796. {
  9797. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9799. }
  9800. 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'))
  9801. {
  9802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9803. }
  9804. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9805. {
  9806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9807. }
  9808. else
  9809. {
  9810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9811. }
  9812. }
  9813. 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
  9814. {
  9815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9816. }
  9817. }
  9818. else
  9819. {
  9820. //replace reservation
  9821. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9823. }
  9824. }
  9825. }// END FOR GB_QUANTITY
  9826. }
  9827. else
  9828. {
  9829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9830. {
  9831. tempIndex = 2;
  9832. }
  9833. else
  9834. {
  9835. tempIndex = (connectorIdInt -1);
  9836. }
  9837. for (int index = 0; index < AC_QUANTITY; index++)
  9838. {
  9839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9840. {
  9841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9842. {
  9843. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9844. {
  9845. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9846. {
  9847. 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))
  9848. {
  9849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9850. }
  9851. else
  9852. {
  9853. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9855. }
  9856. }
  9857. 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'))
  9858. {
  9859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9860. }
  9861. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9862. {
  9863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9864. }
  9865. else
  9866. {
  9867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9868. }
  9869. }
  9870. 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
  9871. {
  9872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9873. }
  9874. }
  9875. else
  9876. {
  9877. //replace reservation
  9878. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9880. }
  9881. }
  9882. } // END FOR AC_QUANTITY
  9883. }
  9884. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9885. }
  9886. else if(connectorIdInt == 0)
  9887. {
  9888. //check Transaction active
  9889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9890. {
  9891. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9892. {
  9893. 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'))
  9894. {
  9895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9896. goto end;
  9897. }
  9898. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9899. {
  9900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9901. goto end;
  9902. }
  9903. 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
  9904. {
  9905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9906. goto end;
  9907. }
  9908. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9909. {
  9910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9911. goto end;
  9912. }
  9913. }
  9914. }// END FOR CHAdeMO_QUANTITY
  9915. for (int index = 0; index < CCS_QUANTITY; index++)
  9916. {
  9917. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9918. {
  9919. 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'))
  9920. {
  9921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9922. goto end;
  9923. }
  9924. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9925. {
  9926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9927. goto end;
  9928. }
  9929. 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
  9930. {
  9931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9932. goto end;
  9933. }
  9934. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9935. {
  9936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9937. goto end;
  9938. }
  9939. }
  9940. } // END FOR CCS_QUANTITY
  9941. for (int index = 0; index < GB_QUANTITY; index++)
  9942. {
  9943. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9944. {
  9945. 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'))
  9946. {
  9947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9948. goto end;
  9949. }
  9950. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9951. {
  9952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9953. goto end;
  9954. }
  9955. 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
  9956. {
  9957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9958. goto end;
  9959. }
  9960. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9961. {
  9962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9963. goto end;
  9964. }
  9965. }
  9966. } // END FOR GB_QUANTITY
  9967. for (int index = 0; index < AC_QUANTITY; index++)
  9968. {
  9969. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9970. {
  9971. 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'))
  9972. {
  9973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9974. goto end;
  9975. }
  9976. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9977. {
  9978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9979. goto end;
  9980. }
  9981. 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
  9982. {
  9983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9984. goto end;
  9985. }
  9986. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9987. {
  9988. 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))
  9989. {
  9990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9991. goto end;
  9992. }
  9993. }
  9994. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9995. {
  9996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9997. goto end;
  9998. }
  9999. }
  10000. }// END FOR AC_QUANTITY
  10001. //The connectorId is 0
  10002. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10004. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10005. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10006. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10007. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10008. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10009. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10010. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10011. result = TRUE;
  10012. return result;
  10013. }
  10014. else
  10015. {
  10016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10017. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10018. }
  10019. if(strcmp(comfirmstr,"Accepted") == 0)
  10020. {
  10021. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10022. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10023. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10024. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10025. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10026. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10027. result = TRUE;
  10028. return result;
  10029. }
  10030. end:
  10031. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10032. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10033. return result;
  10034. }
  10035. int handleResetRequest(char *uuid, char *payload)
  10036. {
  10037. mtrace();
  10038. int result = FAIL;
  10039. char sstr[10]={0},sstrtemp[30]={ 0 };
  10040. char typestr[10]={0};
  10041. char comfirmstr[20]={0};
  10042. int c = 0;
  10043. char *loc;
  10044. DEBUG_INFO("handleResetRequest...\n");
  10045. strcpy(sstrtemp, stringtrimspace(payload));
  10046. loc = strstr(sstrtemp, "type");
  10047. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10048. c = 0;
  10049. while (loc[3+strlen("type")+c] != '\"')
  10050. {
  10051. sstr[c] = loc[3+strlen("type")+c];
  10052. c++;
  10053. }
  10054. sstr[c] = '\0';
  10055. strcpy(typestr,sstr);
  10056. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10057. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10058. {
  10059. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10060. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10061. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10062. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10063. }
  10064. else
  10065. {
  10066. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10067. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10068. result = PASS;
  10069. }
  10070. sendResetConfirmation(uuid, comfirmstr);
  10071. return result;
  10072. }
  10073. int handleSendLocalListRequest(char *uuid, char *payload)
  10074. {
  10075. mtrace();
  10076. int result = FAIL;
  10077. char comfirmstr[20];
  10078. int checkState_Faulted = FALSE;
  10079. json_object *SendLocalList;
  10080. DEBUG_INFO("handleSendLocalListRequest...\n");
  10081. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10082. {
  10083. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10084. goto end;
  10085. }
  10086. //check Charge Point state
  10087. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10088. {
  10089. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10090. {
  10091. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10092. }
  10093. }
  10094. for (int index = 0; index < CCS_QUANTITY; index++)
  10095. {
  10096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10097. {
  10098. checkState_Faulted = TRUE; //OCPP Status
  10099. }
  10100. }
  10101. for (int index = 0; index < GB_QUANTITY; index++)
  10102. {
  10103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10104. {
  10105. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10106. }
  10107. }
  10108. //check Charge Point state
  10109. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10110. {
  10111. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10112. {
  10113. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10114. }
  10115. }
  10116. //check Charge Point state
  10117. for (int index = 0; index < AC_QUANTITY; index++)
  10118. {
  10119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10120. {
  10121. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10122. }
  10123. }
  10124. if(checkState_Faulted == TRUE)
  10125. {
  10126. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10127. goto end;
  10128. }
  10129. // Parsing payload
  10130. SendLocalList = json_tokener_parse(payload);
  10131. if(!is_error(SendLocalList))
  10132. {
  10133. // Required data
  10134. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10135. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10136. // Optional data
  10137. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10138. {
  10139. //Check UpdateType
  10140. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10141. {
  10142. //Local list full update
  10143. DEBUG_INFO("Local list full update.\n");
  10144. OCPP_getListVerion();
  10145. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10146. {
  10147. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10148. goto end;
  10149. }
  10150. OCPP_cleanLocalList();
  10151. }
  10152. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10153. {
  10154. //Local list different update
  10155. DEBUG_INFO("Local list different update.\n");
  10156. OCPP_getListVerion();
  10157. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10158. {
  10159. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10160. goto end;
  10161. }
  10162. }
  10163. else
  10164. {
  10165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10166. goto end;
  10167. }
  10168. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10169. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10170. {
  10171. 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")));
  10172. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10173. {
  10174. 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")));
  10175. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10176. 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")));
  10177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10178. 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")));
  10179. }
  10180. // Add to db
  10181. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10182. {
  10183. //Local list full update
  10184. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10185. idx,
  10186. ShmOCPP16Data->SendLocalList.ListVersion,
  10187. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10188. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10189. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10191. // update list
  10192. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10193. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10194. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10195. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10197. }
  10198. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10199. {
  10200. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10201. idx,
  10202. ShmOCPP16Data->SendLocalList.ListVersion,
  10203. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10204. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10207. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10208. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10209. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10212. }
  10213. }
  10214. }
  10215. else
  10216. {
  10217. //Check UpdateType
  10218. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10219. {
  10220. //Local list full update
  10221. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10222. OCPP_cleanLocalList();
  10223. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10224. goto end;
  10225. }
  10226. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10227. {
  10228. //Local list different update
  10229. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10230. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10231. goto end;
  10232. }
  10233. }
  10234. result = PASS;
  10235. }
  10236. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10237. end:
  10238. json_object_put(SendLocalList);
  10239. sendSendLocalListConfirmation(uuid, comfirmstr);
  10240. return result;
  10241. }
  10242. #define MAX 200
  10243. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10244. {
  10245. mtrace();
  10246. int result = FAIL;
  10247. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10248. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10249. char chargingProfilePurposeStr[30]={0};
  10250. char chargingProfileKindStr[16]={0};
  10251. char recurrencyKindStr[10]={0};
  10252. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10253. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10254. int chargingSchedulePeriodCount = 0;
  10255. char comfirmstr[20]={0};
  10256. int meet= FALSE;
  10257. FILE *fptr1;
  10258. char filename[MAX]={0};
  10259. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10260. char rmFileCmd[50]={0};
  10261. char tempchargingProfilePurposeStr[30]={0};
  10262. char word[1600]={0};
  10263. int n_chargingProfile = 0;
  10264. json_object *SetChargingProfile;
  10265. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10266. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10267. SetChargingProfile = json_tokener_parse(payload);
  10268. if(!is_error(SetChargingProfile))
  10269. {
  10270. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10271. {
  10272. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10273. if(connectorIdInt == 0)
  10274. {
  10275. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10276. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10277. }
  10278. else
  10279. {
  10280. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10281. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10282. }
  10283. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10284. }
  10285. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10286. {
  10287. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10288. {
  10289. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10290. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10291. {
  10292. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10293. }
  10294. else
  10295. {
  10296. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10297. }
  10298. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10299. }
  10300. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10301. {
  10302. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10303. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10304. {
  10305. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10306. }
  10307. else
  10308. {
  10309. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10310. }
  10311. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10312. }
  10313. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10314. {
  10315. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10316. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10317. {
  10318. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10319. }
  10320. else
  10321. {
  10322. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10323. }
  10324. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10325. }
  10326. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10327. {
  10328. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10329. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10330. {
  10331. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10332. }
  10333. else
  10334. {
  10335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10336. }
  10337. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10338. }
  10339. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10340. {
  10341. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10342. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10343. {
  10344. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10345. }
  10346. else
  10347. {
  10348. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10349. }
  10350. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10351. }
  10352. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10353. {
  10354. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10355. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10356. {
  10357. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10358. }
  10359. else
  10360. {
  10361. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10362. }
  10363. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10364. }
  10365. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10366. {
  10367. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10368. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10369. {
  10370. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10371. }
  10372. else
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10375. }
  10376. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10377. }
  10378. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10379. {
  10380. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10382. {
  10383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10384. }
  10385. else
  10386. {
  10387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10388. }
  10389. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10390. }
  10391. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10392. {
  10393. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10394. {
  10395. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10397. {
  10398. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10399. }
  10400. else
  10401. {
  10402. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10403. }
  10404. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10405. }
  10406. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10407. {
  10408. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10409. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10410. {
  10411. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10412. }
  10413. else
  10414. {
  10415. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10416. }
  10417. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10418. }
  10419. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10420. {
  10421. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10422. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10423. {
  10424. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10425. }
  10426. else
  10427. {
  10428. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10429. }
  10430. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10431. }
  10432. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10433. {
  10434. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10436. {
  10437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10438. }
  10439. else
  10440. {
  10441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10442. }
  10443. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10444. }
  10445. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10446. {
  10447. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10448. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10449. if(chargingSchedulePeriodCount <= 10)
  10450. {
  10451. 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++)
  10452. {
  10453. 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)
  10454. {
  10455. 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"));
  10456. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10457. {
  10458. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10459. }
  10460. else
  10461. {
  10462. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10463. }
  10464. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10465. }
  10466. 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)
  10467. {
  10468. 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"));
  10469. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10470. {
  10471. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10472. }
  10473. else
  10474. {
  10475. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10476. }
  10477. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10478. }
  10479. 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)
  10480. {
  10481. 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"));
  10482. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10483. {
  10484. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10485. }
  10486. else
  10487. {
  10488. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10489. }
  10490. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10491. }
  10492. }
  10493. }
  10494. }
  10495. }
  10496. }
  10497. }
  10498. json_object_put(SetChargingProfile);
  10499. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10500. {
  10501. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10502. goto end;
  10503. }
  10504. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10505. {
  10506. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10507. if(connectorIdInt != 0)
  10508. {
  10509. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10510. goto end;
  10511. }
  10512. strcpy(filename, ChargePointMaxProfile_JSON );
  10513. fptr1 = fopen(filename, "r");
  10514. if (!fptr1)
  10515. {
  10516. //file not exist
  10517. DEBUG_INFO("Unable to open the input file!!\n");
  10518. fptr1 = fopen(filename, "w+");
  10519. }
  10520. else
  10521. {
  10522. //Check Charging Profile Count
  10523. while(fscanf(fptr1, "%s", word) != EOF)
  10524. {
  10525. //DEBUG_INFO("word=%s\n",word);
  10526. if(strstr(word, "chargingProfileId")!= NULL)
  10527. {
  10528. //DEBUG_INFO("test chargingProfileId \n");
  10529. n_chargingProfile = n_chargingProfile + 1;
  10530. //DEBUG_INFO("chargingProfileId Found\n");
  10531. }
  10532. }
  10533. }
  10534. fclose(fptr1);
  10535. }
  10536. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10537. {
  10538. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10539. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10540. {
  10541. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10542. goto end;
  10543. }
  10544. memset(filename, 0, ARRAY_SIZE(filename));
  10545. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10546. fptr1 = fopen(filename, "r");
  10547. if (!fptr1)
  10548. {
  10549. //file not exist
  10550. //DEBUG_INFO("Unable to open the input file!!\n");
  10551. fptr1 = fopen(filename, "w+");
  10552. }
  10553. else
  10554. {
  10555. //Check Charging Profile Count
  10556. while(fscanf(fptr1, "%s", word) != EOF)
  10557. {
  10558. //DEBUG_INFO("word=%s\n",word);
  10559. if(strstr(word, "chargingProfileId")!= NULL)
  10560. {
  10561. //DEBUG_INFO("test chargingProfileId \n");
  10562. n_chargingProfile = n_chargingProfile + 1;
  10563. //DEBUG_INFO("chargingProfileId Found\n");
  10564. }
  10565. }
  10566. }
  10567. fclose(fptr1);
  10568. }
  10569. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10570. {
  10571. //printf("set chargingProfile 1-4\n");
  10572. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10573. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10574. if(connectorIdInt == 0)
  10575. {
  10576. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10577. goto end;
  10578. }
  10579. int tempIndex = 0;
  10580. //check Transaction active
  10581. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10582. {
  10583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10584. {
  10585. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10586. }
  10587. else
  10588. {
  10589. tempIndex = connectorIdInt -1;
  10590. }
  10591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10592. {
  10593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10594. {
  10595. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10596. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10597. {
  10598. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10599. {
  10600. meet = TRUE;
  10601. break;
  10602. }
  10603. }
  10604. }
  10605. }
  10606. }
  10607. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10608. {
  10609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10610. {
  10611. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10612. }
  10613. else
  10614. {
  10615. tempIndex = connectorIdInt -1;
  10616. }
  10617. for (int index = 0; index < CCS_QUANTITY; index++)
  10618. {
  10619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10620. {
  10621. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10622. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10623. {
  10624. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10625. {
  10626. meet = TRUE;
  10627. break;
  10628. }
  10629. }
  10630. }
  10631. }
  10632. }
  10633. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10634. {
  10635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10636. {
  10637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10638. }
  10639. else
  10640. {
  10641. tempIndex = connectorIdInt -1;
  10642. }
  10643. for (int index = 0; index < GB_QUANTITY; index++)
  10644. {
  10645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10646. {
  10647. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10648. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10649. {
  10650. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10651. {
  10652. meet = TRUE;
  10653. break;
  10654. }
  10655. }
  10656. }
  10657. }
  10658. }
  10659. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10660. {
  10661. tempIndex = connectorIdInt -1;
  10662. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10663. {
  10664. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10665. {
  10666. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10667. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.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
  10679. {
  10680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10681. {
  10682. tempIndex = 2;
  10683. }
  10684. else
  10685. {
  10686. tempIndex = (connectorIdInt -1);
  10687. }
  10688. for (int index = 0; index < AC_QUANTITY; index++)
  10689. {
  10690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10691. {
  10692. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10693. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10694. {
  10695. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10696. {
  10697. meet = TRUE;
  10698. break;
  10699. }
  10700. }
  10701. }
  10702. }
  10703. }
  10704. //check Transaction active
  10705. if(meet == FALSE)
  10706. {
  10707. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10708. goto end;
  10709. }
  10710. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10711. {
  10712. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10713. goto end;
  10714. }
  10715. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10716. fptr1 = fopen(filename, "r");
  10717. if (!fptr1)
  10718. {
  10719. //file not exist
  10720. DEBUG_INFO("Unable to open the input file!!\n");
  10721. fptr1 = fopen(filename, "w+");
  10722. }
  10723. else
  10724. {
  10725. //Check Charging Profile Count
  10726. while(fscanf(fptr1, "%s", word) != EOF)
  10727. {
  10728. //DEBUG_INFO("word=%s\n",word);
  10729. if(strstr(word, "chargingProfileId")!= NULL)
  10730. {
  10731. //DEBUG_INFO("test chargingProfileId \n");
  10732. n_chargingProfile = n_chargingProfile + 1;
  10733. //DEBUG_INFO("chargingProfileId Found\n");
  10734. }
  10735. }
  10736. }
  10737. fclose(fptr1);
  10738. }
  10739. // Check ChargeProfileMaxStackLevel
  10740. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10741. {
  10742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10743. goto end;
  10744. }
  10745. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10746. {
  10747. int i = 0;
  10748. char fnametemp[200]={0};
  10749. n_chargingProfile = 0;
  10750. //Check ChargePointMaxProfile.json exit
  10751. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10752. {
  10753. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10754. //Check Charging Profile Count
  10755. while(fscanf(fptr1, "%s", word) != EOF)
  10756. {
  10757. //DEBUG_INFO("word=%s\n",word);
  10758. if(strstr(word, "chargingProfileId")!= NULL)
  10759. {
  10760. //DEBUG_INFO("test chargingProfileId \n");
  10761. n_chargingProfile = n_chargingProfile + 1;
  10762. i = i + 1;
  10763. //DEBUG_INFO("chargingProfileId Found\n");
  10764. }
  10765. memset(word, 0, ARRAY_SIZE(word));
  10766. }
  10767. fclose(fptr1);
  10768. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10769. }
  10770. //Check TxDefaultProfile_0.json exit
  10771. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10772. {
  10773. i = 0;
  10774. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10775. //Check Charging Profile Count
  10776. while(fscanf(fptr1, "%s", word) != EOF)
  10777. {
  10778. //DEBUG_INFO("word=%s\n",word);
  10779. if(strstr(word, "chargingProfileId")!= NULL)
  10780. {
  10781. //DEBUG_INFO("test chargingProfileId \n");
  10782. n_chargingProfile = n_chargingProfile + 1;
  10783. i = i + 1;
  10784. //DEBUG_INFO("chargingProfileId Found\n");
  10785. }
  10786. memset(word, 0, ARRAY_SIZE(word));
  10787. }
  10788. fclose(fptr1);
  10789. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10790. }
  10791. //Check TxDefaultProfile_%d.json
  10792. for(int j=1; j <= gunTotalNumber; j++)
  10793. {
  10794. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10795. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10796. if((access(fnametemp,F_OK))!=-1)
  10797. {
  10798. i = 0;
  10799. fptr1 = fopen(fnametemp, "r");
  10800. //Check Charging Profile Count
  10801. while(fscanf(fptr1, "%s", word) != EOF)
  10802. {
  10803. //DEBUG_INFO("word=%s\n",word);
  10804. if(strstr(word, "chargingProfileId")!= NULL)
  10805. {
  10806. //DEBUG_INFO("test chargingProfileId \n");
  10807. n_chargingProfile = n_chargingProfile + 1;
  10808. i = i + 1;
  10809. //DEBUG_INFO("chargingProfileId Found\n");
  10810. }
  10811. memset(word, 0, ARRAY_SIZE(word));
  10812. }
  10813. fclose(fptr1);
  10814. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10815. }
  10816. }
  10817. //Check TxProfile_%d.json
  10818. for(int j=1; j <= gunTotalNumber; j++)
  10819. {
  10820. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10821. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10822. if((access(fnametemp,F_OK))!=-1)
  10823. {
  10824. i = 0;
  10825. fptr1 = fopen(fnametemp, "r");
  10826. //Check Charging Profile Count
  10827. while(fscanf(fptr1, "%s", word) != EOF)
  10828. {
  10829. //DEBUG_INFO("word=%s\n",word);
  10830. if(strstr(word, "chargingProfileId")!= NULL)
  10831. {
  10832. //DEBUG_INFO("test chargingProfileId \n");
  10833. n_chargingProfile = n_chargingProfile + 1;
  10834. i = i + 1;
  10835. //DEBUG_INFO("chargingProfileId Found\n");
  10836. }
  10837. memset(word, 0, ARRAY_SIZE(word));
  10838. }
  10839. fclose(fptr1);
  10840. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10841. }
  10842. }
  10843. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10844. {
  10845. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10846. goto end;
  10847. }
  10848. }
  10849. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10850. //**********************************Write to File********************************************************/
  10851. FILE *infile;
  10852. FILE *outfile;
  10853. infile = fopen (filename, "r");
  10854. outfile = fopen (tempfile, "w");
  10855. int d =0;
  10856. d = fgetc(infile);
  10857. rewind(infile);
  10858. if(d == EOF)
  10859. {
  10860. // Profile is empty
  10861. fprintf(outfile,"%s\n",payload);
  10862. fclose(infile);
  10863. fclose(outfile);
  10864. sprintf(rmFileCmd,"rm -f %s",filename);
  10865. system(rmFileCmd);
  10866. rename(tempfile, filename);
  10867. }
  10868. else
  10869. {
  10870. // Profile is not empty
  10871. char buf[2048]={0};
  10872. int ChargingProfileAdded = FALSE;
  10873. while (fgets(buf, sizeof(buf), infile) != NULL)
  10874. {
  10875. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10876. json_object *tmpChargingProfile;
  10877. tmpChargingProfile = json_tokener_parse(buf);
  10878. if(!is_error(SetChargingProfile))
  10879. {
  10880. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10881. {
  10882. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10883. }
  10884. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10885. {
  10886. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10887. {
  10888. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10889. }
  10890. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10891. {
  10892. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10893. }
  10894. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10895. {
  10896. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10897. }
  10898. }
  10899. }
  10900. json_object_put(tmpChargingProfile);
  10901. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10902. {
  10903. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10904. {
  10905. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10906. if(ChargingProfileAdded == FALSE)
  10907. {
  10908. fprintf(outfile,"%s\n",payload);
  10909. ChargingProfileAdded = TRUE;
  10910. }
  10911. }
  10912. else
  10913. {
  10914. if(tempstackLevelInt < stackLevelInt)
  10915. {
  10916. if(ChargingProfileAdded == FALSE)
  10917. {
  10918. fprintf(outfile,"%s\n",buf);
  10919. fprintf(outfile,"%s\n",payload);
  10920. ChargingProfileAdded = TRUE;
  10921. }
  10922. else
  10923. {
  10924. fprintf(outfile,"%s\n",buf);
  10925. }
  10926. }
  10927. else
  10928. {
  10929. if(ChargingProfileAdded == FALSE)
  10930. {
  10931. fprintf(outfile,"%s\n",buf);
  10932. fprintf(outfile,"%s\n",payload);
  10933. ChargingProfileAdded = TRUE;
  10934. }
  10935. else
  10936. {
  10937. fprintf(outfile,"%s\n",buf);
  10938. }
  10939. }
  10940. }
  10941. }
  10942. else
  10943. {
  10944. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10945. {
  10946. if(ChargingProfileAdded == FALSE)
  10947. {
  10948. fprintf(outfile,"%s\n",buf);
  10949. fprintf(outfile,"%s\n",payload);
  10950. ChargingProfileAdded = TRUE;
  10951. }
  10952. else
  10953. {
  10954. fprintf(outfile,"%s\n",buf);
  10955. }
  10956. }
  10957. else if(tempstackLevelInt < stackLevelInt)
  10958. {
  10959. if(ChargingProfileAdded == FALSE)
  10960. {
  10961. fprintf(outfile,"%s\n",buf);
  10962. fprintf(outfile,"%s\n",payload);
  10963. ChargingProfileAdded = TRUE;
  10964. }
  10965. else
  10966. {
  10967. fprintf(outfile,"%s\n",buf);
  10968. }
  10969. }
  10970. else
  10971. {
  10972. if(ChargingProfileAdded == FALSE)
  10973. {
  10974. fprintf(outfile,"%s\n",buf);
  10975. fprintf(outfile,"%s\n",payload);
  10976. ChargingProfileAdded = TRUE;
  10977. }
  10978. else
  10979. {
  10980. fprintf(outfile,"%s\n",buf);
  10981. }
  10982. }
  10983. }
  10984. } // end of while loop
  10985. fclose(infile);
  10986. fclose(outfile);
  10987. sprintf(rmFileCmd,"rm -f %s",filename);
  10988. system(rmFileCmd);
  10989. rename(tempfile, filename);
  10990. }
  10991. sleep(1);
  10992. result = TRUE;
  10993. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10994. end:
  10995. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10996. {
  10997. if(connectorIdInt == 0)
  10998. {
  10999. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11000. {
  11001. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11002. }
  11003. }
  11004. else
  11005. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11006. }
  11007. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11008. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11009. return result;
  11010. }
  11011. int handleTriggerMessageRequest(char *uuid, char *payload)
  11012. {
  11013. mtrace();
  11014. int result = FAIL;
  11015. int connectorIdIsNULL = FALSE;
  11016. int connectorIdInt =0;
  11017. char sstr[40]={0},sstrtemp[100]={ 0 };
  11018. char requestedMessagestr[40]={0};
  11019. char comfirmstr[20]={0};
  11020. int c = 0;
  11021. char *loc;
  11022. DEBUG_INFO("handleTriggerMessageRequest\n");
  11023. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11024. strcpy(sstrtemp, stringtrimspace(payload));
  11025. c = 0;
  11026. loc = strstr(sstrtemp, "requestedMessage");
  11027. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11028. {
  11029. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11030. c++;
  11031. }
  11032. sstr[c] = '\0';
  11033. strcpy(requestedMessagestr, sstr);
  11034. c = 0;
  11035. loc = strstr(sstrtemp, "connectorId");
  11036. if(loc == NULL)
  11037. {
  11038. connectorIdIsNULL = TRUE;
  11039. }
  11040. else
  11041. {
  11042. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11043. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11044. {
  11045. sstr[c] = loc[strlen("connectorId")+2+c];
  11046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11047. c++;
  11048. }
  11049. sstr[c] = '\0';
  11050. connectorIdInt = atoi(sstr);
  11051. }
  11052. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11053. {
  11054. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11055. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11056. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11057. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11058. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11059. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11060. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11061. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11062. {
  11063. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11064. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11065. return TRUE;
  11066. }
  11067. else
  11068. {
  11069. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11070. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11071. }
  11072. }
  11073. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11074. {
  11075. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11076. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11077. return TRUE;
  11078. }
  11079. //==========================
  11080. // Trigger message
  11081. //==========================
  11082. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11083. {
  11084. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11085. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11086. {
  11087. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11088. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11089. }
  11090. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11091. }
  11092. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11093. {
  11094. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11095. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11096. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11097. }
  11098. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11099. {
  11100. //sendBootNotificationRequest();
  11101. server_sign = FALSE;
  11102. }
  11103. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11104. {
  11105. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11106. }
  11107. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11108. {
  11109. if(connectorIdIsNULL == FALSE)
  11110. {
  11111. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11112. {
  11113. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11114. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11115. }
  11116. }
  11117. else
  11118. {
  11119. for(int idx=0;idx< gunTotalNumber;idx++)
  11120. {
  11121. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11122. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11123. }
  11124. }
  11125. }
  11126. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11127. {
  11128. if(connectorIdIsNULL == FALSE)
  11129. {
  11130. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11131. {
  11132. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11133. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11134. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11135. }
  11136. }
  11137. else
  11138. {
  11139. for(int idx=0;idx< gunTotalNumber;idx++)
  11140. {
  11141. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11142. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11143. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11144. }
  11145. }
  11146. }
  11147. return result;
  11148. }
  11149. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11150. {
  11151. mtrace();
  11152. int result = FAIL;
  11153. int connectorIdInt =0;
  11154. char comfirmstr[20]={0};
  11155. int tempIndex = 0;
  11156. json_object *UnlockConnector;
  11157. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11158. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11159. UnlockConnector = json_tokener_parse(payload);
  11160. if(!is_error(UnlockConnector))
  11161. {
  11162. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11163. {
  11164. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11165. }
  11166. }
  11167. json_object_put(UnlockConnector);
  11168. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11169. if(gunTotalNumber == 0)
  11170. {
  11171. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11172. goto end;
  11173. }
  11174. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11175. {
  11176. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11177. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11178. goto end;
  11179. }
  11180. else
  11181. {
  11182. //check Transaction active
  11183. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11184. {
  11185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11186. {
  11187. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11188. }
  11189. else
  11190. {
  11191. tempIndex = connectorIdInt -1;
  11192. }
  11193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11194. {
  11195. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11196. {
  11197. //stop Transaction
  11198. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11199. }
  11200. }
  11201. }
  11202. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  11213. {
  11214. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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_GBT)
  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 < GB_QUANTITY; index++)
  11232. {
  11233. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[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_DO)
  11241. {
  11242. tempIndex = connectorIdInt -1;
  11243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11244. {
  11245. 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)))
  11246. {
  11247. //stop Transaction
  11248. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11249. }
  11250. }
  11251. }
  11252. else
  11253. {
  11254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11255. {
  11256. tempIndex = 2;
  11257. }
  11258. else
  11259. {
  11260. tempIndex = connectorIdInt-1;
  11261. }
  11262. for (int index = 0; index < AC_QUANTITY; index++)
  11263. {
  11264. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11265. {
  11266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11267. }
  11268. }
  11269. }
  11270. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11271. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11272. result = TRUE;
  11273. return result;
  11274. }
  11275. end:
  11276. //json_object_put(obj); --- remove temporally
  11277. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11278. return result;
  11279. }
  11280. static char UpdateFirmwarepayloadData[300]={0};
  11281. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11282. {
  11283. mtrace();
  11284. int result = FAIL;
  11285. pthread_t t;
  11286. sendUpdateFirmwareConfirmation(uuid);
  11287. memset(UpdateFirmwarepayloadData, 0, 300);
  11288. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11289. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11290. ////pthread_join(t, NULL); //
  11291. //pthread_detach(t);
  11292. //sendUpdateFirmwareConfirmation(uuid);
  11293. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11294. return result;
  11295. }
  11296. void *UpdateFirmwareProcess(void *data)
  11297. {
  11298. pthread_detach(pthread_self());
  11299. mtrace();
  11300. int retriesInt =0, retryIntervalInt=0;
  11301. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11302. int port=0;
  11303. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11304. int isSuccess = 0;
  11305. char ftpbuf[1024];
  11306. char temp[1024];
  11307. char * pch;
  11308. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11309. json_object *UpdateFirmware;
  11310. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11311. if(!is_error(UpdateFirmware))
  11312. {
  11313. // Required data
  11314. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11315. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11316. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11317. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11318. // Optional data
  11319. if(json_object_object_get(UpdateFirmware, "retries"))
  11320. {
  11321. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11322. }
  11323. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11324. {
  11325. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11326. }
  11327. }
  11328. json_object_put(UpdateFirmware);
  11329. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11330. memset(path, 0, ARRAY_SIZE(path));
  11331. // Wait retrieveData
  11332. if(strlen(retrieveDatestr) > 10)
  11333. {
  11334. do
  11335. {
  11336. sleep(1);
  11337. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11338. }
  11339. // Ready to download
  11340. system("rm -f /mnt/*");
  11341. if(strncmp(locationstr,"http", 4) == 0)
  11342. {
  11343. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11344. sprintf(ftppath,"/%s", path);
  11345. DEBUG_INFO("locationstr: %s\n", locationstr);
  11346. DEBUG_INFO("protocol: %s\n",protocol);
  11347. DEBUG_INFO("host: %s\n",host);
  11348. DEBUG_INFO("path: %s\n",path);
  11349. DEBUG_INFO("ftppath: %s\n",ftppath);
  11350. int ftppathlen=strlen(ftppath);
  11351. int i=1;
  11352. char filenametemp[50];
  11353. while(i < ftppathlen)
  11354. {
  11355. int len=ftppathlen-i;
  11356. if(ftppath[len]== 47) // '/' ascll code: 47
  11357. {
  11358. DEBUG_INFO("compare '/' all right\n");
  11359. break;
  11360. }
  11361. i=i+1;
  11362. }
  11363. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11364. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11365. filenametemp[i+1] = 0;
  11366. do
  11367. {
  11368. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11369. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11370. sleep(1);
  11371. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11372. if(!isSuccess)
  11373. {
  11374. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11375. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11376. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11377. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11378. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11379. }
  11380. else
  11381. {
  11382. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11383. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11384. }
  11385. retriesInt--;
  11386. }while((isSuccess == 0)&&(retriesInt >= 0));
  11387. }
  11388. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11389. {
  11390. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11391. memset(temp, 0, ARRAY_SIZE(temp));
  11392. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11393. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11394. int ftppathlen=strlen(ftpbuf);
  11395. int i=1;
  11396. char filenametemp[50];
  11397. while(i < ftppathlen)
  11398. {
  11399. int len=ftppathlen-i;
  11400. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11401. {
  11402. DEBUG_INFO(" compare '/' all right\n");
  11403. break;
  11404. }
  11405. i=i+1;
  11406. }
  11407. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11408. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11409. filenametemp[i+1] = 0;
  11410. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11411. pch=strchr(temp,'@');
  11412. if(pch==NULL)
  11413. {
  11414. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11415. protocol, host, &port, path);
  11416. strcpy(user,"anonymous");
  11417. strcpy(password,"");
  11418. }
  11419. else
  11420. {
  11421. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11422. protocol, user, password, host, &port, path);
  11423. }
  11424. sscanf(host,"%[^/]%s",host1, path1);
  11425. sprintf(ftppath,"%s", path1);
  11426. //DEBUG_INFO("protocol =%s\n",protocol);
  11427. //DEBUG_INFO("user =%s\n",user);
  11428. //DEBUG_INFO("password =%s\n",password);
  11429. //DEBUG_INFO("host1 =%s\n",host1);
  11430. //DEBUG_INFO("port =%d\n",port);
  11431. //DEBUG_INFO("path1 =%s\n",path1);
  11432. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11433. //ftpFile(host, user, password, port, ftppath, fname);
  11434. //download firmware pthred
  11435. if(port == 0)
  11436. {
  11437. port = 21;
  11438. }
  11439. do
  11440. {
  11441. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11442. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11443. sleep(1);
  11444. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11445. if(!isSuccess)
  11446. {
  11447. //BulldogUtil.sleepMs(interval*1000);
  11448. DEBUG_INFO("Update firmware request and download file fail.\n");
  11449. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11450. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11451. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11452. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11453. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11454. }
  11455. else
  11456. {
  11457. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11458. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11459. }
  11460. retriesInt--;
  11461. }while((!isSuccess)&&(retriesInt >= 0));
  11462. }
  11463. else
  11464. {
  11465. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11466. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11467. sleep(1);
  11468. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11469. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11470. }
  11471. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11472. pthread_exit(NULL);
  11473. }
  11474. int handleCertificateSignedRequest(char *uuid, char *payload)
  11475. {
  11476. mtrace();
  11477. int result = PASS;
  11478. json_object *CertificateSigned;
  11479. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11480. CertificateSigned = json_tokener_parse(payload);
  11481. if(!is_error(CertificateSigned))
  11482. {
  11483. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11484. }
  11485. json_object_put(CertificateSigned);
  11486. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11487. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11488. fclose(fp);
  11489. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11490. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11491. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11492. sendCertificateSignedConfirmation(uuid);
  11493. return result;
  11494. }
  11495. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11496. {
  11497. mtrace();
  11498. int result = PASS;
  11499. json_object *DeleteCertificate;
  11500. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11501. DeleteCertificate = json_tokener_parse(payload);
  11502. if(!is_error(DeleteCertificate))
  11503. {
  11504. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11505. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11506. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11507. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11508. }
  11509. json_object_put(DeleteCertificate);
  11510. /*
  11511. * TODO: Delete certificateSigned process
  11512. */
  11513. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11514. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11515. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11516. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11517. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11518. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11519. sendDeleteCertificateConfirmation(uuid);
  11520. return result;
  11521. }
  11522. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11523. {
  11524. mtrace();
  11525. int result = PASS;
  11526. json_object *ExtendedTriggerMessage;
  11527. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11528. ExtendedTriggerMessage = json_tokener_parse(payload);
  11529. if(!is_error(ExtendedTriggerMessage))
  11530. {
  11531. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11532. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11533. {
  11534. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11535. }
  11536. else
  11537. {
  11538. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11539. }
  11540. }
  11541. json_object_put(ExtendedTriggerMessage);
  11542. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11543. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11544. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11545. {
  11546. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11547. }
  11548. else
  11549. {
  11550. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11551. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11552. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11553. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11554. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11555. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11556. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11557. {
  11558. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11559. }
  11560. else
  11561. {
  11562. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11563. }
  11564. }
  11565. sendExtendedTriggerMessageConfirmation(uuid);
  11566. //==========================
  11567. // Trigger message
  11568. //==========================
  11569. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11570. {
  11571. //sendBootNotificationRequest();
  11572. server_sign = FALSE;
  11573. }
  11574. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11575. {
  11576. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11577. }
  11578. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11579. {
  11580. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11581. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11582. {
  11583. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11584. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11585. }
  11586. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11587. }
  11588. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11589. {
  11590. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11591. }
  11592. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11593. {
  11594. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11595. {
  11596. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11597. }
  11598. else
  11599. {
  11600. for(int idx=0;idx< gunTotalNumber;idx++)
  11601. {
  11602. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11603. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11604. }
  11605. }
  11606. }
  11607. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11608. {
  11609. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11610. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11611. {
  11612. 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\" &");
  11613. }
  11614. }
  11615. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11616. {
  11617. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11618. {
  11619. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11620. }
  11621. else
  11622. {
  11623. for(int idx=0;idx< gunTotalNumber;idx++)
  11624. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11625. }
  11626. }
  11627. return result;
  11628. }
  11629. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11630. {
  11631. mtrace();
  11632. int result = PASS;
  11633. json_object *GetInstalledCertificateIds;
  11634. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11635. GetInstalledCertificateIds = json_tokener_parse(payload);
  11636. if(!is_error(GetInstalledCertificateIds))
  11637. {
  11638. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11639. }
  11640. json_object_put(GetInstalledCertificateIds);
  11641. /*
  11642. * TODO: Return installed certificate process
  11643. */
  11644. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11645. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11646. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11647. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11648. sendGetInstalledCertificateIdsConfirmation(uuid);
  11649. return result;
  11650. }
  11651. int handleGetLogRequest(char *uuid, char *payload)
  11652. {
  11653. mtrace();
  11654. int result = PASS;
  11655. json_object *GetLog;
  11656. DEBUG_INFO("handleGetLogRequest...\n");
  11657. GetLog = json_tokener_parse(payload);
  11658. if(!is_error(GetLog))
  11659. {
  11660. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11661. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11662. if(json_object_object_get(GetLog, "retries") != NULL)
  11663. {
  11664. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11665. }
  11666. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11667. {
  11668. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11669. }
  11670. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11671. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11672. {
  11673. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11674. }
  11675. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11676. {
  11677. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11678. }
  11679. }
  11680. json_object_put(GetLog);
  11681. /*
  11682. * TODO: Upload log process
  11683. */
  11684. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11685. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11686. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11687. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11688. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11689. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11690. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11691. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11692. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11693. sendGetLogConfirmation(uuid);
  11694. return result;
  11695. }
  11696. int handleInstallCertificateRequest(char *uuid, char *payload)
  11697. {
  11698. mtrace();
  11699. int result = PASS;
  11700. json_object *InstallCertificate;
  11701. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11702. InstallCertificate = json_tokener_parse(payload);
  11703. if(!is_error(InstallCertificate))
  11704. {
  11705. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11706. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11707. /*
  11708. * TODO: Install certificate process
  11709. */
  11710. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11711. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11712. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11713. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11714. sendInstallCertificateConfirmation(uuid);
  11715. }
  11716. json_object_put(InstallCertificate);
  11717. return result;
  11718. }
  11719. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11720. {
  11721. mtrace();
  11722. int result = PASS;
  11723. json_object *SignedUpdateFirmware;
  11724. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11725. SignedUpdateFirmware = json_tokener_parse(payload);
  11726. if(!is_error(SignedUpdateFirmware))
  11727. {
  11728. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11729. {
  11730. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11731. }
  11732. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11733. {
  11734. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11735. }
  11736. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11737. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11738. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11739. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11740. {
  11741. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11742. }
  11743. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11744. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11745. }
  11746. json_object_put(SignedUpdateFirmware);
  11747. /*
  11748. * TODO: Upgrade firmware process
  11749. */
  11750. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11751. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11752. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11753. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11754. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11755. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11756. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11757. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11758. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11759. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11760. sendInstallCertificateConfirmation(uuid);
  11761. return result;
  11762. }
  11763. int handleUnknownRequest(char *uuid, char *payload)
  11764. {
  11765. mtrace();
  11766. int result = PASS;
  11767. DEBUG_INFO("handleUnknownRequest...\n");
  11768. sendUnknownConfirmation(uuid);
  11769. result = PASS;
  11770. return result;
  11771. }
  11772. //==========================================
  11773. // Handle server response routine
  11774. //==========================================
  11775. void handleAuthorizeResponse(char *payload, int gun_index)
  11776. {
  11777. mtrace();
  11778. char expiryDatestr[30]={0};
  11779. char parentIdTagstr[20]={0};
  11780. char statusstr[20]={0};
  11781. int expiryDateISNULL=FALSE;
  11782. int parentIdTagISNULL=FALSE;
  11783. DEBUG_INFO("handleAuthorizeResponse...\n");
  11784. json_object *Authorize;
  11785. Authorize = json_tokener_parse(payload);
  11786. if(!is_error(Authorize))
  11787. {
  11788. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11789. {
  11790. // Required data
  11791. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11792. // Optional data
  11793. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11794. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11795. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11796. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11797. }
  11798. }
  11799. json_object_put(Authorize);
  11800. if(expiryDateISNULL == FALSE)
  11801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11802. if(parentIdTagISNULL == FALSE)
  11803. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11804. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11805. //Update idTag information to authorization cache if supproted
  11806. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11807. {
  11808. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11809. }
  11810. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11811. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11812. authorizeRetryTimes = 0;
  11813. }
  11814. void handleBootNotificationResponse(char *payload, int gun_index)
  11815. {
  11816. mtrace();
  11817. char statusStr[12]={0};
  11818. char currentTimeStr[30]={0};
  11819. int intervalInt = 0;
  11820. DEBUG_INFO("handleBootNotificationResponse...\n");
  11821. json_object *BootNotification;
  11822. BootNotification = json_tokener_parse(payload);
  11823. if(!is_error(BootNotification))
  11824. {
  11825. // Required data
  11826. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11827. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11828. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11829. }
  11830. json_object_put(BootNotification);
  11831. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11832. BootNotificationInterval = intervalInt;
  11833. HeartBeatWaitTime = intervalInt;
  11834. //write back to ShmOCPP16Data->BootNotification
  11835. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11836. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11837. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11838. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11839. {
  11840. server_sign = TRUE;
  11841. server_pending =FALSE;
  11842. }
  11843. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11844. {
  11845. server_pending = TRUE;
  11846. }
  11847. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11848. srand(time(NULL));
  11849. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11850. SetOcppConnStatus(TRUE);
  11851. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11852. }
  11853. void handleDataTransferResponse(char *payload, int gun_index)
  11854. {
  11855. char sstr[160]={0};//sstr[200]={ 0 };
  11856. int c = 0;
  11857. char *loc;
  11858. DEBUG_INFO("handleDataTransferResponse ...\n");
  11859. loc = strstr(payload, "status");
  11860. c = 0;
  11861. while (loc[3+strlen("status")+c] != '\"')
  11862. {
  11863. sstr[c] = loc[3+strlen("status")+c];
  11864. c++;
  11865. }
  11866. sstr[c] = '\0';
  11867. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11868. }
  11869. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11870. {
  11871. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11872. //struct json_object *obj;
  11873. // obj = json_tokener_parse(payload);
  11874. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11875. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11876. //No fields are defined.
  11877. }
  11878. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11879. {
  11880. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11881. //struct json_object *obj;
  11882. // obj = json_tokener_parse(payload);
  11883. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11884. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11885. //No fields are defined.
  11886. }
  11887. void handleHeartbeatResponse(char *payload, int gun_index)
  11888. {
  11889. mtrace();
  11890. DEBUG_INFO("handleHeartbeatResponse...\n");
  11891. json_object *Heartbeat;
  11892. Heartbeat = json_tokener_parse(payload);
  11893. if(!is_error(Heartbeat))
  11894. {
  11895. // Required data
  11896. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11897. }
  11898. json_object_put(Heartbeat);
  11899. if(FirstHeartBeat == 0)
  11900. {
  11901. FirstHeartBeat = 1;
  11902. DEBUG_INFO("FirstHeartBeat \n");
  11903. }
  11904. HeartBeatWithNOResponse = 0;
  11905. clientTime.Heartbeat=time((time_t*)NULL);
  11906. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11907. }
  11908. void handleMeterValuesResponse(char *payload, int gun_index)
  11909. {
  11910. mtrace();
  11911. DEBUG_INFO("handleMeterValuesResponse...\n");
  11912. }
  11913. void handleStartTransactionResponse(char *payload, int gun_index)
  11914. {
  11915. mtrace();
  11916. //int transactionIdInt = 0;
  11917. FILE *outfile;
  11918. char data[100]={0};
  11919. DEBUG_INFO("handleStartTransactionResponse...\n");
  11920. json_object *StartTransaction;
  11921. StartTransaction = json_tokener_parse(payload);
  11922. if(!is_error(StartTransaction))
  11923. {
  11924. // Required data
  11925. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11926. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11927. // Optional data
  11928. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11929. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11930. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11931. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11932. }
  11933. json_object_put(StartTransaction);
  11934. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11935. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11936. //-----------Start : write to the Queue TransactionId file -----------------//
  11937. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11938. {}
  11939. else
  11940. {
  11941. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11942. if(log == NULL)
  11943. {
  11944. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11945. return ;
  11946. }
  11947. else
  11948. {
  11949. fclose(log);
  11950. }
  11951. }
  11952. // open file for writing
  11953. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11954. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11955. {
  11956. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11957. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11958. fputs(data, outfile);
  11959. fclose (outfile);
  11960. }
  11961. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11962. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11963. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11964. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11965. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11966. }
  11967. void handleStatusNotificationResponse(char *payload, int gun_index)
  11968. {
  11969. mtrace();
  11970. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11971. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11972. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11973. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11974. }
  11975. void handleStopTransactionnResponse(char *payload, int gun_index)
  11976. {
  11977. mtrace();
  11978. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11979. json_object *StopTransaction;
  11980. StopTransaction = json_tokener_parse(payload);
  11981. if(!is_error(StopTransaction))
  11982. {
  11983. // Optional data
  11984. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11985. {
  11986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11987. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11989. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11991. }
  11992. }
  11993. json_object_put(StopTransaction);
  11994. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11995. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11996. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11997. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11998. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11999. }
  12000. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12001. {
  12002. mtrace();
  12003. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12004. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12005. }
  12006. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12007. {
  12008. mtrace();
  12009. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12010. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12011. }
  12012. void handleSignCertificateResponse(char *payload, int gun_index)
  12013. {
  12014. mtrace();
  12015. DEBUG_INFO("handleSignCertificateResponse...\n");
  12016. json_object *SignCertificate;
  12017. SignCertificate = json_tokener_parse(payload);
  12018. if(!is_error(SignCertificate))
  12019. {
  12020. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12021. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12022. }
  12023. json_object_put(SignCertificate);
  12024. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12025. }
  12026. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12027. {
  12028. mtrace();
  12029. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12030. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12031. }
  12032. //==========================================
  12033. // Handle Error routine
  12034. //==========================================
  12035. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12036. {
  12037. mtrace();
  12038. #ifdef SystemLogMessage
  12039. DEBUG_INFO("errorCode: %s\n", errorCode);
  12040. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12041. DEBUG_INFO("errorDetails: %s\n", payload);
  12042. #endif
  12043. }
  12044. //===============================================
  12045. // Common routine
  12046. //===============================================
  12047. int initialConfigurationTable(void)
  12048. {
  12049. //clock_t start_t, end_t, total_t;
  12050. FILE *fp;
  12051. FILE *outfile;
  12052. char str[512]={0};
  12053. char sstr[256]={0};
  12054. int c = 0;
  12055. char *loc;
  12056. int confVersion = 5;
  12057. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12058. //start_t = clock();
  12059. //printf("Starting of the program, start_t = %ld\n", start_t);
  12060. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12061. // Check configuration file size is correct
  12062. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12063. {
  12064. struct stat st;
  12065. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12066. if(st.st_size < 3100)
  12067. {
  12068. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12069. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12070. }
  12071. }
  12072. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12073. {
  12074. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12075. if(outfile == NULL)
  12076. {
  12077. DEBUG_INFO("Error opening file\n");
  12078. return FALSE;
  12079. }
  12080. /*Core Profile*/
  12081. //AllowOfflineTxForUnknownId
  12082. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12086. //AuthorizationCacheEnabled
  12087. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12091. //AuthorizeRemoteTxRequests
  12092. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12096. //BlinkRepeat
  12097. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12101. //ClockAlignedDataInterval
  12102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12106. //ConnectionTimeOut
  12107. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12111. //GetConfigurationMaxKeys
  12112. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12116. // HeartbeatInterval
  12117. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12121. // LightIntensity
  12122. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12126. // LocalAuthorizeOffline
  12127. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12131. // LocalPreAuthorize
  12132. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12136. // MaxEnergyOnInvalidId
  12137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12141. // MeterValuesAlignedData
  12142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12146. else
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12149. // MeterValuesAlignedDataMaxLength
  12150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  12154. else
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  12156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12157. // MeterValuesSampledData
  12158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12162. else
  12163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12165. // MeterValuesSampledDataMaxLength
  12166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  12170. else
  12171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  12172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12173. // MeterValueSampleInterval
  12174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12178. // MinimumStatusDuration
  12179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12182. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12184. // NumberOfConnectors
  12185. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12188. {
  12189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12190. }
  12191. else
  12192. {
  12193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12194. }
  12195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12196. // ResetRetries
  12197. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12201. // ConnectorPhaseRotation
  12202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12206. // ConnectorPhaseRotationMaxLength
  12207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12211. // StopTransactionOnEVSideDisconnect
  12212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12216. // StopTransactionOnInvalidId
  12217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12221. // StopTxnAlignedData
  12222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12226. // StopTxnAlignedDataMaxLength
  12227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12231. // StopTxnSampledData
  12232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12236. else
  12237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12239. // StopTxnSampledDataMaxLength
  12240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12243. {
  12244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12245. }
  12246. else
  12247. {
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12249. }
  12250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12251. // SupportedFeatureProfiles
  12252. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12256. // SupportedFeatureProfilesMaxLength
  12257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12261. // TransactionMessageAttempts
  12262. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12265. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12267. // TransactionMessageRetryInterval
  12268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12271. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12273. // UnlockConnectorOnEVSideDisconnect
  12274. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12278. // WebSocketPingInterval
  12279. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12283. // QueueOffLineStartTransactionMessage
  12284. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12288. // AuthorizationKey
  12289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12293. // SecurityProfile
  12294. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12298. // DefaultPrice
  12299. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12303. // CustomDisplayCostAndPrice
  12304. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12308. // CustomIdleFeeAfterStop
  12309. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12313. // TimeOffset
  12314. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12318. // NextTimeOffsetTransitionDateTime
  12319. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12323. // TimeOffsetNextTransition
  12324. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12328. // Configuration Version
  12329. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12333. //* Local Auth List Management Profile*/
  12334. #if 0
  12335. //For OCTT Test Case
  12336. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12339. #endif
  12340. #if 1
  12341. //LocalAuthListEnabled
  12342. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12346. #endif
  12347. //LocalAuthListMaxLength
  12348. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12352. //SendLocalListMaxLength
  12353. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12357. //ReserveConnectorZeroSupported
  12358. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12362. //* Smart Charging Profile */
  12363. //ChargeProfileMaxStackLevel
  12364. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12368. // ChargingScheduleAllowedChargingRateUnit
  12369. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12373. // ChargingScheduleMaxPeriods
  12374. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12378. // ConnectorSwitch3to1PhaseSupported
  12379. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12383. // MaxChargingProfilesInstalled
  12384. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12388. fclose(outfile);
  12389. }
  12390. else
  12391. {
  12392. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12393. char keystr[60]={0};
  12394. char readonlystr[10]={0};
  12395. char valuestr[256]={0};
  12396. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12397. if(fp == NULL) {
  12398. DEBUG_INFO("Error opening file");
  12399. return FALSE;
  12400. }
  12401. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12402. {
  12403. //DEBUG_INFO("Get Configuration \n");
  12404. if(strlen(str) > 0)
  12405. {
  12406. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12407. //*************************key*********************************/
  12408. if(strstr(str, "key") != NULL)
  12409. {
  12410. loc = strstr(str, "key");
  12411. c = 0;
  12412. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12413. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12414. {
  12415. sstr[c] = loc[strlen("key")+3+c];
  12416. c++;
  12417. }
  12418. sstr[c] = '\0';
  12419. strcpy(keystr,sstr);
  12420. }
  12421. //*************************readonly*********************************/
  12422. if(strstr(str, "readonly") != NULL)
  12423. {
  12424. loc = strstr(str, "readonly");
  12425. c = 0;
  12426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12427. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12428. {
  12429. sstr[c] = loc[strlen("readonly")+2+c];
  12430. c++;
  12431. }
  12432. sstr[c] = '\0';
  12433. strcpy(readonlystr,sstr);
  12434. }
  12435. //*************************value*********************************/
  12436. if(strstr(str, "value") != NULL)
  12437. {
  12438. loc = strstr(str, "value");
  12439. c = 0;
  12440. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12441. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12442. {
  12443. sstr[c] = loc[strlen("value")+3+c];
  12444. c++;
  12445. }
  12446. sstr[c] = '\0';
  12447. strcpy(valuestr,sstr);
  12448. }
  12449. // DEBUG_INFO("keystr=%s\n",keystr);
  12450. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12451. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12452. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12453. {
  12454. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12455. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12457. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12458. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12459. }
  12460. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12461. {
  12462. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12463. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12465. }
  12466. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12467. {
  12468. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12470. }
  12471. if(strcmp(keystr, "BlinkRepeat") == 0)
  12472. {
  12473. //Charger.BlinkRepeat = Integer.parseInt(value);
  12474. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12476. }
  12477. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12478. {
  12479. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12481. }
  12482. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12483. {
  12484. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12486. }
  12487. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12488. {
  12489. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12491. }
  12492. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12493. {
  12494. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12496. HeartBeatWaitTime = atoi(valuestr);
  12497. }
  12498. if(strcmp(keystr, "LightIntensity") == 0)
  12499. {
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12502. }
  12503. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12504. {
  12505. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12507. }
  12508. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12509. {
  12510. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12512. }
  12513. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12514. {
  12515. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12517. }
  12518. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12519. {
  12520. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12522. }
  12523. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12524. {
  12525. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12527. }
  12528. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12529. {
  12530. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12532. }
  12533. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12534. {
  12535. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12537. }
  12538. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12539. {
  12540. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12542. }
  12543. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12544. {
  12545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12547. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12548. }
  12549. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12550. {
  12551. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12553. }
  12554. if(strcmp(keystr, "ResetRetries") == 0)
  12555. {
  12556. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12558. }
  12559. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12560. {
  12561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12563. }
  12564. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12565. {
  12566. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12568. }
  12569. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12570. {
  12571. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12573. }
  12574. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12575. {
  12576. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12578. }
  12579. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12580. {
  12581. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12583. }
  12584. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12585. {
  12586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12588. }
  12589. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12590. {
  12591. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12593. }
  12594. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12595. {
  12596. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12598. }
  12599. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12600. {
  12601. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12603. }
  12604. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12605. {
  12606. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12608. }
  12609. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12610. {
  12611. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12613. TransactionMessageAttemptsValue = atoi(valuestr);
  12614. }
  12615. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12616. {
  12617. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12619. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12620. }
  12621. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12622. {
  12623. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12625. }
  12626. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12627. {
  12628. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12630. }
  12631. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12632. {
  12633. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12635. }
  12636. if(strcmp(keystr, "AuthorizationKey") == 0)
  12637. {
  12638. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12639. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12641. }
  12642. if(strcmp(keystr, "SecurityProfile") == 0)
  12643. {
  12644. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12646. }
  12647. if(strcmp(keystr, "DefaultPrice") == 0)
  12648. {
  12649. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12651. }
  12652. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12653. {
  12654. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12656. }
  12657. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12658. {
  12659. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12661. }
  12662. if(strcmp(keystr, "TimeOffset") == 0)
  12663. {
  12664. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12666. }
  12667. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12668. {
  12669. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12671. }
  12672. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12673. {
  12674. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12676. }
  12677. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12678. {
  12679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12681. }
  12682. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12683. {
  12684. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12686. }
  12687. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12688. {
  12689. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12691. }
  12692. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12693. {
  12694. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12696. }
  12697. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12698. {
  12699. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12701. }
  12702. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12703. {
  12704. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12706. }
  12707. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12708. {
  12709. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12711. }
  12712. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12713. {
  12714. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12716. }
  12717. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12718. {
  12719. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12721. }
  12722. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12723. {
  12724. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12726. }
  12727. }
  12728. }
  12729. fclose(fp);
  12730. }
  12731. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12732. {
  12733. return PASS;
  12734. }
  12735. else
  12736. {
  12737. return FAIL;
  12738. }
  12739. }
  12740. void StoreConfigurationTable(void)
  12741. {
  12742. FILE *outfile;
  12743. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12744. if(outfile == NULL)
  12745. {
  12746. DEBUG_INFO("Error opening file");
  12747. return ;
  12748. }
  12749. /*Core Profile*/
  12750. //AllowOfflineTxForUnknownId
  12751. /*
  12752. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12753. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12756. */
  12757. //DEBUG_INFO("data=%s\n",data);
  12758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12759. //AuthorizationCacheEnabled
  12760. /*
  12761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12764. */
  12765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12766. //AuthorizeRemoteTxRequests
  12767. /*
  12768. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12771. */
  12772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12773. //BlinkRepeat
  12774. /*
  12775. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12778. */
  12779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12780. //ClockAlignedDataInterval
  12781. /*
  12782. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12785. */
  12786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12787. //ConnectionTimeOut
  12788. /*
  12789. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12792. */
  12793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12794. //GetConfigurationMaxKeys
  12795. /*
  12796. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12799. */
  12800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12801. // HeartbeatInterval
  12802. /*
  12803. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12806. */
  12807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12808. // LightIntensity
  12809. /*
  12810. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12813. */
  12814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12815. // LocalAuthorizeOffline
  12816. /*
  12817. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12820. */
  12821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12822. // LocalPreAuthorize
  12823. /*
  12824. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12827. */
  12828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12829. // MaxEnergyOnInvalidId
  12830. /*
  12831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12834. */
  12835. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12837. // MeterValuesAlignedData
  12838. /*
  12839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12842. */
  12843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12844. // MeterValuesAlignedDataMaxLength
  12845. /*
  12846. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12849. */
  12850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12851. // MeterValuesSampledData
  12852. /*
  12853. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12856. */
  12857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12858. // MeterValuesSampledDataMaxLength
  12859. /*
  12860. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12863. */
  12864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12865. // MeterValueSampleInterval
  12866. /*
  12867. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12870. */
  12871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12872. // MinimumStatusDuration
  12873. /*
  12874. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12877. */
  12878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12879. // NumberOfConnectors
  12880. /*
  12881. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12884. {
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12886. }
  12887. else
  12888. {
  12889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12890. }
  12891. */
  12892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12893. // ResetRetries
  12894. /*
  12895. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12898. */
  12899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12900. // ConnectorPhaseRotation
  12901. /*
  12902. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12905. */
  12906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12907. // ConnectorPhaseRotationMaxLength
  12908. /*
  12909. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12912. */
  12913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12914. // StopTransactionOnEVSideDisconnect
  12915. /*
  12916. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12919. */
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12921. // StopTransactionOnInvalidId
  12922. /*
  12923. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12926. */
  12927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12928. // StopTxnAlignedData
  12929. /*
  12930. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12933. */
  12934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12935. // StopTxnAlignedDataMaxLength
  12936. /*
  12937. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12940. */
  12941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12942. // StopTxnSampledData
  12943. /*
  12944. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12947. */
  12948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12949. // StopTxnSampledDataMaxLength
  12950. /*
  12951. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12954. */
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12956. // SupportedFeatureProfiles
  12957. /*
  12958. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12961. */
  12962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12963. // SupportedFeatureProfilesMaxLength
  12964. /*
  12965. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12968. */
  12969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12970. // TransactionMessageAttempts
  12971. /*
  12972. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12975. */
  12976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12977. // TransactionMessageRetryInterval
  12978. /*
  12979. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12982. */
  12983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12984. // UnlockConnectorOnEVSideDisconnect
  12985. /*
  12986. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12989. */
  12990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12991. // WebSocketPingInterval
  12992. /*
  12993. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12996. */
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12998. // QueueOffLineStartTransactionMessage
  12999. /*
  13000. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13003. */
  13004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13005. // AuthorizationKey
  13006. /*
  13007. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13010. */
  13011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13012. // SecurityProfile
  13013. /*
  13014. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13017. */
  13018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13019. // DefaultPrice
  13020. /*
  13021. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13024. */
  13025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13026. // CustomDisplayCostAndPrice
  13027. /*
  13028. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13031. */
  13032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13033. // CustomIdleFeeAfterStop
  13034. /*
  13035. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13038. */
  13039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13040. // TimeOffset
  13041. /*
  13042. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13045. */
  13046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13047. // NextTimeOffsetTransitionDateTime
  13048. /*
  13049. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13052. */
  13053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13054. // TimeOffsetNextTransition
  13055. /*
  13056. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13059. */
  13060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13061. // ConfigurationVersion
  13062. /*
  13063. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13066. */
  13067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13068. //* Local Auth List Management Profile*/
  13069. //LocalAuthListEnabled
  13070. /*
  13071. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13074. */
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13076. //LocalAuthListMaxLength
  13077. /*
  13078. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13081. */
  13082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13083. //SendLocalListMaxLength
  13084. /*
  13085. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13088. */
  13089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13090. //ReserveConnectorZeroSupported
  13091. /*
  13092. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13095. */
  13096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13097. //* Smart Charging Profile */
  13098. //ChargeProfileMaxStackLevel
  13099. /*
  13100. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13103. */
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13105. // ChargingScheduleAllowedChargingRateUnit
  13106. /*
  13107. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13110. */
  13111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13112. // ChargingScheduleMaxPeriods
  13113. /*
  13114. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13117. */
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13119. // ConnectorSwitch3to1PhaseSupported
  13120. /*
  13121. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13124. */
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13126. // MaxChargingProfilesInstalled
  13127. /*
  13128. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13131. */
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13133. fclose(outfile);
  13134. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13135. }
  13136. void getKeyValue(char *keyReq)
  13137. {
  13138. int isEmpty = FALSE;
  13139. int isKnowKey = FALSE;
  13140. DEBUG_INFO("keyReq = %s\n", keyReq);
  13141. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13142. isEmpty = TRUE;
  13143. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13144. {
  13145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13148. {
  13149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13150. }
  13151. else
  13152. {
  13153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13154. }
  13155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13156. isKnowKey = TRUE;
  13157. }
  13158. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13159. {
  13160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13163. {
  13164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13165. }
  13166. else
  13167. {
  13168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13169. }
  13170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13171. isKnowKey = TRUE;
  13172. }
  13173. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13174. {
  13175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13178. {
  13179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13180. }
  13181. else
  13182. {
  13183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13184. }
  13185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13186. isKnowKey = TRUE;
  13187. }
  13188. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13189. {
  13190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13193. {
  13194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13195. }
  13196. else
  13197. {
  13198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13199. }
  13200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13201. isKnowKey = TRUE;
  13202. }
  13203. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13204. {
  13205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13208. {
  13209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13210. }
  13211. else
  13212. {
  13213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13214. }
  13215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13216. isKnowKey = TRUE;
  13217. }
  13218. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13219. {
  13220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13223. {
  13224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13225. }
  13226. else
  13227. {
  13228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13229. }
  13230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13231. isKnowKey = TRUE;
  13232. }
  13233. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13234. {
  13235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13238. {
  13239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13240. }
  13241. else
  13242. {
  13243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13244. }
  13245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13246. isKnowKey = TRUE;
  13247. }
  13248. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13249. {
  13250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13253. {
  13254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13255. }
  13256. else
  13257. {
  13258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13259. }
  13260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13261. isKnowKey = TRUE;
  13262. }
  13263. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13264. {
  13265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13268. {
  13269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13270. }
  13271. else
  13272. {
  13273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13274. }
  13275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13276. isKnowKey = TRUE;
  13277. }
  13278. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13279. {
  13280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13283. {
  13284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13285. }
  13286. else
  13287. {
  13288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13289. }
  13290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13291. isKnowKey = TRUE;
  13292. }
  13293. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13294. {
  13295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13298. {
  13299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13300. }
  13301. else
  13302. {
  13303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13304. }
  13305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13306. isKnowKey = TRUE;
  13307. }
  13308. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13309. {
  13310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13313. {
  13314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13315. }
  13316. else
  13317. {
  13318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13319. }
  13320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13321. isKnowKey = TRUE;
  13322. }
  13323. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13324. {
  13325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13328. {
  13329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13330. }
  13331. else
  13332. {
  13333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13334. }
  13335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13336. isKnowKey = TRUE;
  13337. }
  13338. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13339. {
  13340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13343. {
  13344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13345. }
  13346. else
  13347. {
  13348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13349. }
  13350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13351. isKnowKey = TRUE;
  13352. }
  13353. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13354. {
  13355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13358. {
  13359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13360. }
  13361. else
  13362. {
  13363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13364. }
  13365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13366. isKnowKey = TRUE;
  13367. }
  13368. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13369. {
  13370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13373. {
  13374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13375. }
  13376. else
  13377. {
  13378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13379. }
  13380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13381. isKnowKey = TRUE;
  13382. }
  13383. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13384. {
  13385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13388. {
  13389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13390. }
  13391. else
  13392. {
  13393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13394. }
  13395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13396. isKnowKey = TRUE;
  13397. }
  13398. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13399. {
  13400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13403. {
  13404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13405. }
  13406. else
  13407. {
  13408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13409. }
  13410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13411. isKnowKey = TRUE;
  13412. }
  13413. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13414. {
  13415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13418. {
  13419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13420. }
  13421. else
  13422. {
  13423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13424. }
  13425. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13427. isKnowKey = TRUE;
  13428. }
  13429. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13430. {
  13431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13434. {
  13435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13436. }
  13437. else
  13438. {
  13439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13440. }
  13441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13442. isKnowKey = TRUE;
  13443. }
  13444. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13445. {
  13446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13449. {
  13450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13451. }
  13452. else
  13453. {
  13454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13455. }
  13456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13457. isKnowKey = TRUE;
  13458. }
  13459. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13460. {
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13464. {
  13465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13466. }
  13467. else
  13468. {
  13469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13470. }
  13471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13472. isKnowKey = TRUE;
  13473. }
  13474. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13475. {
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13479. {
  13480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13481. }
  13482. else
  13483. {
  13484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13485. }
  13486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13487. isKnowKey = TRUE;
  13488. }
  13489. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13490. {
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13494. {
  13495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13496. }
  13497. else
  13498. {
  13499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13500. }
  13501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13502. isKnowKey = TRUE;
  13503. }
  13504. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13505. {
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13509. {
  13510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13511. }
  13512. else
  13513. {
  13514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13515. }
  13516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13517. isKnowKey = TRUE;
  13518. }
  13519. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13520. {
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13524. {
  13525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13526. }
  13527. else
  13528. {
  13529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13530. }
  13531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13532. isKnowKey = TRUE;
  13533. }
  13534. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13535. {
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13539. {
  13540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13541. }
  13542. else
  13543. {
  13544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13545. }
  13546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13547. isKnowKey = TRUE;
  13548. }
  13549. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13550. {
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13554. {
  13555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13556. }
  13557. else
  13558. {
  13559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13560. }
  13561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13562. isKnowKey = TRUE;
  13563. }
  13564. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13565. {
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13569. {
  13570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13571. }
  13572. else
  13573. {
  13574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13575. }
  13576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13577. isKnowKey = TRUE;
  13578. }
  13579. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13580. {
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13584. {
  13585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13586. }
  13587. else
  13588. {
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13590. }
  13591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13592. isKnowKey = TRUE;
  13593. }
  13594. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13595. {
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13599. {
  13600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13601. }
  13602. else
  13603. {
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13605. }
  13606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13607. isKnowKey = TRUE;
  13608. }
  13609. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13610. {
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13614. {
  13615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13616. }
  13617. else
  13618. {
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13620. }
  13621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13622. isKnowKey = TRUE;
  13623. }
  13624. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13625. {
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13629. {
  13630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13631. }
  13632. else
  13633. {
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13635. }
  13636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13637. isKnowKey = TRUE;
  13638. }
  13639. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13640. {
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13644. {
  13645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13646. }
  13647. else
  13648. {
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13650. }
  13651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13652. isKnowKey = TRUE;
  13653. }
  13654. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13655. {
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13659. {
  13660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13661. }
  13662. else
  13663. {
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13665. }
  13666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13667. isKnowKey = TRUE;
  13668. }
  13669. /*
  13670. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13671. {
  13672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13675. {
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13677. }
  13678. else
  13679. {
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13681. }
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13683. isKnowKey = TRUE;
  13684. }*/
  13685. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13686. {
  13687. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13690. {
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13692. }
  13693. else
  13694. {
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13696. }
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13698. isKnowKey = TRUE;
  13699. }
  13700. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13701. {
  13702. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13705. {
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13707. }
  13708. else
  13709. {
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13711. }
  13712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13713. isKnowKey = TRUE;
  13714. }
  13715. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13716. {
  13717. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13720. {
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13722. }
  13723. else
  13724. {
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13726. }
  13727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13728. isKnowKey = TRUE;
  13729. }
  13730. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13731. {
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13735. {
  13736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13737. }
  13738. else
  13739. {
  13740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13741. }
  13742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13743. isKnowKey = TRUE;
  13744. }
  13745. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13746. {
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13750. {
  13751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13752. }
  13753. else
  13754. {
  13755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13756. }
  13757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13758. isKnowKey = TRUE;
  13759. }
  13760. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13761. {
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13765. {
  13766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13767. }
  13768. else
  13769. {
  13770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13771. }
  13772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13773. isKnowKey = TRUE;
  13774. }
  13775. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13776. {
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13780. {
  13781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13782. }
  13783. else
  13784. {
  13785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13786. }
  13787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13788. isKnowKey = TRUE;
  13789. }
  13790. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13791. {
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13795. {
  13796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13797. }
  13798. else
  13799. {
  13800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13801. }
  13802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13803. isKnowKey = TRUE;
  13804. }
  13805. #if 1
  13806. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13807. {
  13808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13810. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13813. }
  13814. else
  13815. {
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13817. }
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13819. isKnowKey = TRUE;
  13820. }
  13821. #endif
  13822. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13823. {
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13826. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13827. {
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13829. }
  13830. else
  13831. {
  13832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13833. }
  13834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13835. isKnowKey = TRUE;
  13836. }
  13837. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13838. {
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13841. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13844. }
  13845. else
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13848. }
  13849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13850. isKnowKey = TRUE;
  13851. }
  13852. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13853. {
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13856. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13859. }
  13860. else
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13863. }
  13864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13865. isKnowKey = TRUE;
  13866. }
  13867. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13868. {
  13869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13871. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13872. {
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13874. }
  13875. else
  13876. {
  13877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13878. }
  13879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13880. isKnowKey = TRUE;
  13881. }
  13882. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13883. {
  13884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13886. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13887. {
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13889. }
  13890. else
  13891. {
  13892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13893. }
  13894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13895. isKnowKey = TRUE;
  13896. }
  13897. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13898. {
  13899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13901. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13902. {
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13904. }
  13905. else
  13906. {
  13907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13908. }
  13909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13910. isKnowKey = TRUE;
  13911. }
  13912. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13913. {
  13914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13916. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13917. {
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13919. }
  13920. else
  13921. {
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13923. }
  13924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13925. isKnowKey = TRUE;
  13926. }
  13927. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13928. {
  13929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13931. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13932. {
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13934. }
  13935. else
  13936. {
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13938. }
  13939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13940. isKnowKey = TRUE;
  13941. }
  13942. //=========================================================
  13943. if(!isEmpty && !isKnowKey)
  13944. {
  13945. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13946. strcpy(unknownkey[UnknownKeynum], keyReq);
  13947. UnknownKeynum = UnknownKeynum + 1;
  13948. }
  13949. }
  13950. void processUnkownKey(void)
  13951. {
  13952. DEBUG_INFO("processUnkownKey...\n");
  13953. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13954. for(int index=0; index < UnknownKeynum; index++)
  13955. {
  13956. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13957. {
  13958. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13959. }
  13960. }
  13961. }
  13962. int setKeyValue(char *key, char *value)
  13963. {
  13964. int isSuccess = NotSupported;
  13965. int check_ascii=0;
  13966. char str[256]={0};
  13967. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13968. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13969. {
  13970. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13972. {
  13973. strcpy(str, (const char*)value);
  13974. for(int i = 0; str[i]; i++){
  13975. str[i] = tolower(str[i]);
  13976. }
  13977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13978. isSuccess = ConfigurationStatus_Accepted;
  13979. }
  13980. else
  13981. {
  13982. isSuccess = ConfigurationStatus_Rejected;
  13983. }
  13984. }
  13985. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13986. {
  13987. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13989. {
  13990. strcpy(str, (const char*)value);
  13991. for(int i = 0; str[i]; i++){
  13992. str[i] = tolower(str[i]);
  13993. }
  13994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13995. isSuccess = ConfigurationStatus_Accepted;
  13996. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13997. }
  13998. else
  13999. {
  14000. isSuccess = ConfigurationStatus_Rejected;
  14001. }
  14002. }
  14003. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14004. {
  14005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14006. {
  14007. strcpy(str, (const char*)value);
  14008. for(int i = 0; str[i]; i++)
  14009. {
  14010. str[i] = tolower(str[i]);
  14011. }
  14012. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14014. isSuccess = ConfigurationStatus_Accepted;
  14015. }
  14016. else
  14017. {
  14018. isSuccess = ConfigurationStatus_Rejected;
  14019. }
  14020. }
  14021. if(strcmp(key, "BlinkRepeat") == 0)
  14022. {
  14023. //Charger.BlinkRepeat = Integer.parseInt(value);
  14024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14025. {
  14026. check_ascii = value[0];
  14027. if( (check_ascii < 48) || (check_ascii > 57) )
  14028. {
  14029. isSuccess = ConfigurationStatus_Rejected;
  14030. }
  14031. else
  14032. {
  14033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14034. isSuccess = ConfigurationStatus_Accepted;
  14035. }
  14036. }
  14037. else
  14038. {
  14039. isSuccess = ConfigurationStatus_Rejected;
  14040. }
  14041. }
  14042. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14043. {
  14044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14045. {
  14046. check_ascii = value[0];
  14047. if( (check_ascii < 48) || (check_ascii > 57) )
  14048. {
  14049. isSuccess = ConfigurationStatus_Rejected;
  14050. }
  14051. else
  14052. {
  14053. if((atoi(value) == 0) || (atoi(value) >= 10))
  14054. {
  14055. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14057. isSuccess = ConfigurationStatus_Accepted;
  14058. }
  14059. else
  14060. isSuccess = ConfigurationStatus_Rejected;
  14061. }
  14062. }
  14063. else
  14064. {
  14065. isSuccess = ConfigurationStatus_Rejected;
  14066. }
  14067. }
  14068. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14069. {
  14070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14071. {
  14072. check_ascii = value[0];
  14073. if( (check_ascii < 48) || (check_ascii > 57) )
  14074. {
  14075. isSuccess = ConfigurationStatus_Rejected;
  14076. }
  14077. else
  14078. {
  14079. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14081. isSuccess = ConfigurationStatus_Accepted;
  14082. }
  14083. }
  14084. else
  14085. {
  14086. isSuccess = ConfigurationStatus_Rejected;
  14087. }
  14088. }
  14089. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14090. {
  14091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14092. {
  14093. check_ascii = value[0];
  14094. if( (check_ascii < 48) || (check_ascii > 57) )
  14095. {
  14096. isSuccess = ConfigurationStatus_Rejected;
  14097. }
  14098. else
  14099. {
  14100. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14102. isSuccess = ConfigurationStatus_Accepted;
  14103. }
  14104. }
  14105. else
  14106. {
  14107. isSuccess = ConfigurationStatus_Rejected;
  14108. }
  14109. }
  14110. if(strcmp(key, "HeartbeatInterval") == 0)
  14111. {
  14112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14113. {
  14114. check_ascii = value[0];
  14115. if( (check_ascii < 48) || (check_ascii > 57) )
  14116. {
  14117. isSuccess = ConfigurationStatus_Rejected;
  14118. }
  14119. else
  14120. {
  14121. if((atoi(value) == 0) || (atoi(value) >= 10))
  14122. {
  14123. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14125. HeartBeatWaitTime = atoi(value);
  14126. isSuccess = ConfigurationStatus_Accepted;
  14127. }
  14128. else
  14129. {
  14130. isSuccess = ConfigurationStatus_Rejected;
  14131. }
  14132. }
  14133. }
  14134. else
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. }
  14139. if(strcmp(key, "LightIntensity") == 0)
  14140. {
  14141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14142. {
  14143. check_ascii = value[0];
  14144. if( (check_ascii < 48) || (check_ascii > 57) )
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. else
  14149. {
  14150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14151. isSuccess = ConfigurationStatus_Accepted;
  14152. }
  14153. }
  14154. else
  14155. {
  14156. isSuccess = ConfigurationStatus_Rejected;
  14157. }
  14158. }
  14159. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14160. {
  14161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14162. {
  14163. strcpy(str, (const char*)value);
  14164. for(int i = 0; str[i]; i++)
  14165. {
  14166. str[i] = tolower(str[i]);
  14167. }
  14168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14169. isSuccess = ConfigurationStatus_Accepted;
  14170. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14171. }
  14172. else
  14173. {
  14174. isSuccess = ConfigurationStatus_Rejected;
  14175. }
  14176. }
  14177. if(strcmp(key, "LocalPreAuthorize") == 0)
  14178. {
  14179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14180. {
  14181. strcpy(str, (const char*)value);
  14182. for(int i = 0; str[i]; i++)
  14183. {
  14184. str[i] = tolower(str[i]);
  14185. }
  14186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14187. isSuccess = ConfigurationStatus_Accepted;
  14188. }
  14189. else
  14190. {
  14191. isSuccess = ConfigurationStatus_Rejected;
  14192. }
  14193. }
  14194. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14195. {
  14196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14197. {
  14198. check_ascii = value[0];
  14199. if( (check_ascii < 48) || (check_ascii > 57) )
  14200. {
  14201. isSuccess = ConfigurationStatus_Rejected;
  14202. }
  14203. else
  14204. {
  14205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14206. isSuccess = ConfigurationStatus_Accepted;
  14207. }
  14208. }
  14209. else
  14210. {
  14211. isSuccess = ConfigurationStatus_Rejected;
  14212. }
  14213. }
  14214. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14215. {
  14216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14217. {
  14218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14219. isSuccess = ConfigurationStatus_Accepted;
  14220. }
  14221. else
  14222. {
  14223. isSuccess = ConfigurationStatus_Rejected;
  14224. }
  14225. }
  14226. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14227. {
  14228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14229. {
  14230. check_ascii = value[0];
  14231. if( (check_ascii < 48) || (check_ascii > 57) )
  14232. {
  14233. isSuccess = ConfigurationStatus_Rejected;
  14234. }
  14235. else
  14236. {
  14237. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14239. isSuccess = ConfigurationStatus_Accepted;
  14240. }
  14241. }
  14242. else
  14243. {
  14244. isSuccess = ConfigurationStatus_Rejected;
  14245. }
  14246. }
  14247. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14248. {
  14249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14250. {
  14251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14252. isSuccess = ConfigurationStatus_Accepted;
  14253. }
  14254. else
  14255. {
  14256. isSuccess = ConfigurationStatus_Rejected;
  14257. }
  14258. }
  14259. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14260. {
  14261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14262. {
  14263. check_ascii = value[0];
  14264. if( (check_ascii < 48) || (check_ascii > 57) )
  14265. {
  14266. isSuccess = ConfigurationStatus_Rejected;
  14267. }
  14268. else
  14269. {
  14270. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14272. isSuccess = ConfigurationStatus_Accepted;
  14273. }
  14274. }
  14275. else
  14276. {
  14277. isSuccess = ConfigurationStatus_Rejected;
  14278. }
  14279. }
  14280. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14281. {
  14282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14283. {
  14284. check_ascii = value[0];
  14285. if( (check_ascii < 48) || (check_ascii > 57) )
  14286. {
  14287. isSuccess = ConfigurationStatus_Rejected;
  14288. }
  14289. else
  14290. {
  14291. if((atoi(value) == 0) || (atoi(value) >= 10))
  14292. {
  14293. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14295. isSuccess = ConfigurationStatus_Accepted;
  14296. }
  14297. else
  14298. {
  14299. isSuccess = ConfigurationStatus_Rejected;
  14300. }
  14301. }
  14302. }
  14303. else
  14304. {
  14305. isSuccess = ConfigurationStatus_Rejected;
  14306. }
  14307. }
  14308. if(strcmp(key, "MinimumStatusDuration") == 0)
  14309. {
  14310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14311. {
  14312. check_ascii = value[0];
  14313. if( (check_ascii < 48) || (check_ascii > 57) )
  14314. {
  14315. isSuccess = ConfigurationStatus_Rejected;
  14316. }
  14317. else
  14318. {
  14319. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14320. {
  14321. isSuccess = ConfigurationStatus_Rejected;
  14322. }
  14323. else
  14324. {
  14325. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14327. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14328. isSuccess = ConfigurationStatus_Accepted;
  14329. }
  14330. }
  14331. }
  14332. else
  14333. {
  14334. isSuccess = ConfigurationStatus_Rejected;
  14335. }
  14336. }
  14337. if(strcmp(key, "NumberOfConnectors") == 0)
  14338. {
  14339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14340. {
  14341. check_ascii = value[0];
  14342. if( (check_ascii < 48) || (check_ascii > 57) )
  14343. {
  14344. isSuccess = ConfigurationStatus_Rejected;
  14345. }
  14346. else
  14347. {
  14348. //Charger.ResetRetries = Integer.parseInt(value);
  14349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14350. isSuccess = ConfigurationStatus_Accepted;
  14351. }
  14352. }
  14353. else
  14354. {
  14355. isSuccess = ConfigurationStatus_Rejected;
  14356. }
  14357. }
  14358. if(strcmp(key, "ResetRetries") == 0)
  14359. {
  14360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14361. {
  14362. check_ascii = value[0];
  14363. if( (check_ascii < 48) || (check_ascii > 57) )
  14364. {
  14365. isSuccess = ConfigurationStatus_Rejected;
  14366. }
  14367. else
  14368. {
  14369. //Charger.ResetRetries = Integer.parseInt(value);
  14370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14371. isSuccess = ConfigurationStatus_Accepted;
  14372. }
  14373. }
  14374. else
  14375. {
  14376. isSuccess = ConfigurationStatus_Rejected;
  14377. }
  14378. }
  14379. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14380. {
  14381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14382. {
  14383. strcpy(str, (const char*)value);
  14384. for(int i = 0; str[i]; i++)
  14385. {
  14386. str[i] = tolower(str[i]);
  14387. }
  14388. if(strcmp(str, "notapplicable")== 0)
  14389. {
  14390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14391. isSuccess = ConfigurationStatus_Accepted;
  14392. }
  14393. else if(strcmp(str, "unknown")== 0)
  14394. {
  14395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14396. isSuccess = ConfigurationStatus_Accepted;
  14397. }
  14398. else if(strcmp(str, "rst")== 0)
  14399. {
  14400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14401. isSuccess = ConfigurationStatus_Accepted;
  14402. }
  14403. else if(strcmp(str, "rts")== 0)
  14404. {
  14405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14406. isSuccess = ConfigurationStatus_Accepted;
  14407. }
  14408. else if(strcmp(str, "srt")== 0)
  14409. {
  14410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14411. isSuccess = ConfigurationStatus_Accepted;
  14412. }
  14413. else if(strcmp(str, "str")== 0)
  14414. {
  14415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14416. isSuccess = ConfigurationStatus_Accepted;
  14417. }
  14418. else if(strcmp(str, "trs")== 0)
  14419. {
  14420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14421. isSuccess = ConfigurationStatus_Accepted;
  14422. }
  14423. else if(strcmp(str, "tsr")== 0)
  14424. {
  14425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14426. isSuccess = ConfigurationStatus_Accepted;
  14427. }
  14428. else
  14429. {
  14430. isSuccess = ConfigurationStatus_Rejected;
  14431. }
  14432. }
  14433. else
  14434. {
  14435. isSuccess = ConfigurationStatus_Rejected;
  14436. }
  14437. }
  14438. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14439. {
  14440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14441. {
  14442. check_ascii = value[0];
  14443. if( (check_ascii < 48) || (check_ascii > 57) )
  14444. {
  14445. isSuccess = ConfigurationStatus_Rejected;
  14446. }
  14447. else
  14448. {
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14450. isSuccess = ConfigurationStatus_Accepted;
  14451. }
  14452. }
  14453. else
  14454. {
  14455. isSuccess = ConfigurationStatus_Rejected;
  14456. }
  14457. }
  14458. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14459. {
  14460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14461. {
  14462. strcpy(str, (const char*)value);
  14463. for(int i = 0; str[i]; i++)
  14464. {
  14465. str[i] = tolower(str[i]);
  14466. }
  14467. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14469. isSuccess = ConfigurationStatus_Accepted;
  14470. }
  14471. else
  14472. {
  14473. isSuccess = ConfigurationStatus_Rejected;
  14474. }
  14475. }
  14476. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14477. {
  14478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14479. {
  14480. strcpy(str, (const char*)value);
  14481. for(int i = 0; str[i]; i++)
  14482. {
  14483. str[i] = tolower(str[i]);
  14484. }
  14485. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14487. isSuccess = ConfigurationStatus_Accepted;
  14488. }
  14489. else
  14490. {
  14491. isSuccess = ConfigurationStatus_Rejected;
  14492. }
  14493. }
  14494. if(strcmp(key, "StopTxnAlignedData") == 0)
  14495. {
  14496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14497. {
  14498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14499. isSuccess = ConfigurationStatus_Accepted;
  14500. }
  14501. else
  14502. {
  14503. isSuccess = ConfigurationStatus_Rejected;
  14504. }
  14505. }
  14506. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14507. {
  14508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14509. {
  14510. check_ascii = value[0];
  14511. if( (check_ascii < 48) || (check_ascii > 57) )
  14512. {
  14513. isSuccess = ConfigurationStatus_Rejected;
  14514. }
  14515. else
  14516. {
  14517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14518. isSuccess = ConfigurationStatus_Accepted;
  14519. }
  14520. }
  14521. else
  14522. {
  14523. isSuccess = ConfigurationStatus_Rejected;
  14524. }
  14525. }
  14526. if(strcmp(key, "StopTxnSampledData") == 0)
  14527. {
  14528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14529. {
  14530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14531. isSuccess = ConfigurationStatus_Accepted;
  14532. }
  14533. else
  14534. {
  14535. isSuccess = ConfigurationStatus_Rejected;
  14536. }
  14537. }
  14538. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14539. {
  14540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14541. {
  14542. check_ascii = value[0];
  14543. if( (check_ascii < 48) || (check_ascii > 57) )
  14544. {
  14545. isSuccess = ConfigurationStatus_Rejected;
  14546. }
  14547. else
  14548. {
  14549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14550. isSuccess = ConfigurationStatus_Accepted;
  14551. }
  14552. }
  14553. else
  14554. {
  14555. isSuccess = ConfigurationStatus_Rejected;
  14556. }
  14557. }
  14558. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14559. {
  14560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14561. {
  14562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14563. isSuccess = ConfigurationStatus_Accepted;
  14564. }
  14565. else
  14566. {
  14567. isSuccess = ConfigurationStatus_Rejected;
  14568. }
  14569. }
  14570. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14571. {
  14572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14573. {
  14574. check_ascii = value[0];
  14575. if( (check_ascii < 48) || (check_ascii > 57) )
  14576. {
  14577. isSuccess = ConfigurationStatus_Rejected;
  14578. }
  14579. else
  14580. {
  14581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14582. isSuccess = ConfigurationStatus_Accepted;
  14583. }
  14584. }
  14585. else
  14586. {
  14587. isSuccess = ConfigurationStatus_Rejected;
  14588. }
  14589. }
  14590. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14591. {
  14592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14593. {
  14594. check_ascii = value[0];
  14595. if( (check_ascii < 48) || (check_ascii > 57) )
  14596. {
  14597. isSuccess = ConfigurationStatus_Rejected;
  14598. }
  14599. else
  14600. {
  14601. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14603. TransactionMessageAttemptsValue = atoi(value);
  14604. isSuccess = ConfigurationStatus_Accepted;
  14605. }
  14606. }
  14607. else
  14608. {
  14609. isSuccess = ConfigurationStatus_Rejected;
  14610. }
  14611. }
  14612. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14613. {
  14614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14615. {
  14616. check_ascii = value[0];
  14617. if( (check_ascii < 48) || (check_ascii > 57) )
  14618. {
  14619. isSuccess = ConfigurationStatus_Rejected;
  14620. }
  14621. else
  14622. {
  14623. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14625. TransactionMessageRetryIntervalValue = atoi(value);
  14626. isSuccess = ConfigurationStatus_Accepted;
  14627. }
  14628. }
  14629. else
  14630. {
  14631. isSuccess = ConfigurationStatus_Rejected;
  14632. }
  14633. }
  14634. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14635. {
  14636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14637. {
  14638. strcpy(str, (const char*)value);
  14639. for(int i = 0; str[i]; i++)
  14640. {
  14641. str[i] = tolower(str[i]);
  14642. }
  14643. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14645. isSuccess = ConfigurationStatus_Accepted;
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. if(strcmp(key, "WebSocketPingInterval") == 0)
  14653. {
  14654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14655. {
  14656. check_ascii = value[0];
  14657. if( (check_ascii < 48) || (check_ascii > 57) )
  14658. {
  14659. isSuccess = ConfigurationStatus_Rejected;
  14660. }
  14661. else
  14662. {
  14663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14664. isSuccess = ConfigurationStatus_Accepted;
  14665. }
  14666. }
  14667. else
  14668. {
  14669. isSuccess = ConfigurationStatus_Rejected;
  14670. }
  14671. }
  14672. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14673. {
  14674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14675. {
  14676. strcpy(str, (const char*)value);
  14677. for(int i = 0; str[i]; i++)
  14678. {
  14679. str[i] = tolower(str[i]);
  14680. }
  14681. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14683. isSuccess = ConfigurationStatus_Accepted;
  14684. }
  14685. else
  14686. {
  14687. isSuccess = ConfigurationStatus_Rejected;
  14688. }
  14689. }
  14690. if(strcmp(key, "AuthorizationKey") == 0)
  14691. {
  14692. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14693. {
  14694. strcpy(str, (const char*)value);
  14695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14696. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14697. isSuccess = ConfigurationStatus_Accepted;
  14698. }
  14699. else
  14700. {
  14701. isSuccess = ConfigurationStatus_Rejected;
  14702. }
  14703. }
  14704. if(strcmp(key, "SecurityProfile") == 0)
  14705. {
  14706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14707. {
  14708. check_ascii = value[0];
  14709. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14710. {
  14711. isSuccess = ConfigurationStatus_Rejected;
  14712. }
  14713. else if(check_ascii == 0x33)
  14714. {
  14715. isSuccess = NotSupported;
  14716. }
  14717. else
  14718. {
  14719. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14720. {
  14721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14722. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14723. isSuccess = ConfigurationStatus_Accepted;
  14724. }
  14725. else
  14726. isSuccess = ConfigurationStatus_Rejected;
  14727. }
  14728. }
  14729. else
  14730. {
  14731. isSuccess = ConfigurationStatus_Rejected;
  14732. }
  14733. }
  14734. if(strcmp(key, "DefaultPrice") == 0)
  14735. {
  14736. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14737. {
  14738. strcpy(str, (const char*)value);
  14739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14740. isSuccess = ConfigurationStatus_Accepted;
  14741. }
  14742. else
  14743. {
  14744. isSuccess = ConfigurationStatus_Rejected;
  14745. }
  14746. }
  14747. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14748. {
  14749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14750. {
  14751. strcpy(str, (const char*)value);
  14752. for(int i = 0; str[i]; i++)
  14753. {
  14754. str[i] = tolower(str[i]);
  14755. }
  14756. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14758. isSuccess = ConfigurationStatus_Accepted;
  14759. }
  14760. else
  14761. {
  14762. isSuccess = ConfigurationStatus_Rejected;
  14763. }
  14764. }
  14765. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14766. {
  14767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14768. {
  14769. strcpy(str, (const char*)value);
  14770. for(int i = 0; str[i]; i++)
  14771. {
  14772. str[i] = tolower(str[i]);
  14773. }
  14774. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14776. isSuccess = ConfigurationStatus_Accepted;
  14777. }
  14778. else
  14779. {
  14780. isSuccess = ConfigurationStatus_Rejected;
  14781. }
  14782. }
  14783. if(strcmp(key, "TimeOffset") == 0)
  14784. {
  14785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14786. {
  14787. strcpy(str, (const char*)value);
  14788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14789. isSuccess = ConfigurationStatus_Accepted;
  14790. }
  14791. else
  14792. {
  14793. isSuccess = ConfigurationStatus_Rejected;
  14794. }
  14795. }
  14796. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14797. {
  14798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14799. {
  14800. strcpy(str, (const char*)value);
  14801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14802. isSuccess = ConfigurationStatus_Accepted;
  14803. }
  14804. else
  14805. {
  14806. isSuccess = ConfigurationStatus_Rejected;
  14807. }
  14808. }
  14809. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14810. {
  14811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14812. {
  14813. strcpy(str, (const char*)value);
  14814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14815. isSuccess = ConfigurationStatus_Accepted;
  14816. }
  14817. else
  14818. {
  14819. isSuccess = ConfigurationStatus_Rejected;
  14820. }
  14821. }
  14822. #if 0
  14823. //For OCPP Test Case
  14824. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14825. {
  14826. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14827. {
  14828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14829. isSuccess = ConfigurationStatus_Accepted;
  14830. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14831. }
  14832. else
  14833. {
  14834. isSuccess = ConfigurationStatus_Rejected;
  14835. }
  14836. }
  14837. #endif
  14838. #if 1
  14839. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14840. {
  14841. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14842. {
  14843. strcpy(str, (const char*)value);
  14844. for(int i = 0; str[i]; i++)
  14845. {
  14846. str[i] = tolower(str[i]);
  14847. }
  14848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14849. isSuccess = ConfigurationStatus_Accepted;
  14850. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14851. }
  14852. else
  14853. {
  14854. isSuccess = ConfigurationStatus_Rejected;
  14855. }
  14856. }
  14857. #endif
  14858. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14859. {
  14860. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14861. {
  14862. check_ascii = value[0];
  14863. if( (check_ascii < 48) || (check_ascii > 57) )
  14864. {
  14865. isSuccess = ConfigurationStatus_Rejected;
  14866. }
  14867. else
  14868. {
  14869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14870. isSuccess = ConfigurationStatus_Accepted;
  14871. }
  14872. }
  14873. else
  14874. {
  14875. isSuccess = ConfigurationStatus_Rejected;
  14876. }
  14877. }
  14878. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14879. {
  14880. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14881. {
  14882. check_ascii = value[0];
  14883. if( (check_ascii < 48) || (check_ascii > 57) )
  14884. {
  14885. isSuccess = ConfigurationStatus_Rejected;
  14886. }
  14887. else
  14888. {
  14889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14890. isSuccess = ConfigurationStatus_Accepted;
  14891. }
  14892. }
  14893. else
  14894. {
  14895. isSuccess = ConfigurationStatus_Rejected;
  14896. }
  14897. }
  14898. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14899. {
  14900. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14901. {
  14902. strcpy(str, (const char*)value);
  14903. for(int i = 0; str[i]; i++)
  14904. {
  14905. str[i] = tolower(str[i]);
  14906. }
  14907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14908. isSuccess = ConfigurationStatus_Accepted;
  14909. }
  14910. else
  14911. {
  14912. isSuccess = ConfigurationStatus_Rejected;
  14913. }
  14914. }
  14915. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14916. {
  14917. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14918. {
  14919. check_ascii = value[0];
  14920. if( (check_ascii < 48) || (check_ascii > 57) )
  14921. {
  14922. isSuccess = ConfigurationStatus_Rejected;
  14923. }
  14924. else
  14925. {
  14926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14927. isSuccess = ConfigurationStatus_Accepted;
  14928. }
  14929. }
  14930. else
  14931. {
  14932. isSuccess = ConfigurationStatus_Rejected;
  14933. }
  14934. }
  14935. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14936. {
  14937. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14938. {
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14940. isSuccess = ConfigurationStatus_Accepted;
  14941. }
  14942. else
  14943. {
  14944. isSuccess = ConfigurationStatus_Rejected;
  14945. }
  14946. }
  14947. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14948. {
  14949. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14950. {
  14951. check_ascii = value[0];
  14952. if( (check_ascii < 48) || (check_ascii > 57) )
  14953. {
  14954. isSuccess = ConfigurationStatus_Rejected;
  14955. }
  14956. else
  14957. {
  14958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14959. isSuccess = ConfigurationStatus_Accepted;
  14960. }
  14961. }
  14962. else
  14963. {
  14964. isSuccess = ConfigurationStatus_Rejected;
  14965. }
  14966. }
  14967. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14968. {
  14969. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14970. {
  14971. strcpy(str, (const char*)value);
  14972. for(int i = 0; str[i]; i++)
  14973. {
  14974. str[i] = tolower(str[i]);
  14975. }
  14976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14977. isSuccess = ConfigurationStatus_Accepted;
  14978. }
  14979. else
  14980. {
  14981. isSuccess = ConfigurationStatus_Rejected;
  14982. }
  14983. }
  14984. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14985. {
  14986. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14987. {
  14988. check_ascii = value[0];
  14989. if( (check_ascii < 48) || (check_ascii > 57) )
  14990. {
  14991. isSuccess = ConfigurationStatus_Rejected;
  14992. }
  14993. else
  14994. {
  14995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14996. isSuccess = ConfigurationStatus_Accepted;
  14997. }
  14998. }
  14999. else
  15000. {
  15001. isSuccess = ConfigurationStatus_Rejected;
  15002. }
  15003. }
  15004. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15005. return isSuccess;
  15006. }
  15007. int TransactionMessageAttemptsGet(void)
  15008. {
  15009. return TransactionMessageAttemptsValue;
  15010. }
  15011. int FirstHeartBeatResponse(void)
  15012. {
  15013. return FirstHeartBeat;
  15014. }
  15015. int TransactionMessageRetryIntervalGet(void)
  15016. {
  15017. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15018. }
  15019. int ReadHttpStatus(int sock)
  15020. {
  15021. //char c;
  15022. char buff[1024]="",*ptr=buff+1;
  15023. int bytes_received, status;
  15024. DEBUG_INFO("Begin Response ..\n");
  15025. while((bytes_received = recv(sock, ptr, 1, 0))){
  15026. if(bytes_received==-1){
  15027. perror("ReadHttpStatus");
  15028. exit(1);
  15029. }
  15030. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15031. ptr++;
  15032. }
  15033. *ptr=0;
  15034. ptr=buff+1;
  15035. sscanf(ptr,"%*s %d ", &status);
  15036. DEBUG_INFO("%s\n",ptr);
  15037. DEBUG_INFO("status=%d\n",status);
  15038. DEBUG_INFO("End Response ..\n");
  15039. return (bytes_received>0)?status:0;
  15040. }
  15041. //the only filed that it parsed is 'Content-Length'
  15042. int ParseHeader(int sock)
  15043. {
  15044. //char c;
  15045. char buff[1024]="",*ptr=buff+4;
  15046. int bytes_received;
  15047. DEBUG_INFO("Begin HEADER ..\n");
  15048. while((bytes_received = recv(sock, ptr, 1, 0))){
  15049. if(bytes_received==-1){
  15050. perror("Parse Header");
  15051. exit(1);
  15052. }
  15053. if(
  15054. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15055. (ptr[-1]=='\r') && (*ptr=='\n' )
  15056. ) break;
  15057. ptr++;
  15058. }
  15059. *ptr=0;
  15060. ptr=buff+4;
  15061. //printf("%s",ptr);
  15062. if(bytes_received){
  15063. ptr=strstr(ptr,"Content-Length:");
  15064. if(ptr){
  15065. sscanf(ptr,"%*s %d",&bytes_received);
  15066. }else
  15067. bytes_received=-1; //unknown size
  15068. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15069. }
  15070. DEBUG_INFO("End HEADER ..\n");
  15071. return bytes_received ;
  15072. }
  15073. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15074. {
  15075. int result = TRUE;
  15076. char rmFileCmd[100]={0};
  15077. char FilePath[100]={0};
  15078. char ftpbuf[200];
  15079. int systemresult;
  15080. //DEBUG_INFO("filename=%s\n",filename);
  15081. //DEBUG_INFO("url=%s\n",url);
  15082. sprintf(FilePath,"/mnt/%s",filename);
  15083. system("ping 8.8.8.8 &");
  15084. if((access(FilePath,F_OK))!=-1)
  15085. {
  15086. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15087. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15088. system(rmFileCmd);
  15089. }
  15090. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15091. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15092. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15093. systemresult = system(ftpbuf);
  15094. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15095. if(systemresult != 0)
  15096. {
  15097. DEBUG_INFO("http DownLoad error!\n");
  15098. result = FALSE;
  15099. }
  15100. system("pkill ping");
  15101. return result;
  15102. }
  15103. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15104. {
  15105. int result = TRUE;
  15106. char rmFileCmd[100]={0};
  15107. char FilePath[100]={0};
  15108. char ftpbuf[200];
  15109. int systemresult;
  15110. //char temp[100];
  15111. sprintf(FilePath,"/mnt/%s",filename);
  15112. system("ping 8.8.8.8 &");
  15113. if((access(FilePath,F_OK))!=-1)
  15114. {
  15115. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15116. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15117. system(rmFileCmd);
  15118. }
  15119. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15120. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15121. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15122. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15123. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15124. systemresult = system(ftpbuf);
  15125. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15126. if(systemresult != 0)
  15127. {
  15128. DEBUG_WARN("wget error!\n");
  15129. result = FALSE;
  15130. }
  15131. system("pkill ping");
  15132. return result;
  15133. }
  15134. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15135. {
  15136. char rmFileCmd[100]={0};
  15137. char FilePath[100]={0};
  15138. char buf[512];
  15139. int systemresult = 0;
  15140. //DEBUG_INFO("filename=%s\n",filename);
  15141. //DEBUG_INFO("url=%s\n",url);
  15142. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15143. if((access(FilePath,F_OK))!=-1)
  15144. {
  15145. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15146. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15147. system(rmFileCmd);
  15148. }
  15149. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15150. if(fp == NULL)
  15151. {
  15152. DEBUG_INFO("log is NULL\n");
  15153. return FALSE;
  15154. }
  15155. else
  15156. {
  15157. fprintf(fp, "%s\n", url);
  15158. fprintf(fp, "%s\n", filename);
  15159. fclose(fp);
  15160. }
  15161. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15162. if(phpFP == NULL)
  15163. {
  15164. DEBUG_INFO("PHP upload fail.\n");
  15165. return FALSE;
  15166. }
  15167. else
  15168. {
  15169. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15170. {
  15171. if(strstr(buf, "result") != NULL)
  15172. {
  15173. sscanf(buf, "result: %d", &systemresult);
  15174. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15175. }
  15176. }
  15177. pclose(phpFP);
  15178. }
  15179. if(systemresult != 1)
  15180. {
  15181. DEBUG_INFO("HTTP upload error!\n");
  15182. return FALSE;
  15183. }
  15184. return TRUE;
  15185. }
  15186. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15187. {
  15188. struct hostent* server;
  15189. char *IPbuffer;
  15190. char ftpbuf[200];
  15191. int systemresult;
  15192. // To retrieve host information
  15193. server = gethostbyname(location);
  15194. // To convert an Internet network
  15195. // address into ASCII string
  15196. IPbuffer = inet_ntoa(*((struct in_addr*)
  15197. server->h_addr_list[0]));
  15198. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15199. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15200. /* format : ftpput -u username -p passwd IP target source*/
  15201. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15202. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15203. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15204. systemresult = system(ftpbuf);
  15205. DEBUG_INFO("systemresult=%d\n",systemresult);
  15206. if(systemresult != 0)
  15207. {
  15208. DEBUG_INFO("ftpput error!\n");
  15209. return FALSE;
  15210. }
  15211. return TRUE;
  15212. }
  15213. int GetOcppServerURL()
  15214. {
  15215. int result = FALSE;
  15216. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15217. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15218. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15219. struct yuarel url;
  15220. char urlStr[512];
  15221. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15222. {
  15223. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15224. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15225. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15226. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15227. if(yuarel_parse(&url, urlStr) != -1)
  15228. {
  15229. sprintf(OcppProtocol, "%s", url.scheme);
  15230. sprintf(OcppHost, "%s", url.host);
  15231. if(url.path == NULL)
  15232. OcppTempPath[0] = '\0';
  15233. else
  15234. {
  15235. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15236. {
  15237. sprintf(OcppTempPath, "%s/", url.path);
  15238. }
  15239. else
  15240. {
  15241. sprintf(OcppTempPath, "%s", url.path);
  15242. }
  15243. }
  15244. if(url.port == 0)
  15245. {
  15246. if(strcmp(OcppProtocol, "wss") == 0)
  15247. OcppPort = 443;
  15248. else
  15249. OcppPort = 80;
  15250. }
  15251. else
  15252. OcppPort = url.port;
  15253. result = TRUE;
  15254. }
  15255. }
  15256. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15257. {
  15258. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15259. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15260. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15261. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15262. if(yuarel_parse(&url, urlStr) != -1)
  15263. {
  15264. sprintf(OcppProtocol, "%s", url.scheme);
  15265. sprintf(OcppHost, "%s", url.host);
  15266. if(url.path == NULL)
  15267. OcppTempPath[0] = '\0';
  15268. else
  15269. sprintf(OcppTempPath, "%s", url.path);
  15270. if(url.port == 0)
  15271. {
  15272. if(strcmp(OcppProtocol, "wss") == 0)
  15273. OcppPort = 443;
  15274. else
  15275. OcppPort = 80;
  15276. }
  15277. else
  15278. OcppPort = url.port;
  15279. result = TRUE;
  15280. }
  15281. }
  15282. else
  15283. {
  15284. strcpy(OcppHost,"");
  15285. }
  15286. return result;
  15287. }
  15288. int GetOcppPath()
  15289. {
  15290. int result = FALSE;
  15291. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15292. {
  15293. if(OcppTempPath == NULL)
  15294. {
  15295. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15296. }
  15297. else
  15298. {
  15299. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15300. }
  15301. result = TRUE;
  15302. goto End;
  15303. }
  15304. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15305. {
  15306. if(OcppTempPath == NULL)
  15307. {
  15308. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15309. }
  15310. else
  15311. {
  15312. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15313. }
  15314. result = TRUE;
  15315. goto End;
  15316. }
  15317. else
  15318. {
  15319. strcpy(OcppPath,"");
  15320. }
  15321. End:
  15322. return result;
  15323. }
  15324. int GetOcppPort()
  15325. {
  15326. return OcppPort;
  15327. }
  15328. int GetOcppConnStatus(void)
  15329. {
  15330. return ShmOCPP16Data->OcppConnStatus;
  15331. }
  15332. void SetOcppConnStatus(uint8_t status)
  15333. {
  15334. ShmOCPP16Data->OcppConnStatus = status;
  15335. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15336. }
  15337. int GetHeartBeatWithNOResponse(void)
  15338. {
  15339. return HeartBeatWithNOResponse;
  15340. }
  15341. void SetHeartBeatWithNOResponse(void)
  15342. {
  15343. HeartBeatWithNOResponse = 0;
  15344. }
  15345. void GetStartTransactionIdTag(int gun_index)
  15346. {
  15347. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15348. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15349. }
  15350. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15351. {
  15352. char ch;
  15353. FILE *fptr1;
  15354. int temptransactionId;
  15355. char str[100]={0};
  15356. temptransactionId = 0;
  15357. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15358. {
  15359. DEBUG_INFO("IdTag is empty.\n");
  15360. return temptransactionId;
  15361. }
  15362. /*------ Read the file ----------------*/
  15363. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15364. if (!fptr1)
  15365. {
  15366. DEBUG_INFO("QueueTransactionId file open error.\n");
  15367. //printf(" File not found or unable to open the input file!!\n");
  15368. return temptransactionId;
  15369. }
  15370. ch=fgetc(fptr1);
  15371. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15372. rewind(fptr1);
  15373. if(ch!=EOF)
  15374. {
  15375. // printf("%c",ch);
  15376. while (fgets(str, 100, fptr1) != NULL)
  15377. {
  15378. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15379. if(str[0]=='\0')
  15380. {
  15381. break;
  15382. }
  15383. char *revbuf[8] = {0}; // Variable store string split
  15384. int num = 0;// Quantity after string split
  15385. DEBUG_INFO("Transaction queue data= %s\n", str);
  15386. splitstring(str,",",revbuf,&num); // String split
  15387. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15388. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15389. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15390. DEBUG_INFO("------------------------------\n");
  15391. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15392. {
  15393. if(isStopTransaction)
  15394. {
  15395. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15396. {
  15397. temptransactionId = atoi(revbuf[2]);
  15398. //break;
  15399. }
  15400. }
  15401. else
  15402. {
  15403. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15404. {
  15405. temptransactionId = atoi(revbuf[2]);
  15406. //break;
  15407. }
  15408. }
  15409. }
  15410. }
  15411. }
  15412. else
  15413. DEBUG_INFO("EOF\n");
  15414. fclose(fptr1);
  15415. /*------- End of reading ---------------*/
  15416. return temptransactionId;
  15417. }
  15418. void SetTransactionIdZero(int transactionId)
  15419. {
  15420. char ch;
  15421. FILE *fptr1, *fptr2;
  15422. int temptransactionId = 0;
  15423. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15424. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15425. if (!fptr1)
  15426. {
  15427. //printf(" File not found or unable to open the input file!!\n");
  15428. return ;
  15429. }
  15430. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15431. if (!fptr2)
  15432. {
  15433. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15434. fclose(fptr1);
  15435. return ;
  15436. }
  15437. ch=fgetc(fptr1);
  15438. rewind(fptr1);
  15439. if(ch!=EOF)
  15440. {
  15441. // copy all contents to the temporary file except the specific line
  15442. while (fgets(str, 100, fptr1) != NULL)
  15443. {
  15444. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15445. if(str[0]=='\0')
  15446. {
  15447. break;
  15448. }
  15449. char *revbuf[8] = {0};
  15450. int num = 0;
  15451. strcpy(strtemp, str);
  15452. splitstring(str,",",revbuf,&num);
  15453. if(revbuf[2][0] != '\0')
  15454. {
  15455. temptransactionId = atoi(revbuf[2]);
  15456. if(transactionId != temptransactionId)
  15457. {
  15458. fprintf(fptr2, "%s\n", strtemp);
  15459. }
  15460. }
  15461. }
  15462. }
  15463. fclose(fptr1);
  15464. fclose(fptr2);
  15465. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15466. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15467. /*------ Read the file ----------------*/
  15468. }
  15469. int InternetDisconnect(void)
  15470. {
  15471. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15472. }
  15473. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15474. void storeTempStopTransaction(int gun_index)
  15475. {
  15476. char guid[37]={0};
  15477. int tempIndex = 0;
  15478. char TempStopTransaction[256];
  15479. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15480. DEBUG_INFO("storeTempStopTransaction...\n");
  15481. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15482. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15483. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15484. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15485. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15486. {
  15487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15488. {
  15489. tempIndex = ((gun_index==2) ? 1: 0);
  15490. }
  15491. else
  15492. {
  15493. tempIndex = gun_index;
  15494. }
  15495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15496. {
  15497. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15498. {
  15499. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15500. }
  15501. }// END OF CHAdeMO_QUANTITY
  15502. }
  15503. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15504. {
  15505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15506. {
  15507. tempIndex = ((gun_index==2) ? 1: 0);
  15508. }
  15509. else
  15510. {
  15511. tempIndex = gun_index;
  15512. }
  15513. for (int index = 0; index < CCS_QUANTITY; index++)
  15514. {
  15515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15516. {
  15517. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15518. }
  15519. }// END OF CCS_QUANTITY
  15520. }
  15521. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15522. {
  15523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15524. {
  15525. tempIndex = ((gun_index==2) ? 1: 0);
  15526. }
  15527. else
  15528. {
  15529. tempIndex = gun_index;
  15530. }
  15531. for (int index = 0; index < GB_QUANTITY; index++)
  15532. {
  15533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15534. {
  15535. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15536. }
  15537. }// END OF GB_QUANTITY
  15538. }
  15539. else if(gunType[gun_index] == GUN_TYPE_DO)
  15540. {
  15541. tempIndex = gun_index;
  15542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15543. {
  15544. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15545. {
  15546. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15547. }
  15548. }
  15549. }
  15550. else
  15551. {
  15552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15553. {
  15554. tempIndex = 2;
  15555. }
  15556. else
  15557. {
  15558. tempIndex = gun_index;
  15559. }
  15560. for (int index = 0; index < AC_QUANTITY; index++)
  15561. {
  15562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15563. {
  15564. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15565. }
  15566. }// END OF AC_QUANTITY
  15567. }
  15568. //Stop Transaction Time
  15569. struct timeval tmnow;
  15570. struct tm *tm;
  15571. char buf[28];//, usec_buf[6];
  15572. gettimeofday(&tmnow, NULL);
  15573. time_t t;
  15574. t = time(NULL);
  15575. /*UTC time and date*/
  15576. tm = gmtime(&t);
  15577. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15579. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15581. random_uuid(guid);
  15582. /***********************************transactionData******************************************************/
  15583. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15585. //=================================
  15586. //1. Transaction_Begin
  15587. //=================================
  15588. //============================== Energy.Active.Import.Interval ===========================================
  15589. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15590. {
  15591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15594. 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*/]);
  15595. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15596. 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))
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15599. }
  15600. else
  15601. {
  15602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15603. }
  15604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15606. }
  15607. //=================================
  15608. //2. Transaction_End
  15609. //=================================
  15610. //2.1====================================== Current.Import L1 ==============================================
  15611. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15612. {
  15613. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15614. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15615. {
  15616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15617. {
  15618. tempIndex = ((gun_index==2) ? 1: 0);
  15619. }
  15620. else
  15621. {
  15622. tempIndex = gun_index;
  15623. }
  15624. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15625. {
  15626. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15627. {
  15628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15629. }
  15630. }// End of for CHAdeMO_QUANTITY
  15631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15632. }
  15633. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  15644. {
  15645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15646. {
  15647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15648. }
  15649. }// End of for CCS_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_GBT)
  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 < GB_QUANTITY; index++)
  15663. {
  15664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15665. {
  15666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15667. }
  15668. }// End of for GB_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_DO)
  15672. {
  15673. tempIndex = gun_index;
  15674. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15675. {
  15676. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15677. {
  15678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15679. }
  15680. }
  15681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15682. }
  15683. else
  15684. {
  15685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15686. {
  15687. tempIndex = 2;
  15688. }
  15689. else
  15690. {
  15691. tempIndex = gun_index;
  15692. }
  15693. for (int index = 0; index < AC_QUANTITY; index++)
  15694. {
  15695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15696. {
  15697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15698. }
  15699. }// End of for AC_QUANTITY
  15700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15701. }
  15702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15705. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15708. }
  15709. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15710. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15711. {
  15712. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15713. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15714. {
  15715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15716. {
  15717. tempIndex = ((gun_index==2) ? 1: 0);
  15718. }
  15719. else
  15720. {
  15721. tempIndex = gun_index;
  15722. }
  15723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15724. {
  15725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15726. {
  15727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15728. }
  15729. }// END OF CHAdeMO_QUANTITY
  15730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15731. }
  15732. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  15743. {
  15744. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15745. {
  15746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15747. }
  15748. }// END OF CCS_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_GBT)
  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 < GB_QUANTITY; index++)
  15762. {
  15763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15764. {
  15765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15766. }
  15767. }// END OF GB_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_DO)
  15771. {
  15772. tempIndex = gun_index;
  15773. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15774. {
  15775. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15776. {
  15777. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15778. }
  15779. }
  15780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15781. }
  15782. else
  15783. {
  15784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15785. {
  15786. tempIndex = 2;
  15787. }
  15788. else
  15789. {
  15790. tempIndex = gun_index;
  15791. }
  15792. for (int index = 0; index < AC_QUANTITY; index++)
  15793. {
  15794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15795. {
  15796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15797. }
  15798. }// END OF AC_QUANTITY
  15799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15800. }
  15801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15804. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15807. }
  15808. //2.3====================================== Power.Active.Import =========================================
  15809. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15810. {
  15811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15812. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15813. {
  15814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15815. {
  15816. tempIndex = ((gun_index==2) ? 1: 0);
  15817. }
  15818. else
  15819. {
  15820. tempIndex = gun_index;
  15821. }
  15822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15823. {
  15824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15825. {
  15826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15827. }
  15828. } // End for CHAdeMO_QUANTITY
  15829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15830. }
  15831. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  15842. {
  15843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15844. {
  15845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15846. }
  15847. } // END for CCS_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_GBT)
  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 < GB_QUANTITY; index++)
  15861. {
  15862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15863. {
  15864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15865. }
  15866. }// END for GB_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_DO)
  15870. {
  15871. tempIndex = gun_index;
  15872. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15873. {
  15874. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15875. {
  15876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15877. }
  15878. }
  15879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15880. }
  15881. else
  15882. {
  15883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15884. {
  15885. tempIndex = 2;
  15886. }
  15887. else
  15888. {
  15889. tempIndex = gun_index;
  15890. }
  15891. for (int index = 0; index < AC_QUANTITY; index++)
  15892. {
  15893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15894. {
  15895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15896. }
  15897. } // END for AC_QUANTITY
  15898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15899. }
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15903. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15906. }
  15907. //2.4====================================== Voltage L1 ====================================================
  15908. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15909. {
  15910. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15912. {
  15913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15914. {
  15915. tempIndex = ((gun_index==2) ? 1: 0);
  15916. }
  15917. else
  15918. {
  15919. tempIndex = gun_index;
  15920. }
  15921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15922. {
  15923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15924. {
  15925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15926. }
  15927. } // END OF FOR CHAdeMO_QUANTITY
  15928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15929. }
  15930. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  15941. {
  15942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15943. {
  15944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15945. }
  15946. } // END OF FOR CCS_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_GBT)
  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 < GB_QUANTITY; index++)
  15960. {
  15961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15962. {
  15963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15964. }
  15965. } // END OF FOR GB_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_DO)
  15969. {
  15970. tempIndex = gun_index;
  15971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15972. {
  15973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15974. {
  15975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15976. }
  15977. }
  15978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15979. }
  15980. else
  15981. {
  15982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15983. {
  15984. tempIndex = 2;
  15985. }
  15986. else
  15987. {
  15988. tempIndex = gun_index;
  15989. }
  15990. for (int index = 0; index < AC_QUANTITY; index++)
  15991. {
  15992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15993. {
  15994. 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
  15995. }
  15996. } // END OF FOR AC_QUANTITY
  15997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15998. }
  15999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16002. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16005. }
  16006. //2.5============================================== End SoC =========================================================
  16007. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16008. {
  16009. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16010. 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))
  16011. {
  16012. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16013. {
  16014. tempIndex = ((gun_index==2) ? 1: 0);
  16015. }
  16016. else
  16017. {
  16018. tempIndex = gun_index;
  16019. }
  16020. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16021. {
  16022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16023. {
  16024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16025. {
  16026. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16027. }
  16028. }
  16029. }
  16030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16031. {
  16032. for (int index = 0; index < CCS_QUANTITY; index++)
  16033. {
  16034. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16035. {
  16036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16037. }
  16038. }
  16039. }
  16040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16041. {
  16042. for (int index = 0; index < GB_QUANTITY; index++)
  16043. {
  16044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16045. {
  16046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16047. }
  16048. }
  16049. }
  16050. else if(gunType[gun_index] == GUN_TYPE_DO)
  16051. {
  16052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16053. {
  16054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16055. {
  16056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16057. }
  16058. }
  16059. }
  16060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16066. } // END FOR DC CASE
  16067. }
  16068. //2.6====================================== Current.Import L2 ==============================================
  16069. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16070. {
  16071. // AC 3 phase L2 current
  16072. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16073. {
  16074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16075. {
  16076. tempIndex = 2;
  16077. }
  16078. else
  16079. {
  16080. tempIndex = gun_index;
  16081. }
  16082. for (int index = 0; index < AC_QUANTITY; index++)
  16083. {
  16084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16085. {
  16086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16087. }
  16088. }// End of for AC_QUANTITY
  16089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16090. }
  16091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16096. }
  16097. //2.7====================================== Current.Import L3 ==============================================
  16098. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16099. {
  16100. // AC 3 phase L3 current
  16101. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16102. {
  16103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16104. {
  16105. tempIndex = 2;
  16106. }
  16107. else
  16108. {
  16109. tempIndex = gun_index;
  16110. }
  16111. for (int index = 0; index < AC_QUANTITY; index++)
  16112. {
  16113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16114. {
  16115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16116. }
  16117. }// End of for AC_QUANTITY
  16118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16119. }
  16120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16125. }
  16126. //2.9====================================== Voltage L2 ====================================================
  16127. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16128. {
  16129. // AC 3 phase L2 volatge
  16130. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16131. {
  16132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16133. {
  16134. tempIndex = 2;
  16135. }
  16136. else
  16137. {
  16138. tempIndex = gun_index;
  16139. }
  16140. for (int index = 0; index < AC_QUANTITY; index++)
  16141. {
  16142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16143. {
  16144. 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
  16145. }
  16146. } // END OF FOR AC_QUANTITY
  16147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16148. }
  16149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16154. }
  16155. //2.10====================================== Voltage L3 ====================================================
  16156. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16157. {
  16158. // AC 3 phase L3 volatge
  16159. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16160. {
  16161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16162. {
  16163. tempIndex = 2;
  16164. }
  16165. else
  16166. {
  16167. tempIndex = gun_index;
  16168. }
  16169. for (int index = 0; index < AC_QUANTITY; index++)
  16170. {
  16171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16172. {
  16173. 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
  16174. }
  16175. } // END OF FOR AC_QUANTITY
  16176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16177. }
  16178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16183. }
  16184. //====================== Start SoC ================================
  16185. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16186. {
  16187. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16188. 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))
  16189. {
  16190. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16191. {
  16192. tempIndex = ((gun_index==2) ? 1: 0);
  16193. }
  16194. else
  16195. {
  16196. tempIndex = gun_index;
  16197. }
  16198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16199. {
  16200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16201. {
  16202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16203. {
  16204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16205. }
  16206. }
  16207. }
  16208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16209. {
  16210. for (int index = 0; index < CCS_QUANTITY; index++)
  16211. {
  16212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16213. {
  16214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16215. }
  16216. }
  16217. }
  16218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16219. {
  16220. for (int index = 0; index < GB_QUANTITY; index++)
  16221. {
  16222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16223. {
  16224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16225. }
  16226. }
  16227. }
  16228. else if(gunType[gun_index] == GUN_TYPE_DO)
  16229. {
  16230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16231. {
  16232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16233. {
  16234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16235. }
  16236. }
  16237. }
  16238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16244. } // END FOR DC CASE
  16245. }
  16246. //======================================== Message create ==============================================
  16247. json_object *StopTransaction = json_object_new_object();
  16248. json_object *transactionDatas = json_object_new_array();
  16249. json_object *sampledValues = json_object_new_array();
  16250. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16251. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16252. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16253. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16254. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16255. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16256. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16257. {
  16258. json_object *transactionData = json_object_new_object();
  16259. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16260. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16261. {
  16262. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16263. {
  16264. json_object *sampledValue = json_object_new_object();
  16265. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16266. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16267. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16268. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16269. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16270. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16271. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16272. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16273. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16274. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16275. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16276. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16277. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16278. json_object_array_add(sampledValues, sampledValue);
  16279. }
  16280. }
  16281. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16282. json_object_array_add(transactionDatas, transactionData);
  16283. }
  16284. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16285. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16286. ,MESSAGE_TYPE_CALL
  16287. ,guid
  16288. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16289. json_object_put(StopTransaction);
  16290. // Check File "TempStopTransaction" Exist
  16291. if((access(TempStopTransaction,F_OK))!=-1)
  16292. {
  16293. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16294. fclose(fopen(TempStopTransaction, "w"));
  16295. }
  16296. else
  16297. {
  16298. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16299. FILE *log = fopen(TempStopTransaction, "w+");
  16300. if(log == NULL)
  16301. {
  16302. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16303. return ;
  16304. }
  16305. else
  16306. {
  16307. fclose(log);
  16308. }
  16309. }
  16310. //Add TempStopTransaction | Update TempStopTransaction
  16311. // open file for writing
  16312. FILE *outfile;
  16313. outfile = fopen (TempStopTransaction, "a");
  16314. //DEBUG_INFO("data = %s\n", queuedata);
  16315. fputs(queuedata, outfile);
  16316. fputs("\n", outfile);
  16317. fclose (outfile);
  16318. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16319. }
  16320. void checkTempStopTransaction(int gun_index)
  16321. {
  16322. FILE *fptr1;
  16323. char ch;
  16324. char str[QUEUE_MESSAGE_LENGTH]={0};
  16325. char guid[37]={0};
  16326. char tempdata[65]={0};
  16327. char connectorStr[2]={0};
  16328. char TempStopTransaction[256];
  16329. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16330. fptr1 = fopen(TempStopTransaction, "r");
  16331. //TempStopTransaction格式: 槍號,StopTransaction封包
  16332. if (!fptr1)
  16333. {
  16334. //printf(" File not found or unable to open the input file!!\n");
  16335. return ;
  16336. }
  16337. ch=fgetc(fptr1);
  16338. //printf(" Now the content of the file %s is : \n",fname);
  16339. rewind(fptr1);
  16340. if(ch!=EOF)
  16341. {
  16342. // copy all contents to the temporary file except the specific line
  16343. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16344. {
  16345. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16346. if(str[0]=='\0')
  16347. {
  16348. break;
  16349. }
  16350. //TempStopTransaction格式: 槍號,StopTransaction封包
  16351. strncpy(connectorStr, str, 1);
  16352. if(atoi(connectorStr) != (gun_index+1))
  16353. {
  16354. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16355. fclose(fptr1);
  16356. return ;
  16357. }
  16358. //random_uuid(guid);
  16359. strncpy(guid, str+6, 36); //copy guid
  16360. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16361. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16362. {
  16363. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16364. }
  16365. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16366. OCPP_insert_transaction_msg(NO, str);
  16367. memset(str,0,ARRAY_SIZE(str));
  16368. }
  16369. }
  16370. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16371. fclose(fptr1);
  16372. remove(TempStopTransaction); // remove the original file
  16373. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16374. }
  16375. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16376. {
  16377. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16378. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16379. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16380. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16381. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16382. }
  16383. int GetWebSocketPingInterval(void)
  16384. {
  16385. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16386. }
  16387. int GetServerSign(void)
  16388. {
  16389. return server_sign;
  16390. }
  16391. uint8_t GetOcppSecurityProfile()
  16392. {
  16393. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16394. }
  16395. void GetOcppChargerBoxId(uint8_t *data)
  16396. {
  16397. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16398. }
  16399. void GetOcppSecurityPassword(uint8_t *data)
  16400. {
  16401. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16402. }
  16403. void SetOcppVersion(uint8_t *version)
  16404. {
  16405. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16406. DEBUG_INFO("ocpp version: %s\n", version);
  16407. if(strstr((char*)version, "ocpp1.6") != NULL)
  16408. {
  16409. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16410. }
  16411. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16412. {
  16413. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16414. system("pkill OcppBackend");
  16415. }
  16416. }
  16417. void SetServerSign(int value)
  16418. {
  16419. server_sign = value;
  16420. }
  16421. int GetBootNotificationInterval(void)
  16422. {
  16423. return BootNotificationInterval;
  16424. }
  16425. int GetInternetConn(void)
  16426. {
  16427. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16428. }
  16429. int GetBackendConnectionTimeout(void)
  16430. {
  16431. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16432. }
  16433. int isConnectorInitMode(int gun_index)
  16434. {
  16435. int tempIndex = 0;
  16436. int result = TRUE;
  16437. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16438. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16439. {
  16440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16441. {
  16442. tempIndex = ((gun_index==2) ? 1: 0);
  16443. }
  16444. else
  16445. {
  16446. tempIndex = gun_index;
  16447. }
  16448. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16449. {
  16450. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16451. {
  16452. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16453. } //end of the same index
  16454. }//end of for CHAdeMO_QUANTITY
  16455. }
  16456. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16457. {
  16458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16459. {
  16460. tempIndex = ((gun_index==2) ? 1: 0);
  16461. }
  16462. else
  16463. {
  16464. tempIndex = gun_index;
  16465. }
  16466. for (int index = 0; index < CCS_QUANTITY; index++)
  16467. {
  16468. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16469. {
  16470. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16471. } //end of the same index
  16472. } // end of for CCS_QUANTITY
  16473. }
  16474. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16475. {
  16476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16477. {
  16478. tempIndex = ((gun_index==2) ? 1: 0);
  16479. }
  16480. else
  16481. {
  16482. tempIndex = gun_index;
  16483. }
  16484. for (int index = 0; index < GB_QUANTITY; index++)
  16485. {
  16486. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16487. {
  16488. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16489. } //end of the same index
  16490. } // end of for GB_QUANTITY
  16491. }
  16492. else if(gunType[gun_index] == GUN_TYPE_DO)
  16493. {
  16494. tempIndex = gun_index;
  16495. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16496. {
  16497. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16498. {
  16499. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16500. } //end of the same index
  16501. }
  16502. }
  16503. else
  16504. {
  16505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16506. {
  16507. tempIndex = 2;
  16508. }
  16509. else
  16510. {
  16511. tempIndex = gun_index;
  16512. }
  16513. for (int index = 0; index < AC_QUANTITY; index++)
  16514. {
  16515. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16516. {
  16517. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16518. }//end of the same index
  16519. }//end of for AC_QUANTITY
  16520. }
  16521. return result;
  16522. }
  16523. void refreshProcDogTimer()
  16524. {
  16525. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16526. }
  16527. void InitialSystemValue(void)
  16528. {
  16529. int connectorIndex = 0;
  16530. //int valueASCII = 0;
  16531. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16532. gunTotalNumber=0;
  16533. SystemInitial = 0;
  16534. locallistVersion=0;
  16535. BootNotificationInterval = 0;
  16536. authorizeRetryTimes = 0;
  16537. GunStatusInterval = 10;
  16538. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16539. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16540. //Hear Beat
  16541. HeartBeatWithNOResponse = 0;
  16542. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16543. FirstHeartBeat = 0;
  16544. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16545. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16546. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16547. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16548. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16549. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16550. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16551. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16552. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16553. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16554. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16555. memset(gunType, 0, ARRAY_SIZE(gunType));
  16556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16557. {
  16558. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16559. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16560. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16561. {
  16562. // DO series
  16563. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16564. {
  16565. SystemInitial = SystemInitial + 1;
  16566. gunTotalNumber = gunTotalNumber + 1;
  16567. gunType[connectorIndex] = GUN_TYPE_DO;
  16568. connectorIndex = connectorIndex + 1;
  16569. }
  16570. }
  16571. else
  16572. {
  16573. // DM, DW, DS series
  16574. //check connector / socket type (index: 8, 9, 10)
  16575. for(int index=7; index <10 ; index++)
  16576. {
  16577. if(index != 8)
  16578. {
  16579. // DC Connector
  16580. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16581. {
  16582. SystemInitial = SystemInitial + 1;
  16583. gunTotalNumber = gunTotalNumber + 1;
  16584. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16585. connectorIndex = connectorIndex + 1;
  16586. }
  16587. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16588. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16589. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16590. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16591. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16592. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16593. {
  16594. SystemInitial = SystemInitial + 1;
  16595. gunTotalNumber = gunTotalNumber + 1;
  16596. gunType[connectorIndex] = GUN_TYPE_CCS;
  16597. connectorIndex = connectorIndex + 1;
  16598. }
  16599. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16600. {
  16601. SystemInitial = SystemInitial + 1;
  16602. gunTotalNumber = gunTotalNumber + 1;
  16603. gunType[connectorIndex] = GUN_TYPE_GBT;
  16604. connectorIndex = connectorIndex + 1;
  16605. }
  16606. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16607. {
  16608. SystemInitial = SystemInitial + 1;
  16609. gunTotalNumber = gunTotalNumber + 1;
  16610. gunType[connectorIndex] = GUN_TYPE_DO;
  16611. connectorIndex = connectorIndex + 1;
  16612. }
  16613. }
  16614. else
  16615. {
  16616. // AC Connector
  16617. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16618. {
  16619. SystemInitial = SystemInitial + 1;
  16620. gunTotalNumber = gunTotalNumber + 1;
  16621. gunType[connectorIndex] = GUN_TYPE_AC;
  16622. connectorIndex = connectorIndex + 1;
  16623. }
  16624. }
  16625. }
  16626. }
  16627. //DEBUG_INFO("DC ...\n");
  16628. }
  16629. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16630. {
  16631. //check connector / socket type (index: 8, 9, 10)
  16632. for(int index=7; index <10 ; index++)
  16633. {
  16634. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16635. {
  16636. SystemInitial = SystemInitial + 1;
  16637. gunTotalNumber = gunTotalNumber + 1;
  16638. gunType[connectorIndex] = GUN_TYPE_AC;
  16639. connectorIndex = connectorIndex + 1;
  16640. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16641. }
  16642. }
  16643. }
  16644. //Status && ConnectorPlugIn Setting
  16645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16646. {
  16647. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16648. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16649. }
  16650. for (int index = 0; index < CCS_QUANTITY; index++)
  16651. {
  16652. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16653. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16654. }
  16655. for (int index = 0; index < GB_QUANTITY; index++)
  16656. {
  16657. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16658. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16659. }
  16660. for (int index = 0; index < AC_QUANTITY; index++)
  16661. {
  16662. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16663. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16664. }
  16665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16666. {
  16667. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16668. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16669. }
  16670. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16671. {
  16672. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16673. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16674. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16675. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16676. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16677. }
  16678. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16679. clientTime.Heartbeat=time((time_t*)NULL);
  16680. sleep(1);
  16681. }
  16682. void LWS_Send(char *str)
  16683. {
  16684. //=====================================================
  16685. // Check InternetConn 0: disconnected, 1: connected
  16686. //====================================================
  16687. if(GetOcppConnStatus() == 0)
  16688. {
  16689. DEBUG_INFO("offline now !!!\n");
  16690. return;
  16691. }
  16692. // Only disable isWebsocketSendable operation initiated by charger
  16693. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16694. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16695. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16696. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16697. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16698. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16699. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16700. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16701. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16702. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16703. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16704. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16705. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16706. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16707. {
  16708. isWebsocketSendable = 0;
  16709. }
  16710. pthread_mutex_lock(&lock_send);
  16711. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16712. sprintf((char *)SendBuffer, "%s", str);
  16713. SendBufLen = strlen(str);
  16714. pthread_mutex_unlock(&lock_send);
  16715. lws_callback_on_writable(wsi_client);
  16716. //lws_service(context, 0);
  16717. //sleep(1);
  16718. }
  16719. void LWS_SendNow(char *str)
  16720. {
  16721. //=====================================================
  16722. // Check InternetConn 0: disconnected, 1: connected
  16723. //====================================================
  16724. if(GetOcppConnStatus() == 0)
  16725. {
  16726. DEBUG_INFO("offline now !!!\n");
  16727. return;
  16728. }
  16729. // Only disable isWebsocketSendable operation initiated by charger
  16730. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16731. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16732. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16733. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16734. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16735. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16736. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16737. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16738. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16739. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16740. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16741. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16742. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16743. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16744. {
  16745. isWebsocketSendable = 0;
  16746. }
  16747. pthread_mutex_lock(&lock_send);
  16748. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16749. sprintf((char *)SendBuffer, "%s", str);
  16750. SendBufLen = strlen(str);
  16751. pthread_mutex_unlock(&lock_send);
  16752. lws_callback_on_writable(wsi_client);
  16753. lws_service(context, 0);
  16754. //sleep(1);
  16755. }