MessageHandler.c 845 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  499. {
  500. struct tm *tmTarget;
  501. struct timeb tbTarget;
  502. tmStart.tm_year -= 1900;
  503. tmStart.tm_mon -= 1;
  504. tmStart.tm_gmtoff = 0;
  505. tbTarget.time = mktime(&tmStart);
  506. tbTarget.timezone = 0;
  507. tbTarget.time += (8*3600);
  508. tmTarget = gmtime(&tbTarget.time);
  509. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  510. tx_buf[65] = (tmTarget->tm_mon+1);
  511. tx_buf[66] = tmTarget->tm_mday;
  512. tx_buf[67] = tmTarget->tm_hour;
  513. tx_buf[68] = tmTarget->tm_min;
  514. tx_buf[69] = tmTarget->tm_sec;
  515. }
  516. // Stop date time 6 bytes
  517. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  518. {
  519. struct tm *tmTarget;
  520. struct timeb tbTarget;
  521. tmEnd.tm_year -= 1900;
  522. tmEnd.tm_mon -= 1;
  523. tmEnd.tm_gmtoff = 0;
  524. tbTarget.time = mktime(&tmEnd);
  525. tbTarget.timezone = 0;
  526. tbTarget.time += (8*3600);
  527. tmTarget = gmtime(&tbTarget.time);
  528. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  529. tx_buf[71] = (tmTarget->tm_mon+1);
  530. tx_buf[72] = tmTarget->tm_mday;
  531. tx_buf[73] = tmTarget->tm_hour;
  532. tx_buf[74] = tmTarget->tm_min;
  533. tx_buf[75] = tmTarget->tm_sec;
  534. }
  535. // Session energy 2 bytes
  536. tx_buf[76] = PresentChargedEnergy & 0xff;
  537. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  538. // Start SOC 1 byte
  539. tx_buf[78] = socStart;
  540. // Stop SOC 1 byte
  541. tx_buf[79] = socEnd;
  542. // Open socket
  543. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  544. if(udp_socket_fd == -1)
  545. {
  546. DEBUG_ERROR("UDP socket create failed!\n");
  547. }
  548. else
  549. {
  550. // Get server DNS entry
  551. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  552. if (server == NULL)
  553. {
  554. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. }
  556. else
  557. {
  558. // Build the server's Internet address
  559. bzero((char *) &dest_addr, sizeof(dest_addr));
  560. dest_addr.sin_family = AF_INET;
  561. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  562. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  563. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  564. {
  565. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  566. {
  567. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  568. }
  569. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  570. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  571. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  572. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  573. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. DEBUG_TTIA_INFO("---------- Header ----------\n");
  575. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  576. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  577. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  578. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  579. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  580. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  581. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  582. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  583. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  584. DEBUG_TTIA_INFO("Len: 0x3C\n");
  585. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  586. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  587. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  588. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  589. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  590. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  591. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  592. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  593. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  594. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  596. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  597. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  598. DEBUG_TTIA_INFO("=========================================\n");
  599. sn++;
  600. result = PASS;
  601. }
  602. else
  603. {
  604. DEBUG_ERROR("UDP sent out fail.\n");
  605. }
  606. }
  607. }
  608. return result;
  609. }
  610. //=========================================
  611. // Save configuration
  612. //=========================================
  613. int runShellCmd(const char*cmd)
  614. {
  615. int result = FAIL;
  616. char buf[256];
  617. FILE *fp;
  618. fp = popen(cmd, "r");
  619. if(fp != NULL)
  620. {
  621. while(fgets(buf, sizeof(buf), fp) != NULL)
  622. {
  623. DEBUG_INFO("%s\n", buf);
  624. }
  625. result = PASS;
  626. }
  627. pclose(fp);
  628. return result;
  629. }
  630. int StoreUsrConfigData(struct SysConfigData *UsrData)
  631. {
  632. int result = PASS;
  633. int fd,wrd;
  634. unsigned int i,Chk;
  635. unsigned char *ptr, *BufTmp;
  636. int MtdBlockSize = 0x300000;
  637. Chk=0;
  638. ptr=(unsigned char *)UsrData;
  639. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  640. {
  641. memset(BufTmp,0,MtdBlockSize);
  642. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  643. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  644. Chk+=*(BufTmp+i);
  645. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  646. // Output configuration to file.
  647. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  648. if (fd < 0)
  649. {
  650. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  651. free(BufTmp);
  652. return 0;
  653. }
  654. wrd=write(fd, BufTmp, MtdBlockSize);
  655. close(fd);
  656. if(wrd<MtdBlockSize)
  657. {
  658. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  663. DEBUG_INFO("Erase /dev/mtd10.\n");
  664. runShellCmd("flash_erase /dev/mtd10 0 0");
  665. DEBUG_INFO("Write /dev/mtd10.\n");
  666. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  667. DEBUG_INFO("Erase /dev/mtd11.\n");
  668. runShellCmd("flash_erase /dev/mtd11 0 0");
  669. DEBUG_INFO("Write /dev/mtd11.\n");
  670. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  671. system("rm -f /mnt/EvseConfig.bin");
  672. DEBUG_INFO("EvseConfig write to flash OK\n");
  673. }
  674. else
  675. {
  676. DEBUG_ERROR("alloc BlockSize NG\r\n");
  677. result = FAIL;
  678. }
  679. if(BufTmp!=NULL)
  680. free(BufTmp);
  681. return result;
  682. }
  683. //=========================================
  684. // Sqlite3 related function
  685. //=========================================
  686. static int selectSqlCount = 0;
  687. static int callback(void *data, int argc, char **argv, char **azColName){
  688. int i;
  689. //printf("%s: ", (const char*)data);
  690. selectSqlCount = argc;
  691. for(i = 0; i<argc; i++){
  692. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  693. }
  694. //printf("\n");
  695. return 0;
  696. }
  697. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  698. //int i;
  699. //printf("%s:\n", (const char*)data);
  700. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  701. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  702. return 0;
  703. }
  704. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  705. //printf("%s:\n", (const char*)data);
  706. //idTag
  707. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  708. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. //parentIdTag
  710. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  711. //expir_date
  712. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  713. //status
  714. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  715. //version
  716. if(columenCount > 5)
  717. idTagQuery.listVersionInt = atoi(columnValue[5]);
  718. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  719. return 0;
  720. }
  721. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  722. {
  723. // localversion = argv[5] ? atoi(argv[5]) : 0;
  724. // printf("localversion=%d\n", localversion);
  725. return 0;
  726. }
  727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  728. {
  729. for (int i = 0; i < n_columns; i++)
  730. {
  731. DEBUG_INFO("%s\t", col_values[i]);
  732. }
  733. DEBUG_INFO("\n");
  734. return 0;
  735. }
  736. int OCPP_cleanLocalCache()
  737. {
  738. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  739. char *errMsg = 0;
  740. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  741. if (SQLITE_OK != rc)
  742. {
  743. DEBUG_INFO("SQL error: %s\n",errMsg);
  744. return FALSE;
  745. }
  746. return TRUE;
  747. }
  748. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  749. {
  750. int isSuccess = TRUE;
  751. int ret = 0;
  752. //const char* data = "Callback function called";
  753. char sql[300];
  754. char zErrMsg[200];
  755. memset(sql, 0, 300);
  756. memset(zErrMsg, 0, 200);
  757. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  758. //* Execute SQL statement */
  759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  760. if( ret != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. isSuccess = FALSE;
  764. }
  765. return isSuccess;
  766. }
  767. void OCPP_getIdTagFromLocalCache(char idTag[])
  768. {
  769. int rc = 0;
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  775. memset(&idTagQuery, 0, sizeof(idTagQuery));
  776. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  777. /* Execute SQL statement */
  778. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  779. if( rc != SQLITE_OK )
  780. {
  781. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  782. }
  783. }
  784. void OCPP_getListVerion()
  785. {
  786. int rc = 0;
  787. // const char* data = "Callback function called";
  788. char sql[100];
  789. char zErrMsg[100];
  790. memset(sql, 0, 100);
  791. memset(zErrMsg, 0, 100);
  792. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  793. /* Execute SQL statement */
  794. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  795. if( rc != SQLITE_OK )
  796. {
  797. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  798. }
  799. }
  800. void OCPP_get_TableAuthlocalAllData(void)
  801. {
  802. int rc = 0;
  803. char sql[100];
  804. char zErrMsg[100];
  805. memset(sql, 0, 100);
  806. memset(zErrMsg, 0, 100);
  807. sprintf(sql,"select * from ocpp_auth_local ");
  808. /* Execute SQL statement */
  809. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  810. if( rc != SQLITE_OK )
  811. {
  812. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  813. }
  814. //return ver;
  815. }
  816. int OCPP_cleanLocalList()
  817. {
  818. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  819. char *errMsg = 0;
  820. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  821. if (SQLITE_OK != rc)
  822. {
  823. DEBUG_INFO("%s\n",errMsg);
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  829. {
  830. int isSuccess = FALSE;
  831. int ret = 0;
  832. //const char* data = "Callback function called";
  833. char sql[300];
  834. char zErrMsg[200];
  835. memset(sql, 0, 300);
  836. memset(zErrMsg, 0, 200);
  837. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  838. //* Execute SQL statement */
  839. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  840. if( ret != SQLITE_OK )
  841. {
  842. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  843. return isSuccess;
  844. }
  845. memset(sql, 0, 300);
  846. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  847. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. isSuccess = TRUE;
  854. return isSuccess;
  855. }
  856. void OCPP_getIdTagFromLocalList(char idTag[])
  857. {
  858. int rc = 0;
  859. // const char* data = "Callback function called";
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  866. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  867. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  868. /* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. //return ver;
  875. }
  876. void OCPP_deleteIdTagFromLocalList(char idTag[])
  877. {
  878. //int ver = 0;
  879. //int isSuccess = FALSE;
  880. int rc = 0;
  881. char sql[100];
  882. char zErrMsg[100];
  883. memset(sql, 0, 100);
  884. memset(zErrMsg, 0, 100);
  885. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  886. //* Execute SQL statement */
  887. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  888. if( rc != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. }
  892. }
  893. int getCurrentYear()
  894. {
  895. int result = 0;
  896. time_t CurrentTime;
  897. struct tm *tm;
  898. CurrentTime = time(NULL);
  899. tm=localtime(&CurrentTime);
  900. result = (tm->tm_year + 1900);
  901. return result;
  902. }
  903. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  904. {
  905. int result = PASS;
  906. char* errMsg = NULL;
  907. char sqlStr[8192];
  908. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  909. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  913. }
  914. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  919. }
  920. return result;
  921. }
  922. //==========================================
  923. // Check time passed since today
  924. //==========================================
  925. long long DiffTimebWithNow(struct timeb ST)
  926. {
  927. //return milli-second
  928. struct timeb ET;
  929. long long StartTime,StopTime;
  930. ftime(&ET);
  931. StartTime=(long long)ST.time;
  932. StopTime=(long long)ET.time;
  933. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  934. }
  935. int getTimePassSinceToday(uint8_t gun_index)
  936. {
  937. int result = -1;
  938. static time_t lastTime[4];
  939. time_t t;
  940. struct tm *tmStartToday;
  941. struct timeb tbStartToday;
  942. t=time(NULL);
  943. if(difftime(t, lastTime[gun_index])>0)
  944. {
  945. tmStartToday=localtime(&t);
  946. tmStartToday->tm_hour = 0;
  947. tmStartToday->tm_min = 0;
  948. tmStartToday->tm_sec = 0;
  949. tbStartToday.time = mktime(tmStartToday);
  950. tbStartToday.millitm = 0;
  951. result = DiffTimebWithNow(tbStartToday)/1000;
  952. lastTime[gun_index] = t;
  953. }
  954. return result;
  955. }
  956. void getNowDatetime(uint8_t *data)
  957. {
  958. time_t t = time(NULL);
  959. struct tm tm = *localtime(&t);
  960. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  961. }
  962. int syncDateTimeRTC(uint8_t *data)
  963. {
  964. struct ParsingResult
  965. {
  966. int result;
  967. int scanedElement;
  968. int year;
  969. int month;
  970. int mday;
  971. int hour;
  972. int min;
  973. int sec;
  974. int tz_hour;
  975. int tz_min;
  976. float minSec;
  977. }result;
  978. struct tm tmOrg;
  979. struct tm *tmTarget;
  980. struct timeb tbTarget;
  981. char buf[128];
  982. memset(&result, 0x00, sizeof(struct ParsingResult));
  983. result.result = PASS;
  984. if(strstr((char*)data, ".") != NULL)
  985. {
  986. // Original data with mini second
  987. if(strstr((char*)data, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  991. &result.year,
  992. &result.month,
  993. &result.mday,
  994. &result.hour,
  995. &result.min,
  996. &result.sec,
  997. &result.minSec);
  998. }
  999. else
  1000. {
  1001. // Original data without Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec,
  1009. &result.minSec,
  1010. &result.tz_hour,
  1011. &result.tz_min);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. // Original data without mini second
  1017. if(strstr((char*)data, "Z") != NULL)
  1018. {
  1019. // Original data with Z
  1020. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1021. &result.year,
  1022. &result.month,
  1023. &result.mday,
  1024. &result.hour,
  1025. &result.min,
  1026. &result.sec);
  1027. }
  1028. else
  1029. {
  1030. // Original data without Z
  1031. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1032. &result.year,
  1033. &result.month,
  1034. &result.mday,
  1035. &result.hour,
  1036. &result.min,
  1037. &result.sec,
  1038. &result.tz_hour,
  1039. &result.tz_min);
  1040. }
  1041. }
  1042. tmOrg.tm_year = result.year - 1900;
  1043. tmOrg.tm_mon = result.month - 1;
  1044. tmOrg.tm_mday = result.mday;
  1045. tmOrg.tm_hour = result.hour;
  1046. tmOrg.tm_min = result.min;
  1047. tmOrg.tm_sec = result.sec;
  1048. tmOrg.tm_gmtoff = 0;
  1049. tbTarget.time = mktime(&tmOrg);
  1050. tbTarget.timezone = 0;
  1051. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1052. tmTarget = gmtime(&tbTarget.time);
  1053. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1054. //DEBUG_INFO(" org date time: %s\n", data);
  1055. //DEBUG_INFO("parse date time: %s\n", buf);
  1056. system(buf);
  1057. system("/sbin/hwclock -w --systohc");
  1058. if(result.scanedElement < 6)
  1059. result.result = FAIL;
  1060. return result.result;
  1061. }
  1062. //==========================================
  1063. // GetCompositeSchedule logic related function
  1064. //==========================================
  1065. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1066. {
  1067. //return milli-second
  1068. unsigned int StartTime,StopTime;
  1069. StartTime=(unsigned int)ST.time;
  1070. StopTime=(unsigned int)ET.time;
  1071. return (StopTime-StartTime);
  1072. }
  1073. int DiffTimebWithNowSec(struct timeb ST)
  1074. {
  1075. //return milli-second
  1076. struct timeb ET;
  1077. unsigned int StartTime,StopTime;
  1078. ftime(&ET);
  1079. StartTime=(unsigned int)ST.time;
  1080. StopTime=(unsigned int)ET.time;
  1081. return (StopTime-StartTime);
  1082. }
  1083. int getStartStop(uint8_t *start, uint8_t *stop)
  1084. {
  1085. int result = -1;
  1086. struct tm tmStart;
  1087. struct timeb tbStart;
  1088. struct tm tmStop;
  1089. struct timeb tbStop;
  1090. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1091. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1092. {
  1093. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1094. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1095. tmStart.tm_year -= 1900;
  1096. tmStart.tm_mon -= 1;
  1097. tbStart.time = mktime(&tmStart);
  1098. tbStart.millitm = 0;
  1099. tmStop.tm_year -= 1900;
  1100. tmStop.tm_mon -= 1;
  1101. tbStop.time = mktime(&tmStop);
  1102. tbStop.millitm = 0;
  1103. result = DiffTimebSec(tbStart, tbStop);
  1104. //DEBUG_INFO("getStartStop(): %d\n", result);
  1105. }
  1106. else
  1107. {
  1108. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1109. }
  1110. return result;
  1111. }
  1112. int isOvertNow(uint8_t *start)
  1113. {
  1114. int result = NO;
  1115. struct ParsingResult
  1116. {
  1117. int result;
  1118. int scanedElement;
  1119. int year;
  1120. int month;
  1121. int mday;
  1122. int hour;
  1123. int min;
  1124. int sec;
  1125. int tz_hour;
  1126. int tz_min;
  1127. float minSec;
  1128. }parsingResult;
  1129. struct tm tmStart;
  1130. struct timeb tbStart;
  1131. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1132. if(strstr((char*)start, ".") != NULL)
  1133. {
  1134. // Original data with mini second
  1135. if(strstr((char*)start, "Z") != NULL)
  1136. {
  1137. // Original data with Z
  1138. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1139. &parsingResult.year,
  1140. &parsingResult.month,
  1141. &parsingResult.mday,
  1142. &parsingResult.hour,
  1143. &parsingResult.min,
  1144. &parsingResult.sec,
  1145. &parsingResult.minSec);
  1146. }
  1147. else
  1148. {
  1149. // Original data without Z
  1150. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1151. &parsingResult.year,
  1152. &parsingResult.month,
  1153. &parsingResult.mday,
  1154. &parsingResult.hour,
  1155. &parsingResult.min,
  1156. &parsingResult.sec,
  1157. &parsingResult.minSec,
  1158. &parsingResult.tz_hour,
  1159. &parsingResult.tz_min);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. // Original data without mini second
  1165. if(strstr((char*)start, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec);
  1175. }
  1176. else
  1177. {
  1178. // Original data without Z
  1179. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1180. &parsingResult.year,
  1181. &parsingResult.month,
  1182. &parsingResult.mday,
  1183. &parsingResult.hour,
  1184. &parsingResult.min,
  1185. &parsingResult.sec,
  1186. &parsingResult.tz_hour,
  1187. &parsingResult.tz_min);
  1188. }
  1189. }
  1190. if(parsingResult.scanedElement >= 6)
  1191. {
  1192. tmStart.tm_year = parsingResult.year - 1900;
  1193. tmStart.tm_mon = parsingResult.month - 1;
  1194. tmStart.tm_mday = parsingResult.mday;
  1195. tmStart.tm_hour = parsingResult.hour;
  1196. tmStart.tm_min = parsingResult.min;
  1197. tmStart.tm_sec = parsingResult.sec;
  1198. tmStart.tm_gmtoff = 0;
  1199. tbStart.time = mktime(&tmStart);
  1200. tbStart.timezone = 0;
  1201. tbStart.millitm = 0;
  1202. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1203. if(DiffTimebWithNowSec(tbStart) <= 0)
  1204. result = NO;
  1205. else
  1206. result = YES;
  1207. }
  1208. else
  1209. {
  1210. DEBUG_WARN("Start date parsing error.\n");
  1211. }
  1212. return result;
  1213. }
  1214. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1215. {
  1216. int result = -1;
  1217. struct tm tmStart;
  1218. struct timeb tbStart;
  1219. struct tm tmStop;
  1220. struct timeb tbStop;
  1221. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1222. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1223. {
  1224. tmStart.tm_year -= 1900;
  1225. tmStart.tm_mon -= 1;
  1226. tbStart.time = mktime(&tmStart);
  1227. tbStart.millitm = 0;
  1228. tmStop.tm_year -= 1900;
  1229. tmStop.tm_mon -= 1;
  1230. tbStop.time = mktime(&tmStop);
  1231. tbStop.millitm = 0;
  1232. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1233. }
  1234. return result;
  1235. }
  1236. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1237. {
  1238. FILE *fp;
  1239. char profileFileName[128];
  1240. char *line = NULL;
  1241. size_t len = 0;
  1242. time_t CurrentTime;
  1243. struct tm *tmComposite;
  1244. struct StructChargingProfile maxProfile;
  1245. uint8_t limitMax=0;
  1246. int compositePeriodIdx = 0;
  1247. CurrentTime = time(NULL);
  1248. tmComposite=localtime(&CurrentTime);
  1249. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1250. if(isUnitA)
  1251. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1252. else
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1254. compositeProfile->ChargingSchedule.Duration = durationReq;
  1255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1256. {
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1260. }
  1261. compositeProfile->ChargingProfileId = 0;
  1262. compositeProfile->StackLevel = 99 ;
  1263. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1264. maxProfile.ChargingProfileId = -1;
  1265. maxProfile.ChargingSchedule.Duration = -1;
  1266. system("rm -f /tmp/*.json");
  1267. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1268. // Search max profile
  1269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1270. if((access(profileFileName, F_OK))!=-1)
  1271. {
  1272. fp = fopen(profileFileName, "r");
  1273. while(getline(&line, &len, fp) != -1)
  1274. {
  1275. json_object *obj = NULL;
  1276. obj = json_tokener_parse(line);
  1277. if(is_error(obj))
  1278. {
  1279. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1280. }
  1281. else
  1282. {
  1283. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1284. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1285. )
  1286. {
  1287. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1288. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1289. )
  1290. {
  1291. struct tm tmFrom, tmTo;
  1292. struct timeb tbFrom, tbTo;
  1293. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1294. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1295. {
  1296. tmFrom.tm_year -= 1900;
  1297. tmFrom.tm_mon -= 1;
  1298. tbFrom.time = mktime(&tmFrom);
  1299. tmTo.tm_year -= 1900;
  1300. tmTo.tm_mon -= 1;
  1301. tbTo.time = mktime(&tmTo);
  1302. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1303. {
  1304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1305. {
  1306. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1309. }
  1310. maxProfile.ChargingProfileId = -1;
  1311. maxProfile.StackLevel = -1;
  1312. if(maxProfile.ChargingProfileId == -1)
  1313. DEBUG_INFO("MaxProfile found.\n");
  1314. else
  1315. DEBUG_INFO("MaxProfile updated.\n");
  1316. // Required item
  1317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1320. if(isUnitA)
  1321. {
  1322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1323. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1324. {
  1325. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1326. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1327. 3:
  1328. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1329. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1330. }
  1331. }
  1332. else
  1333. {
  1334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1335. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1336. {
  1337. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1338. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1339. 3:
  1340. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1341. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1342. }
  1343. }
  1344. // Optional item
  1345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)maxProfile.ValidFrom, " ");
  1352. }
  1353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1356. }
  1357. else
  1358. {
  1359. sprintf((char*)maxProfile.ValidTo, " ");
  1360. }
  1361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1368. }
  1369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1370. {
  1371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1372. }
  1373. else
  1374. {
  1375. maxProfile.TransactionId = -1;
  1376. }
  1377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1380. }
  1381. else
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = 86400;
  1384. }
  1385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1386. {
  1387. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1388. }
  1389. else
  1390. {
  1391. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1392. }
  1393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1396. }
  1397. else
  1398. {
  1399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1411. }
  1412. maxProfile.ChargingProfileId = -1;
  1413. maxProfile.StackLevel = -1;
  1414. if(maxProfile.ChargingProfileId == -1)
  1415. DEBUG_INFO("MaxProfile found.\n");
  1416. else
  1417. DEBUG_INFO("MaxProfile updated.\n");
  1418. // Required item
  1419. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1420. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1421. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1422. if(isUnitA)
  1423. {
  1424. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1425. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1426. {
  1427. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1428. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1429. 3:
  1430. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1431. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1432. }
  1433. }
  1434. else
  1435. {
  1436. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1437. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1438. {
  1439. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1440. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1441. 3:
  1442. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1443. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1444. }
  1445. }
  1446. // Optional item
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidFrom, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ValidTo, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1464. {
  1465. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1466. }
  1467. else
  1468. {
  1469. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1470. }
  1471. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1472. {
  1473. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.TransactionId = -1;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1480. {
  1481. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1482. }
  1483. else
  1484. {
  1485. maxProfile.ChargingSchedule.Duration = 86400;
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1488. {
  1489. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1490. }
  1491. else
  1492. {
  1493. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1494. }
  1495. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1496. {
  1497. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1498. }
  1499. else
  1500. {
  1501. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1502. }
  1503. }
  1504. }
  1505. }
  1506. json_object_put(obj);
  1507. }
  1508. fclose(fp);
  1509. /*
  1510. if(maxProfile.ChargingProfileId !=-1)
  1511. {
  1512. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1513. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1514. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1515. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1516. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1517. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1518. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1519. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1520. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1521. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1522. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1526. {
  1527. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1528. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1529. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1530. }
  1531. }
  1532. }
  1533. else
  1534. DEBUG_INFO("MaxProfile not found.\n");
  1535. DEBUG_INFO("------------------------------------\n");*/
  1536. }
  1537. if(maxProfile.ChargingProfileId != -1)
  1538. {
  1539. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1540. {
  1541. if(maxProfile.ChargingSchedule.Duration != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. }
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1552. 0:
  1553. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1554. if(idxPeriod > 0)
  1555. {
  1556. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1565. {
  1566. if(maxProfile.ChargingSchedule.Duration != -1)
  1567. {
  1568. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1569. }
  1570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1571. {
  1572. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1588. {
  1589. if(maxProfile.ChargingSchedule.Duration != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. }
  1595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1596. {
  1597. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1598. {
  1599. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1600. 0:
  1601. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1602. if(idxPeriod > 0)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1605. {
  1606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. else
  1613. {
  1614. if(maxProfile.ChargingSchedule.Duration != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. }
  1620. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1621. {
  1622. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1623. {
  1624. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1625. 0:
  1626. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1627. if(idxPeriod > 0)
  1628. {
  1629. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1630. {
  1631. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1632. }
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. /*
  1639. DEBUG_INFO("MaxProfile after align.\n");
  1640. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1641. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1642. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1643. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1644. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1645. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1646. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1647. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1648. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1649. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1650. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1652. {
  1653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1654. {
  1655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1658. }
  1659. }
  1660. DEBUG_INFO("------------------------------------\n");*/
  1661. }
  1662. // Find each profile period quantity
  1663. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1664. {
  1665. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1666. limitMax = idx+1;
  1667. }
  1668. if(maxProfile.ChargingProfileId != -1)
  1669. {
  1670. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1671. {
  1672. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1673. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1674. (maxProfile.ChargingSchedule.Duration > 0))
  1675. {
  1676. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1677. {
  1678. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1679. compositePeriodIdx++;
  1680. }
  1681. else
  1682. {
  1683. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1684. }
  1685. }
  1686. }
  1687. }
  1688. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1689. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1690. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1691. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1692. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1693. {
  1694. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1695. {
  1696. compositeProfile->ChargingProfileId = 1;
  1697. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1698. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1699. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1700. }
  1701. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1702. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1703. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1704. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1705. }
  1706. if(line)
  1707. free(line);
  1708. }
  1709. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1710. {
  1711. FILE *fp;
  1712. char profileFileName[128];
  1713. char *line = NULL;
  1714. size_t len = 0;
  1715. time_t CurrentTime;
  1716. struct tm *tmComposite;
  1717. struct StructChargingProfile maxProfile;
  1718. struct StructChargingProfile defaultTxProfile;
  1719. struct StructChargingProfile txProfile;
  1720. struct StructChargingSchedulePeriod tmpPeriod;
  1721. uint8_t limitMax=0;
  1722. uint8_t limitDef=0;
  1723. uint8_t limitTx=0;
  1724. int compositePeriodIdx = 0;
  1725. CurrentTime = time(NULL);
  1726. tmComposite=localtime(&CurrentTime);
  1727. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1728. if(isUnitA)
  1729. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1730. else
  1731. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1732. compositeProfile->ChargingSchedule.Duration = durationReq;
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1736. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1738. }
  1739. compositeProfile->ChargingProfileId = 0;
  1740. compositeProfile->StackLevel = 99 ;
  1741. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1742. maxProfile.ChargingProfileId = -1;
  1743. defaultTxProfile.ChargingProfileId = -1;
  1744. txProfile.ChargingProfileId = -1;
  1745. maxProfile.ChargingSchedule.Duration = -1;
  1746. defaultTxProfile.ChargingSchedule.Duration = -1;
  1747. txProfile.ChargingSchedule.Duration = -1;
  1748. system("rm -f /tmp/*.json");
  1749. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1750. /*
  1751. * Search valid charging profile
  1752. */
  1753. //DEBUG_INFO("====================================\n");
  1754. // Search tx profile
  1755. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1756. if((access(profileFileName, F_OK))!=-1)
  1757. {
  1758. fp = fopen(profileFileName, "r");
  1759. while(getline(&line, &len, fp) != -1)
  1760. {
  1761. json_object *obj = NULL;
  1762. obj = json_tokener_parse(line);
  1763. if(is_error(obj))
  1764. {
  1765. DEBUG_ERROR("Parse txProfile from file error.\n");
  1766. }
  1767. else
  1768. {
  1769. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1770. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1771. )
  1772. {
  1773. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1774. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1775. )
  1776. {
  1777. struct tm tmFrom, tmTo;
  1778. struct timeb tbFrom, tbTo;
  1779. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1780. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1781. {
  1782. tmFrom.tm_year -= 1900;
  1783. tmFrom.tm_mon -= 1;
  1784. tbFrom.time = mktime(&tmFrom);
  1785. tmTo.tm_year -= 1900;
  1786. tmTo.tm_mon -= 1;
  1787. tbTo.time = mktime(&tmTo);
  1788. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1789. {
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1795. }
  1796. txProfile.ChargingProfileId = -1;
  1797. txProfile.StackLevel = -1;
  1798. if(txProfile.ChargingProfileId == -1)
  1799. DEBUG_INFO("TxProfile found.\n");
  1800. else
  1801. DEBUG_INFO("TxProfile updated.\n");
  1802. // Required item
  1803. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1804. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1805. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1806. if(isUnitA)
  1807. {
  1808. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1809. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1810. {
  1811. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1813. 3:
  1814. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1815. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1816. }
  1817. }
  1818. else
  1819. {
  1820. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1821. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1822. {
  1823. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1824. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1825. 3:
  1826. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1827. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1828. }
  1829. }
  1830. // Optional item
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidFrom, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.ValidTo, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1848. {
  1849. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1850. }
  1851. else
  1852. {
  1853. sprintf((char*)txProfile.RecurrencyKind, " ");
  1854. }
  1855. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1856. {
  1857. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.TransactionId = -1;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1864. {
  1865. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1866. }
  1867. else
  1868. {
  1869. txProfile.ChargingSchedule.Duration = 86400;
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1872. {
  1873. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1874. }
  1875. else
  1876. {
  1877. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1878. }
  1879. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1880. {
  1881. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1882. }
  1883. else
  1884. {
  1885. txProfile.ChargingSchedule.MinChargingRate = -1;
  1886. }
  1887. }
  1888. }
  1889. }
  1890. else
  1891. {
  1892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1893. {
  1894. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1895. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1897. }
  1898. txProfile.ChargingProfileId = -1;
  1899. txProfile.StackLevel = -1;
  1900. if(txProfile.ChargingProfileId == -1)
  1901. DEBUG_INFO("TxProfile found.\n");
  1902. else
  1903. DEBUG_INFO("TxProfile updated.\n");
  1904. // Required item
  1905. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1906. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1907. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1908. if(isUnitA)
  1909. {
  1910. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1911. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1912. {
  1913. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1914. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1915. 3:
  1916. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1917. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1918. }
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1923. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1924. {
  1925. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1926. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1927. 3:
  1928. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1929. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1930. }
  1931. }
  1932. // Optional item
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.ValidFrom, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1942. {
  1943. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1944. }
  1945. else
  1946. {
  1947. sprintf((char*)txProfile.ValidTo, " ");
  1948. }
  1949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1950. {
  1951. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1952. }
  1953. else
  1954. {
  1955. sprintf((char*)txProfile.RecurrencyKind, " ");
  1956. }
  1957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1958. {
  1959. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1960. }
  1961. else
  1962. {
  1963. txProfile.TransactionId = -1;
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.Duration = 86400;
  1972. }
  1973. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1974. {
  1975. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1976. }
  1977. else
  1978. {
  1979. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1980. }
  1981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1982. {
  1983. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1984. }
  1985. else
  1986. {
  1987. txProfile.ChargingSchedule.MinChargingRate = -1;
  1988. }
  1989. }
  1990. }
  1991. }
  1992. json_object_put(obj);
  1993. }
  1994. fclose(fp);
  1995. /*
  1996. if(txProfile.ChargingProfileId != -1)
  1997. {
  1998. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1999. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2000. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2001. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2002. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2003. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2004. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2005. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2006. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2007. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2008. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2010. {
  2011. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2012. {
  2013. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2014. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2015. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2016. }
  2017. }
  2018. }
  2019. else
  2020. DEBUG_INFO("TxProfile not found.\n");*/
  2021. }
  2022. // Search default tx profile
  2023. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2024. if((access(profileFileName, F_OK))==-1)
  2025. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2026. if((access(profileFileName, F_OK))!=-1)
  2027. {
  2028. fp = fopen(profileFileName, "r");
  2029. while(getline(&line, &len, fp) != -1)
  2030. {
  2031. json_object *obj = NULL;
  2032. obj = json_tokener_parse(line);
  2033. if(is_error(obj))
  2034. {
  2035. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2036. }
  2037. else
  2038. {
  2039. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2040. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2041. )
  2042. {
  2043. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2044. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2045. )
  2046. {
  2047. struct tm tmFrom, tmTo;
  2048. struct timeb tbFrom, tbTo;
  2049. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2050. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2051. {
  2052. tmFrom.tm_year -= 1900;
  2053. tmFrom.tm_mon -= 1;
  2054. tbFrom.time = mktime(&tmFrom);
  2055. tmTo.tm_year -= 1900;
  2056. tmTo.tm_mon -= 1;
  2057. tbTo.time = mktime(&tmTo);
  2058. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2059. {
  2060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2061. {
  2062. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2063. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2065. }
  2066. defaultTxProfile.ChargingProfileId = -1;
  2067. defaultTxProfile.StackLevel = -1;
  2068. if(defaultTxProfile.ChargingProfileId == -1)
  2069. DEBUG_INFO("TxDefaultProfile found.\n");
  2070. else
  2071. DEBUG_INFO("TxDefaultProfile updated.\n");
  2072. // Required item
  2073. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2074. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2075. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2076. if(isUnitA)
  2077. {
  2078. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2079. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2080. {
  2081. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2082. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2083. 3:
  2084. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2085. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2091. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2092. {
  2093. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2094. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2095. 3:
  2096. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2097. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2098. }
  2099. }
  2100. // Optional item
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2110. {
  2111. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2116. }
  2117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2118. {
  2119. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2124. }
  2125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2126. {
  2127. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2128. }
  2129. else
  2130. {
  2131. defaultTxProfile.TransactionId = -1;
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2140. }
  2141. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2142. {
  2143. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2144. }
  2145. else
  2146. {
  2147. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2148. }
  2149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2150. {
  2151. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2152. }
  2153. else
  2154. {
  2155. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2165. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2167. }
  2168. defaultTxProfile.ChargingProfileId = -1;
  2169. defaultTxProfile.StackLevel = -1;
  2170. if(defaultTxProfile.ChargingProfileId == -1)
  2171. DEBUG_INFO("TxDefaultProfile found.\n");
  2172. else
  2173. DEBUG_INFO("TxDefaultProfile updated.\n");
  2174. // Required item
  2175. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2176. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2177. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2178. if(isUnitA)
  2179. {
  2180. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2181. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2182. {
  2183. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2184. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2185. 3:
  2186. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2187. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2193. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2194. {
  2195. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2196. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2197. 3:
  2198. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2200. }
  2201. }
  2202. // Optional item
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2204. {
  2205. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2206. }
  2207. else
  2208. {
  2209. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2210. }
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2220. {
  2221. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2228. {
  2229. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.TransactionId = -1;
  2234. }
  2235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2236. {
  2237. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2238. }
  2239. else
  2240. {
  2241. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2244. {
  2245. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2246. }
  2247. else
  2248. {
  2249. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2252. {
  2253. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2254. }
  2255. else
  2256. {
  2257. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. json_object_put(obj);
  2263. }
  2264. fclose(fp);
  2265. /*
  2266. if(defaultTxProfile.ChargingProfileId != -1)
  2267. {
  2268. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2269. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2270. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2271. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2272. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2273. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2274. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2275. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2276. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2277. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2278. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2279. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2280. {
  2281. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2282. {
  2283. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2284. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2285. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2286. }
  2287. }
  2288. }
  2289. else
  2290. DEBUG_INFO("TxDefaultProfile not found.\n");
  2291. DEBUG_INFO("------------------------------------\n");*/
  2292. }
  2293. // Search max profile
  2294. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2295. if((access(profileFileName, F_OK))!=-1)
  2296. {
  2297. fp = fopen(profileFileName, "r");
  2298. while(getline(&line, &len, fp) != -1)
  2299. {
  2300. json_object *obj = NULL;
  2301. obj = json_tokener_parse(line);
  2302. if(is_error(obj))
  2303. {
  2304. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2305. }
  2306. else
  2307. {
  2308. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2309. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2310. )
  2311. {
  2312. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2313. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2314. )
  2315. {
  2316. struct tm tmFrom, tmTo;
  2317. struct timeb tbFrom, tbTo;
  2318. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2319. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2320. {
  2321. tmFrom.tm_year -= 1900;
  2322. tmFrom.tm_mon -= 1;
  2323. tbFrom.time = mktime(&tmFrom);
  2324. tmTo.tm_year -= 1900;
  2325. tmTo.tm_mon -= 1;
  2326. tbTo.time = mktime(&tmTo);
  2327. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2328. {
  2329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2330. {
  2331. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2334. }
  2335. maxProfile.ChargingProfileId = -1;
  2336. maxProfile.StackLevel = -1;
  2337. if(maxProfile.ChargingProfileId == -1)
  2338. DEBUG_INFO("MaxProfile found.\n");
  2339. else
  2340. DEBUG_INFO("MaxProfile updated.\n");
  2341. // Required item
  2342. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2343. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2344. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2345. if(isUnitA)
  2346. {
  2347. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2348. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2349. {
  2350. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2352. 3:
  2353. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2354. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2355. }
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2360. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2361. {
  2362. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2363. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2364. 3:
  2365. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2366. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2367. }
  2368. }
  2369. // Optional item
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2371. {
  2372. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2373. }
  2374. else
  2375. {
  2376. sprintf((char*)maxProfile.ValidFrom, " ");
  2377. }
  2378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2379. {
  2380. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2381. }
  2382. else
  2383. {
  2384. sprintf((char*)maxProfile.ValidTo, " ");
  2385. }
  2386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2387. {
  2388. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2393. }
  2394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2395. {
  2396. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.TransactionId = -1;
  2401. }
  2402. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2403. {
  2404. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2405. }
  2406. else
  2407. {
  2408. maxProfile.ChargingSchedule.Duration = 86400;
  2409. }
  2410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2411. {
  2412. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2413. }
  2414. else
  2415. {
  2416. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2417. }
  2418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2419. {
  2420. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2421. }
  2422. else
  2423. {
  2424. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. else
  2430. {
  2431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2432. {
  2433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2436. }
  2437. maxProfile.ChargingProfileId = -1;
  2438. maxProfile.StackLevel = -1;
  2439. if(maxProfile.ChargingProfileId == -1)
  2440. DEBUG_INFO("MaxProfile found.\n");
  2441. else
  2442. DEBUG_INFO("MaxProfile updated.\n");
  2443. // Required item
  2444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2447. if(isUnitA)
  2448. {
  2449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2450. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2451. {
  2452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2454. 3:
  2455. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2457. }
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2462. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2466. 3:
  2467. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2469. }
  2470. }
  2471. // Optional item
  2472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2473. {
  2474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2475. }
  2476. else
  2477. {
  2478. sprintf((char*)maxProfile.ValidFrom, " ");
  2479. }
  2480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2481. {
  2482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)maxProfile.ValidTo, " ");
  2487. }
  2488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2489. {
  2490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2495. }
  2496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2497. {
  2498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2499. }
  2500. else
  2501. {
  2502. maxProfile.TransactionId = -1;
  2503. }
  2504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2505. {
  2506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2507. }
  2508. else
  2509. {
  2510. maxProfile.ChargingSchedule.Duration = 86400;
  2511. }
  2512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2513. {
  2514. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2515. }
  2516. else
  2517. {
  2518. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2519. }
  2520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2521. {
  2522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2523. }
  2524. else
  2525. {
  2526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. json_object_put(obj);
  2532. }
  2533. fclose(fp);
  2534. /*
  2535. if(maxProfile.ChargingProfileId !=-1)
  2536. {
  2537. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2538. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2539. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2540. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2541. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2542. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2543. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2544. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2545. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2546. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2547. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2551. {
  2552. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2554. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2555. }
  2556. }
  2557. }
  2558. else
  2559. DEBUG_INFO("MaxProfile not found.\n");
  2560. DEBUG_INFO("------------------------------------\n");*/
  2561. }
  2562. /*
  2563. * Align found profile start schedule & periods
  2564. */
  2565. //DEBUG_INFO("====================================\n");
  2566. /*
  2567. // For local test usage, force modify found profile start schedule info
  2568. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2569. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2570. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2571. */
  2572. if(txProfile.ChargingProfileId != -1)
  2573. {
  2574. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2575. {
  2576. if(txProfile.ChargingSchedule.Duration != -1)
  2577. {
  2578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2579. 0:
  2580. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2581. }
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2587. 0:
  2588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2600. {
  2601. if(txProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2604. 0:
  2605. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2612. 0:
  2613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2614. if(idxPeriod > 0)
  2615. {
  2616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2617. {
  2618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2627. {
  2628. if(txProfile.ChargingSchedule.Duration != -1)
  2629. {
  2630. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2631. 0:
  2632. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2633. }
  2634. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2639. 0:
  2640. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2641. if(idxPeriod > 0)
  2642. {
  2643. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2644. {
  2645. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2646. }
  2647. }
  2648. }
  2649. }
  2650. }
  2651. else
  2652. {
  2653. if(txProfile.ChargingSchedule.Duration != -1)
  2654. {
  2655. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2656. 0:
  2657. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2658. }
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2662. {
  2663. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2664. 0:
  2665. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2666. if(idxPeriod > 0)
  2667. {
  2668. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2669. {
  2670. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. /*
  2678. DEBUG_INFO("txProfile after align.\n");
  2679. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2680. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2681. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2682. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2683. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2684. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2685. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2686. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2687. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2688. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2689. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2690. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2691. {
  2692. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2693. {
  2694. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2695. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2696. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2697. }
  2698. }*/
  2699. }
  2700. if(defaultTxProfile.ChargingProfileId != -1)
  2701. {
  2702. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2703. {
  2704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2707. 0:
  2708. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2709. }
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2718. {
  2719. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2720. }
  2721. if(idxPeriod > 0)
  2722. {
  2723. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2724. {
  2725. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2732. {
  2733. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2734. {
  2735. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2736. 0:
  2737. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2738. }
  2739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2740. {
  2741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2742. {
  2743. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2744. 0:
  2745. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2746. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2747. {
  2748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2749. }
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. else
  2761. {
  2762. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2763. {
  2764. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2765. {
  2766. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2769. }
  2770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2771. {
  2772. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2773. {
  2774. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2777. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2778. {
  2779. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2780. }
  2781. if(idxPeriod > 0)
  2782. {
  2783. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2784. {
  2785. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. else
  2792. {
  2793. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2794. {
  2795. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2796. 0:
  2797. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2798. }
  2799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2800. {
  2801. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2802. {
  2803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2804. 0:
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2807. {
  2808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2809. }
  2810. if(idxPeriod > 0)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. /*
  2822. DEBUG_INFO("defaultTxProfile after align.\n");
  2823. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2824. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2825. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2826. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2827. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2828. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2829. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2830. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2831. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2832. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2833. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2834. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2835. {
  2836. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2837. {
  2838. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2839. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2840. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2841. }
  2842. }
  2843. DEBUG_INFO("------------------------------------\n");*/
  2844. }
  2845. if(maxProfile.ChargingProfileId != -1)
  2846. {
  2847. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2848. {
  2849. if(maxProfile.ChargingSchedule.Duration != -1)
  2850. {
  2851. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2852. 0:
  2853. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2854. }
  2855. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2860. 0:
  2861. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2862. if(idxPeriod > 0)
  2863. {
  2864. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2865. {
  2866. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2867. }
  2868. }
  2869. }
  2870. }
  2871. }
  2872. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2873. {
  2874. if(maxProfile.ChargingSchedule.Duration != -1)
  2875. {
  2876. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2877. 0:
  2878. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2879. }
  2880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2881. {
  2882. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2883. {
  2884. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2885. 0:
  2886. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2887. if(idxPeriod > 0)
  2888. {
  2889. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2890. {
  2891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2892. }
  2893. }
  2894. }
  2895. }
  2896. }
  2897. else
  2898. {
  2899. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2900. {
  2901. if(maxProfile.ChargingSchedule.Duration != -1)
  2902. {
  2903. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2904. 0:
  2905. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2906. }
  2907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2912. 0:
  2913. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2914. if(idxPeriod > 0)
  2915. {
  2916. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2917. {
  2918. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924. else
  2925. {
  2926. if(maxProfile.ChargingSchedule.Duration != -1)
  2927. {
  2928. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2929. 0:
  2930. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2931. }
  2932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2933. {
  2934. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2935. {
  2936. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2937. 0:
  2938. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2939. if(idxPeriod > 0)
  2940. {
  2941. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2942. {
  2943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. /*
  2951. DEBUG_INFO("MaxProfile after align.\n");
  2952. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2953. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2954. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2955. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2956. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2957. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2958. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2959. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2960. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2961. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2962. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2963. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2964. {
  2965. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2966. {
  2967. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2968. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2969. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2970. }
  2971. }
  2972. DEBUG_INFO("------------------------------------\n");*/
  2973. }
  2974. /*
  2975. * Merge to conposite schedule
  2976. */
  2977. //DEBUG_INFO("====================================\n");
  2978. // Find each profile period quantity
  2979. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2980. {
  2981. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2982. limitMax = idx+1;
  2983. }
  2984. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2985. {
  2986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2987. limitDef = idx+1;
  2988. }
  2989. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2990. {
  2991. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2992. limitTx = idx+1;
  2993. }
  2994. // TxProfile found, composite schedule based on it
  2995. if(txProfile.ChargingProfileId != -1)
  2996. {
  2997. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2998. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2999. {
  3000. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3001. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3002. (txProfile.ChargingSchedule.Duration > 0))
  3003. {
  3004. if(maxProfile.ChargingProfileId != -1)
  3005. {
  3006. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3007. {
  3008. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3009. {
  3010. if((maxProfile.ChargingSchedule.Duration > 0))
  3011. {
  3012. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3013. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3014. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3015. }
  3016. else
  3017. {
  3018. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3019. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3020. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3021. }
  3022. }
  3023. if(idxMaxPeriod == (limitMax-1))
  3024. {
  3025. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3026. {
  3027. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3028. {
  3029. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3030. compositePeriodIdx++;
  3031. }
  3032. else
  3033. {
  3034. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3035. }
  3036. }
  3037. }
  3038. }
  3039. }
  3040. else
  3041. {
  3042. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3043. {
  3044. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3045. compositePeriodIdx++;
  3046. }
  3047. else
  3048. {
  3049. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3050. }
  3051. }
  3052. }
  3053. if(idxTxPeriod == (limitTx-1))
  3054. {
  3055. if(defaultTxProfile.ChargingProfileId != -1)
  3056. {
  3057. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3058. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3059. {
  3060. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3061. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3062. (defaultTxProfile.ChargingSchedule.Duration>0))
  3063. {
  3064. if(maxProfile.ChargingProfileId != -1)
  3065. {
  3066. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3067. {
  3068. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3069. {
  3070. if((maxProfile.ChargingSchedule.Duration > 0))
  3071. {
  3072. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3073. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3074. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3075. }
  3076. else
  3077. {
  3078. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3079. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3080. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3081. }
  3082. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3083. {
  3084. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3085. {
  3086. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3087. compositePeriodIdx++;
  3088. }
  3089. else
  3090. {
  3091. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3092. }
  3093. }
  3094. // Delete duplicate period
  3095. if(compositePeriodIdx > 1)
  3096. {
  3097. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3098. {
  3099. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3100. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3101. compositePeriodIdx -= 1;
  3102. }
  3103. }
  3104. }
  3105. else
  3106. {
  3107. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3108. {
  3109. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3110. compositePeriodIdx++;
  3111. }
  3112. else
  3113. {
  3114. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3115. }
  3116. break;
  3117. }
  3118. }
  3119. }
  3120. else
  3121. {
  3122. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3123. {
  3124. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3125. compositePeriodIdx++;
  3126. }
  3127. else
  3128. {
  3129. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3139. else if(defaultTxProfile.ChargingProfileId != -1)
  3140. {
  3141. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3142. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3143. {
  3144. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3145. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3146. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3147. {
  3148. if(maxProfile.ChargingProfileId != -1)
  3149. {
  3150. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3151. {
  3152. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3153. {
  3154. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3155. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3156. if((maxProfile.ChargingSchedule.Duration > 0))
  3157. {
  3158. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3159. }
  3160. else
  3161. {
  3162. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3163. }
  3164. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3165. {
  3166. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3167. {
  3168. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3169. compositePeriodIdx++;
  3170. }
  3171. else
  3172. {
  3173. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3174. }
  3175. }
  3176. // Delete duplicate period
  3177. if(compositePeriodIdx > 1)
  3178. {
  3179. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3180. {
  3181. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3182. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3183. compositePeriodIdx -= 1;
  3184. }
  3185. }
  3186. }
  3187. else
  3188. {
  3189. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3190. {
  3191. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3192. compositePeriodIdx++;
  3193. }
  3194. else
  3195. {
  3196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3197. }
  3198. break;
  3199. }
  3200. }
  3201. }
  3202. else
  3203. {
  3204. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3205. {
  3206. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3207. compositePeriodIdx++;
  3208. }
  3209. else
  3210. {
  3211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3212. }
  3213. }
  3214. }
  3215. }
  3216. }
  3217. // Fill other period by MaxProfile
  3218. if(maxProfile.ChargingProfileId != -1)
  3219. {
  3220. if(compositePeriodIdx==0)
  3221. {
  3222. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3223. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3224. {
  3225. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3226. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3227. (maxProfile.ChargingSchedule.Duration > 0))
  3228. {
  3229. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3230. {
  3231. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3232. compositePeriodIdx++;
  3233. }
  3234. else
  3235. {
  3236. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. }
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. int lastCompositePeriodIdx = compositePeriodIdx;
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3247. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3248. (maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3251. {
  3252. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3253. {
  3254. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3255. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3256. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3257. }
  3258. else
  3259. {
  3260. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3261. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3262. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3263. }
  3264. }
  3265. if(tmpPeriod.Limit != -1)
  3266. {
  3267. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3268. {
  3269. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3270. {
  3271. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. compositePeriodIdx++;
  3273. }
  3274. else
  3275. {
  3276. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3277. }
  3278. }
  3279. // Delete duplicate period
  3280. if(compositePeriodIdx > 1)
  3281. {
  3282. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3283. {
  3284. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3285. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3286. compositePeriodIdx -= 1;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. compositeProfile->ChargingSchedule.Duration = durationReq;
  3295. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3296. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3297. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3298. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3300. {
  3301. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3302. {
  3303. compositeProfile->ChargingProfileId = 1;
  3304. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3305. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3306. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3307. }
  3308. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3309. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3310. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3311. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3312. }
  3313. if(line)
  3314. free(line);
  3315. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3316. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3317. }
  3318. //==========================================
  3319. // Init all share memory
  3320. //==========================================
  3321. int InitShareMemory()
  3322. {
  3323. int result = PASS;
  3324. int MeterSMId;
  3325. //creat ShmSysConfigAndInfo
  3326. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3327. {
  3328. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3329. result = FAIL;
  3330. }
  3331. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3332. {
  3333. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3334. result = FAIL;
  3335. }
  3336. else
  3337. {}
  3338. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3339. {
  3340. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3341. result = FAIL;
  3342. }
  3343. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3344. {
  3345. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3346. result = FAIL;
  3347. }
  3348. else
  3349. {}
  3350. //creat ShmPsuData
  3351. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3352. {
  3353. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3354. result = FAIL;
  3355. }
  3356. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3357. {
  3358. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3359. result = FAIL;
  3360. }
  3361. else
  3362. {}
  3363. //creat ShmOCPP16Data
  3364. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3365. {
  3366. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3367. result = FAIL;
  3368. }
  3369. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3370. {
  3371. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3372. result = FAIL;
  3373. }
  3374. else
  3375. {}
  3376. /****************************** For Initial Settings************************************************/
  3377. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3379. // allocate Configuration memory address
  3380. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3381. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3382. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3383. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3384. //offline MeterValue Interval
  3385. TempMeterValueInterval = 0;
  3386. return result;
  3387. }
  3388. int ProcessShareMemory()
  3389. {
  3390. if(InitShareMemory() == FAIL)
  3391. {
  3392. DEBUG_ERROR("InitShareMemory NG\n");
  3393. if(ShmStatusCodeData!=NULL)
  3394. {
  3395. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3396. }
  3397. sleep(5);
  3398. return FAIL;
  3399. }
  3400. return PASS;
  3401. }
  3402. void CheckSystemValue(void)
  3403. {
  3404. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3405. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3406. char filenmae[100]={0};
  3407. char str[100]={0};
  3408. int tempIndex = 0;
  3409. //===============================
  3410. // send Heartbeat
  3411. //===============================
  3412. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3413. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3414. {
  3415. clientTime.Heartbeat=time((time_t*)NULL);
  3416. if(server_sign == TRUE)
  3417. {
  3418. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3419. }
  3420. else
  3421. {
  3422. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3423. }
  3424. }
  3425. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3426. {
  3427. //parameter for test
  3428. sendHeartbeatRequest(0);
  3429. //==============================================
  3430. // Reset Waiting Time
  3431. //==============================================
  3432. HeartBeatWithNOResponse += 1;
  3433. }
  3434. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3435. {
  3436. //==========================================
  3437. // csu trigger DataTransferReq
  3438. //==========================================
  3439. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3440. {
  3441. sendDataTransferRequest(gun_index);
  3442. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3443. }
  3444. //===============================
  3445. // CSU Trigger Authorize Request
  3446. //===============================
  3447. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3448. {
  3449. sendAuthorizeRequest(0);
  3450. authorizeRetryTimes = authorizeRetryTimes + 1;
  3451. if(authorizeRetryTimes < 3)
  3452. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3453. }
  3454. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3455. {
  3456. authorizeRetryTimes = 0;
  3457. SetOcppConnStatus(FALSE);
  3458. server_sign = FALSE;
  3459. }
  3460. 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))
  3461. {
  3462. sendAuthorizeRequest(0);
  3463. }
  3464. //==============================================
  3465. // Charger start transaction
  3466. //==============================================
  3467. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3468. {
  3469. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3470. sendStartTransactionRequest(gun_index);
  3471. clientTime.StartTransaction = time((time_t*)NULL);
  3472. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3473. storeTempStopTransaction(gun_index);
  3474. }
  3475. //==============================================
  3476. // Charger stop transaction
  3477. //==============================================
  3478. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3479. {
  3480. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3481. sendStopTransactionRequest(gun_index);
  3482. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3483. clientTime.StopTransaction = time((time_t*)NULL);
  3484. }
  3485. //==============================================
  3486. // Charger status report
  3487. //==============================================
  3488. //--- Check Mode Change ---//
  3489. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3491. {
  3492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3493. {
  3494. tempIndex = ((gun_index==2) ? 1: 0);
  3495. }
  3496. else
  3497. {
  3498. tempIndex = gun_index;
  3499. }
  3500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3501. {
  3502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3503. {
  3504. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3505. {
  3506. // Sent unplug message for California pricing logic
  3507. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3508. {
  3509. uint8_t ts[20];
  3510. getNowDatetime(ts);
  3511. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3512. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3513. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3514. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3515. }
  3516. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3517. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3518. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3519. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3520. {
  3521. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3522. if((access(filenmae,F_OK))!=-1)
  3523. {
  3524. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3525. sprintf(str,"rm -f %s",filenmae);
  3526. system(str);
  3527. }
  3528. }
  3529. }
  3530. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3531. #if 1 // for TempStopTransaction
  3532. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3533. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3534. {
  3535. checkTempStopTransaction(gun_index);
  3536. }
  3537. #endif
  3538. }
  3539. }
  3540. }
  3541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3542. {
  3543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3544. {
  3545. tempIndex = ((gun_index==2) ? 1: 0);
  3546. }
  3547. else
  3548. {
  3549. tempIndex = gun_index;
  3550. }
  3551. for (int index = 0; index < CCS_QUANTITY; index++)
  3552. {
  3553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3554. {
  3555. 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]*/ )
  3556. {
  3557. // Sent unplug message for California pricing logic
  3558. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3559. {
  3560. uint8_t ts[20];
  3561. getNowDatetime(ts);
  3562. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3563. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3564. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3565. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3566. }
  3567. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3568. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3569. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3570. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3571. {
  3572. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3573. if((access(filenmae,F_OK))!=-1)
  3574. {
  3575. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3576. sprintf(str,"rm -f %s",filenmae);
  3577. system(str);
  3578. }
  3579. }
  3580. }
  3581. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3582. #if 1 // for TempStopTransaction
  3583. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3584. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3585. {
  3586. checkTempStopTransaction(gun_index);
  3587. }
  3588. #endif
  3589. }
  3590. }
  3591. }
  3592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3593. {
  3594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3595. {
  3596. tempIndex = ((gun_index==2) ? 1: 0);
  3597. }
  3598. else
  3599. {
  3600. tempIndex = gun_index;
  3601. }
  3602. for (int index = 0; index < GB_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3605. {
  3606. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3607. {
  3608. // Sent unplug message for California pricing logic
  3609. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3610. {
  3611. uint8_t ts[20];
  3612. getNowDatetime(ts);
  3613. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3614. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3615. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3616. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3617. }
  3618. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3619. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3620. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3621. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3622. {
  3623. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3624. if((access(filenmae,F_OK))!=-1)
  3625. {
  3626. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3627. sprintf(str,"rm -f %s",filenmae);
  3628. system(str);
  3629. }
  3630. }
  3631. }
  3632. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3633. #if 1 // for TempStopTransaction
  3634. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3635. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3636. {
  3637. checkTempStopTransaction(gun_index);
  3638. }
  3639. #endif
  3640. }
  3641. }
  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. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3649. {
  3650. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3651. {
  3652. // Sent unplug message for California pricing logic
  3653. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3654. {
  3655. uint8_t ts[20];
  3656. getNowDatetime(ts);
  3657. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3658. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3659. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3660. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3661. }
  3662. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3663. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3664. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3665. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3666. {
  3667. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3668. if((access(filenmae,F_OK))!=-1)
  3669. {
  3670. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3671. sprintf(str,"rm -f %s",filenmae);
  3672. system(str);
  3673. }
  3674. }
  3675. }
  3676. 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);
  3677. #if 1 // for TempStopTransaction
  3678. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3679. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3680. {
  3681. checkTempStopTransaction(gun_index);
  3682. }
  3683. #endif
  3684. }
  3685. }
  3686. }
  3687. else
  3688. {
  3689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3690. {
  3691. tempIndex = 2;
  3692. }
  3693. else
  3694. {
  3695. tempIndex = gun_index;
  3696. }
  3697. for (int index = 0; index < AC_QUANTITY; index++)
  3698. {
  3699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3700. {
  3701. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3702. {
  3703. // Sent unplug message for California pricing logic
  3704. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3705. {
  3706. uint8_t ts[20];
  3707. getNowDatetime(ts);
  3708. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3709. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3710. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3711. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3712. }
  3713. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3714. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3715. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3716. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3717. {
  3718. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3719. if((access(filenmae,F_OK))!=-1)
  3720. {
  3721. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3722. sprintf(str,"rm -f %s",filenmae);
  3723. system(str);
  3724. }
  3725. }
  3726. }
  3727. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3728. #if 1 // for TempStopTransaction
  3729. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3730. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3731. {
  3732. checkTempStopTransaction(gun_index);
  3733. }
  3734. #endif
  3735. }
  3736. }// END
  3737. }
  3738. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3739. (
  3740. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3741. )
  3742. )
  3743. {
  3744. if(SystemInitial > 0)
  3745. SystemInitial -= 1;
  3746. sendStatusNotificationRequest(gun_index);
  3747. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3748. }
  3749. //==============================================
  3750. // CSU Trigger Smart Charging Profilw
  3751. //==============================================
  3752. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3753. {
  3754. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3755. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3756. }
  3757. //==============================================
  3758. // Meter report
  3759. //==============================================
  3760. // Trigger MeterValue
  3761. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3762. {
  3763. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3764. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3765. }
  3766. // ClockAlign MeterValue
  3767. 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))
  3768. {
  3769. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3770. {
  3771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3772. {
  3773. tempIndex = ((gun_index==2) ? 1: 0);
  3774. }
  3775. else
  3776. {
  3777. tempIndex = gun_index;
  3778. }
  3779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3780. {
  3781. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3782. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3783. {
  3784. reqClockAlignMeter[gun_index] = 1;
  3785. }
  3786. }// End for CHAdeMO
  3787. }
  3788. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3789. {
  3790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3791. {
  3792. tempIndex = ((gun_index==2) ? 1: 0);
  3793. }
  3794. else
  3795. {
  3796. tempIndex = gun_index;
  3797. }
  3798. for (int index = 0; index < CCS_QUANTITY; index++)
  3799. {
  3800. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3801. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3802. {
  3803. reqClockAlignMeter[gun_index] = 1;
  3804. }
  3805. } // End for CCS
  3806. }
  3807. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3808. {
  3809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3810. {
  3811. tempIndex = ((gun_index==2) ? 1: 0);
  3812. }
  3813. else
  3814. {
  3815. tempIndex = gun_index;
  3816. }
  3817. for (int index = 0; index < GB_QUANTITY; index++)
  3818. {
  3819. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3820. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3821. {
  3822. reqClockAlignMeter[gun_index] = 1;
  3823. }
  3824. }// End for GB
  3825. }
  3826. else if(gunType[gun_index] == GUN_TYPE_DO)
  3827. {
  3828. tempIndex = gun_index;
  3829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3830. {
  3831. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3832. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3833. {
  3834. reqClockAlignMeter[gun_index] = 1;
  3835. }
  3836. }
  3837. }
  3838. else
  3839. {
  3840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3841. {
  3842. tempIndex = 2;
  3843. }
  3844. else
  3845. {
  3846. tempIndex = gun_index;
  3847. }
  3848. for (int index = 0; index < AC_QUANTITY; index++)
  3849. {
  3850. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3851. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3852. {
  3853. reqClockAlignMeter[gun_index] = 1;
  3854. }
  3855. }//End for AC
  3856. }
  3857. if(reqClockAlignMeter[gun_index] == 1)
  3858. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3859. }
  3860. // Sample period MeterValue
  3861. 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))))
  3862. {
  3863. //check Transaction active
  3864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3865. {
  3866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3867. {
  3868. tempIndex = ((gun_index==2) ? 1: 0);
  3869. }
  3870. else
  3871. {
  3872. tempIndex = gun_index;
  3873. }
  3874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3875. {
  3876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3878. {
  3879. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3880. {
  3881. reqSampleMeter[gun_index] = 1;
  3882. }
  3883. }
  3884. }// End for CHAdeMO
  3885. }
  3886. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3887. {
  3888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3889. {
  3890. tempIndex = ((gun_index==2) ? 1: 0);
  3891. }
  3892. else
  3893. {
  3894. tempIndex = gun_index;
  3895. }
  3896. for (int index = 0; index < CCS_QUANTITY; index++)
  3897. {
  3898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3899. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3900. {
  3901. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3902. {
  3903. reqSampleMeter[gun_index] = 1;
  3904. }
  3905. }
  3906. } // End for CCS
  3907. }
  3908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3909. {
  3910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3911. {
  3912. tempIndex = ((gun_index==2) ? 1: 0);
  3913. }
  3914. else
  3915. {
  3916. tempIndex = gun_index;
  3917. }
  3918. for (int index = 0; index < GB_QUANTITY; index++)
  3919. {
  3920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3921. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3922. {
  3923. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3924. {
  3925. reqSampleMeter[gun_index] = 1;
  3926. }
  3927. }
  3928. }// End for GB
  3929. }
  3930. else if(gunType[gun_index] == GUN_TYPE_DO)
  3931. {
  3932. tempIndex = gun_index;
  3933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3934. {
  3935. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3936. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3937. {
  3938. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3939. {
  3940. reqSampleMeter[gun_index] = 1;
  3941. }
  3942. }
  3943. }
  3944. }
  3945. else
  3946. {
  3947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3948. {
  3949. tempIndex = 2;
  3950. }
  3951. else
  3952. {
  3953. tempIndex = gun_index;
  3954. }
  3955. for (int index = 0; index < AC_QUANTITY; index++)
  3956. {
  3957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3958. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3959. {
  3960. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3961. {
  3962. reqSampleMeter[gun_index] = 1;
  3963. }
  3964. }
  3965. }//End for AC
  3966. }
  3967. if(reqSampleMeter[gun_index] == 1)
  3968. {
  3969. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3970. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3971. storeTempStopTransaction(gun_index);
  3972. }
  3973. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3974. }
  3975. //==============================================
  3976. // Check Connector reserved
  3977. //==============================================
  3978. //===============================
  3979. // Check if Reserve is expired
  3980. //===============================
  3981. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  3982. {
  3983. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  3984. {
  3985. DEBUG_INFO("reserve expired.\n");
  3986. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3987. }
  3988. }//END OF Check if Reserve is expired
  3989. //==========================================
  3990. // csu trigger FirmwareStatusNotificationReq
  3991. //==========================================
  3992. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3993. {
  3994. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3995. }
  3996. //==========================================
  3997. // csu trigger DiagnosticsStatusNotificationReq
  3998. //==========================================
  3999. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4000. {
  4001. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4002. }
  4003. //==========================================
  4004. // csu trigger CancelReservationConf
  4005. //==========================================
  4006. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4007. {
  4008. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4009. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4010. }
  4011. //==========================================
  4012. // csu trigger ChangeAvailabilityConf
  4013. //==========================================
  4014. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4015. {
  4016. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4017. }
  4018. //==========================================
  4019. // csu trigger UnlockConnectorConf
  4020. //==========================================
  4021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4022. {
  4023. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4024. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4025. }
  4026. //==========================================
  4027. // csu trigger ReserveNowConf
  4028. //==========================================
  4029. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4030. {
  4031. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4032. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4033. }
  4034. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4035. {
  4036. sendSignCertificateRequest();
  4037. }
  4038. }
  4039. }
  4040. //==========================================
  4041. // send request routine
  4042. //==========================================
  4043. int sendAuthorizeRequest(int gun_index)
  4044. {
  4045. mtrace();
  4046. int result = FAIL;
  4047. char message[100]={0};
  4048. char guid[37];
  4049. char tempdata[65]={0};
  4050. DEBUG_INFO("sendAuthorizeRequest...\n");
  4051. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4052. //Local Authorize
  4053. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4054. {
  4055. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4056. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4057. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4058. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4059. result = PASS;
  4060. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4061. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4062. authorizeRetryTimes = 0;
  4063. return result;
  4064. }
  4065. 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))||
  4066. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4067. {
  4068. // Query from cache
  4069. DEBUG_INFO("Authorize from cache.\n");
  4070. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4071. // Query from list
  4072. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4073. {
  4074. DEBUG_INFO("Authorize from list.\n");
  4075. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4076. }
  4077. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4078. {
  4079. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4080. {
  4081. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4082. }
  4083. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4084. {
  4085. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4086. }
  4087. if(!GetOcppConnStatus())
  4088. {
  4089. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4090. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4092. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4093. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4094. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4095. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4096. authorizeRetryTimes = 0;
  4097. return result;
  4098. }
  4099. }
  4100. else
  4101. {
  4102. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4103. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4104. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4105. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4106. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4107. else
  4108. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4109. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4110. result = PASS;
  4111. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4112. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4113. authorizeRetryTimes = 0;
  4114. return result;
  4115. }
  4116. }
  4117. //initialize struct Authorize
  4118. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4119. //get data from shared memory
  4120. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4121. random_uuid(guid);
  4122. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4123. LWS_Send(message);
  4124. sprintf(tempdata, "Authorize,%d", gun_index);
  4125. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4126. {
  4127. result = PASS;
  4128. DEBUG_INFO("Authorize mapItem pass\n");
  4129. }
  4130. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4131. return result;
  4132. }
  4133. int sendBootNotificationRequest(void)
  4134. {
  4135. mtrace();
  4136. int result = FAIL;
  4137. char message[500]={0}, payload[700]={0};
  4138. char guid[37]={0};
  4139. char tempdata[65]={0};
  4140. // Fill BootNotification fields
  4141. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4142. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4143. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4144. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4145. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4146. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4147. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4148. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4149. ShmOCPP16Data->ChargeBoxId
  4150. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4151. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4152. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4153. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4154. ,ShmOCPP16Data->BootNotification.CpIccid
  4155. ,ShmOCPP16Data->BootNotification.CpImsi);
  4156. random_uuid(guid);
  4157. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4158. LWS_Send(message);
  4159. sprintf(tempdata, "BootNotification,0");
  4160. 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*/)
  4161. {
  4162. result = PASS;
  4163. }
  4164. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4165. strcpy(queuedata,message);
  4166. return result;
  4167. }
  4168. int sendDataTransferRequest(int gun_index)
  4169. {
  4170. mtrace();
  4171. char message[1000]={0};
  4172. char guid[37]={0};
  4173. char tempdata[65]={0};
  4174. int result = FAIL;
  4175. random_uuid(guid);
  4176. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4177. MESSAGE_TYPE_CALL,
  4178. guid,
  4179. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4180. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4181. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4182. LWS_Send(message);
  4183. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4184. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4185. {
  4186. result = PASS;
  4187. DEBUG_INFO("DataTransfer mapItem pass\n");
  4188. }
  4189. return result;
  4190. }
  4191. int sendDiagnosticsStatusNotificationRequest(char *status)
  4192. {
  4193. mtrace();
  4194. int result = FAIL;
  4195. char message[110]={0};
  4196. char guid[37]={0};
  4197. char tempdata[65]={0};
  4198. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4199. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4200. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4201. random_uuid(guid);
  4202. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4203. LWS_SendNow(message);
  4204. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4206. {
  4207. result = PASS;
  4208. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4209. }
  4210. //#ifdef SystemLogMessage
  4211. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4212. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4213. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4214. //#endif
  4215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4216. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4217. //record status
  4218. if(strcmp(status,"Idle")==0)
  4219. {
  4220. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4221. }
  4222. else if(strcmp(status,"Uploaded")==0)
  4223. {
  4224. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4225. }
  4226. else if(strcmp(status,"UploadFailed")==0)
  4227. {
  4228. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4229. }
  4230. else if(strcmp(status,"Uploading")==0)
  4231. {
  4232. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4233. }
  4234. return result;
  4235. }
  4236. int sendFirmwareStatusNotificationRequest(char *status)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. char message[110]={0};
  4241. char guid[37]={0};
  4242. char tempdata[65]={0};
  4243. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4244. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4245. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4246. random_uuid(guid);
  4247. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4248. LWS_SendNow(message);
  4249. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4250. 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*/)
  4251. {
  4252. result = PASS;
  4253. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4254. }
  4255. //#ifdef SystemLogMessage
  4256. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4257. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4258. //#endif
  4259. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4260. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4261. //record status
  4262. if(strcmp(status,"Downloaded")==0)
  4263. {
  4264. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4265. }
  4266. else if(strcmp(status,"DownloadFailed")==0)
  4267. {
  4268. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4269. }
  4270. else if(strcmp(status,"Downloading")==0)
  4271. {
  4272. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4273. }
  4274. else if(strcmp(status,"Idle")==0)
  4275. {
  4276. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4277. }
  4278. else if(strcmp(status,"InstallationFailed")==0)
  4279. {
  4280. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4281. }
  4282. else if(strcmp(status,"Installing")==0)
  4283. {
  4284. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4285. }
  4286. else if(strcmp(status,"Installed")==0)
  4287. {
  4288. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4289. }
  4290. return result;
  4291. }
  4292. int sendHeartbeatRequest(int gun_index)
  4293. {
  4294. mtrace();
  4295. int result = FAIL;
  4296. char message[80]={0};
  4297. char guid[37]={0};
  4298. char tempdata[65]={0};
  4299. random_uuid(guid);
  4300. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4301. , MESSAGE_TYPE_CALL
  4302. , guid );
  4303. LWS_Send(message);
  4304. sprintf(tempdata, "Heartbeat,%d", 0);
  4305. 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*/)
  4306. {
  4307. result = PASS;
  4308. }
  4309. return result;
  4310. }
  4311. int sendStartTransactionRequest(int gun_index)
  4312. {
  4313. mtrace();
  4314. int result = FAIL;
  4315. char message[250]={0};
  4316. char guid[37]={0};
  4317. struct timeval tmnow;
  4318. struct tm *tm;
  4319. char buf[28];//, usec_buf[6];
  4320. char tempdata[65]={0};
  4321. int tempIndex = 0;
  4322. DEBUG_INFO("sendStartTransactionRequest...\n");
  4323. gettimeofday(&tmnow, NULL);
  4324. time_t t;
  4325. t = time(NULL);
  4326. /*UTC time and date*/
  4327. tm = gmtime(&t);
  4328. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4329. #if 0 // remove temporally
  4330. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4331. strcat(buf,".");
  4332. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4333. strcat(buf,usec_buf);
  4334. #endif
  4335. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4336. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4337. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4338. // clear StartTransaction Response
  4339. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4340. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4341. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4342. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4343. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  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. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4360. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4361. }
  4362. }
  4363. }
  4364. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4365. {
  4366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4367. {
  4368. tempIndex = ((gun_index==2) ? 1: 0);
  4369. }
  4370. else
  4371. {
  4372. tempIndex = gun_index;
  4373. }
  4374. for (int index = 0; index < CCS_QUANTITY; index++)
  4375. {
  4376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4377. {
  4378. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4379. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4380. }
  4381. }
  4382. }
  4383. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4384. {
  4385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4386. {
  4387. tempIndex = ((gun_index==2) ? 1: 0);
  4388. }
  4389. else
  4390. {
  4391. tempIndex = gun_index;
  4392. }
  4393. for (int index = 0; index < GB_QUANTITY; index++)
  4394. {
  4395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4396. {
  4397. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4398. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4399. }
  4400. }
  4401. }
  4402. else if(gunType[gun_index] == GUN_TYPE_DO)
  4403. {
  4404. tempIndex = gun_index;
  4405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4408. {
  4409. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4410. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4411. }
  4412. }
  4413. }
  4414. else
  4415. {
  4416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4417. {
  4418. tempIndex = 2;
  4419. }
  4420. else
  4421. {
  4422. tempIndex = gun_index;
  4423. }
  4424. for (int index = 0; index < AC_QUANTITY; index++)
  4425. {
  4426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4427. {
  4428. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4429. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4430. }
  4431. }
  4432. }
  4433. random_uuid(guid);
  4434. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4435. {
  4436. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4437. , gun_index +1
  4438. , MESSAGE_TYPE_CALL
  4439. , guid
  4440. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4441. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4442. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4443. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4444. }
  4445. else
  4446. {
  4447. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4448. , gun_index +1
  4449. , MESSAGE_TYPE_CALL
  4450. , guid
  4451. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4452. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4453. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4454. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4455. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4456. }
  4457. #if 1
  4458. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4459. 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*/)
  4460. {
  4461. result = PASS;
  4462. }
  4463. #endif
  4464. strcpy(queuedata, message);
  4465. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4466. OCPP_insert_transaction_msg(YES, queuedata);
  4467. return result;
  4468. }
  4469. int sendStatusNotificationRequest(int gun_index)
  4470. {
  4471. mtrace();
  4472. int result = FAIL;
  4473. char message[600]={0};
  4474. char guid[37];
  4475. int currentStatus = 0;
  4476. struct timeval tmnow;
  4477. struct tm *tm;
  4478. char buf[28];//, usec_buf[6];
  4479. char tempdata[65]={0};
  4480. int tempIndex = 0;
  4481. uint8_t isStateChanged = TRUE;
  4482. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4483. gettimeofday(&tmnow, NULL);
  4484. time_t t;
  4485. t = time(NULL);
  4486. /*UTC time and date*/
  4487. tm = gmtime(&t);
  4488. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4489. #if 0 // remove temporally
  4490. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4491. strcat(buf,".");
  4492. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4493. strcat(buf,usec_buf);
  4494. #endif
  4495. //printf("%s",buf);
  4496. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4497. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4498. // it's option
  4499. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4500. /*
  4501. enum _SYSTEM_STATUS
  4502. {
  4503. S_BOOTING = 0,
  4504. S_IDLE, = 1
  4505. S_AUTHORIZING, =2
  4506. S_REASSIGN_CHECK, =3
  4507. S_REASSIGN, =4
  4508. S_PRECHARGE, =5
  4509. S_PREPARING_FOR_EV, =6
  4510. S_PREPARING_FOR_EVSE, =7
  4511. S_CHARGING, =8
  4512. S_TERMINATING, =9
  4513. S_COMPLETE, =10
  4514. S_ALARM, =11
  4515. S_FAULT =12
  4516. }
  4517. */
  4518. //check Transaction active
  4519. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4520. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4523. {
  4524. tempIndex = ((gun_index==2) ? 1: 0);
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4531. {
  4532. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4533. {
  4534. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4535. {
  4536. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4537. {
  4538. currentStatus = Preparing; //OCPP Status: Preparing
  4539. }
  4540. else
  4541. {
  4542. currentStatus = Available; //OCPP Status: Available
  4543. }
  4544. }
  4545. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4546. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4547. ) //S_PRECHARGE
  4548. {
  4549. currentStatus = Preparing; //OCPP Status: Preparing
  4550. }
  4551. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4552. {
  4553. currentStatus = Charging; //OCPP Status: Charging
  4554. }
  4555. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4556. {
  4557. currentStatus = Finishing; //OCPP Status: Finishing
  4558. }
  4559. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4560. {
  4561. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4562. }
  4563. 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
  4564. {
  4565. currentStatus = Unavailable; //OCPP Status: Unavailable
  4566. }
  4567. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4568. {
  4569. currentStatus = Faulted; //OCPP Status: Faulted
  4570. }
  4571. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4572. {
  4573. currentStatus = Reserved; //OCPP Status: Reserved
  4574. }
  4575. } //end of the same index
  4576. }//end of for CHAdeMO_QUANTITY
  4577. }
  4578. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4579. {
  4580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4581. {
  4582. tempIndex = ((gun_index==2) ? 1: 0);
  4583. }
  4584. else
  4585. {
  4586. tempIndex = gun_index;
  4587. }
  4588. for (int index = 0; index < CCS_QUANTITY; index++)
  4589. {
  4590. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4591. {
  4592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4593. {
  4594. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4595. {
  4596. currentStatus = Preparing; //OCPP Status: Preparing
  4597. }
  4598. else
  4599. {
  4600. currentStatus = Available; //OCPP Status: Available
  4601. }
  4602. }
  4603. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4604. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4605. ) //S_PRECHARGE
  4606. {
  4607. currentStatus = Preparing; //OCPP Status: Preparing
  4608. }
  4609. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4610. {
  4611. currentStatus = Charging; //OCPP Status: Charging
  4612. }
  4613. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4614. {
  4615. currentStatus = Finishing; //OCPP Status: Finishing
  4616. }
  4617. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4618. {
  4619. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4620. }
  4621. 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
  4622. {
  4623. currentStatus = Unavailable; //OCPP Status : Unavailable
  4624. }
  4625. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4626. {
  4627. currentStatus = Faulted; //OCPP Status: Faulted
  4628. }
  4629. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4630. {
  4631. currentStatus = Reserved; //OCPP Status: Reserved
  4632. }
  4633. } //end of the same index
  4634. } // end of for CCS_QUANTITY
  4635. }
  4636. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4637. {
  4638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4639. {
  4640. tempIndex = ((gun_index==2) ? 1: 0);
  4641. }
  4642. else
  4643. {
  4644. tempIndex = gun_index;
  4645. }
  4646. for (int index = 0; index < GB_QUANTITY; index++)
  4647. {
  4648. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4649. {
  4650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4651. {
  4652. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4653. {
  4654. currentStatus = Preparing; //OCPP Status: Preparing
  4655. }
  4656. else
  4657. {
  4658. currentStatus = Available; //OCPP Status: Available
  4659. }
  4660. }
  4661. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4662. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4663. ) //S_PRECHARGE
  4664. {
  4665. currentStatus = Preparing; //OCPP Status: Preparing
  4666. }
  4667. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4668. {
  4669. currentStatus = Charging; //OCPP Status: Charging
  4670. }
  4671. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4672. {
  4673. currentStatus = Finishing; //OCPP Status: Finishing
  4674. }
  4675. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4676. {
  4677. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4678. }
  4679. 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
  4680. {
  4681. currentStatus = Unavailable; //OCPP Status: Unavailable
  4682. }
  4683. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4684. {
  4685. currentStatus = Faulted; //OCPP Status: Faulted
  4686. }
  4687. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4688. {
  4689. currentStatus = Reserved; //OCPP Status: Reserved
  4690. }
  4691. } //end of the same index
  4692. } // end of for GB_QUANTITY
  4693. }
  4694. else if(gunType[gun_index] == GUN_TYPE_DO)
  4695. {
  4696. tempIndex = gun_index;
  4697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4698. {
  4699. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4700. {
  4701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4702. {
  4703. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4704. {
  4705. currentStatus = Preparing; //OCPP Status: Preparing
  4706. }
  4707. else
  4708. {
  4709. currentStatus = Available; //OCPP Status: Available
  4710. }
  4711. }
  4712. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4713. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4714. ) //S_PRECHARGE
  4715. {
  4716. currentStatus = Preparing; //OCPP Status: Preparing
  4717. }
  4718. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4719. {
  4720. currentStatus = Charging; //OCPP Status: Charging
  4721. }
  4722. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4723. {
  4724. currentStatus = Finishing; //OCPP Status: Finishing
  4725. }
  4726. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4727. {
  4728. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4729. }
  4730. 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
  4731. {
  4732. currentStatus = Unavailable; //OCPP Status: Unavailable
  4733. }
  4734. 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
  4735. {
  4736. currentStatus = Faulted; //OCPP Status: Faulted
  4737. }
  4738. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4739. {
  4740. currentStatus = Reserved; //OCPP Status: Reserved
  4741. }
  4742. } //end of the same index
  4743. }
  4744. }
  4745. else
  4746. {
  4747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4748. {
  4749. tempIndex = 2;
  4750. }
  4751. else
  4752. {
  4753. tempIndex = gun_index;
  4754. }
  4755. for (int index = 0; index < AC_QUANTITY; index++)
  4756. {
  4757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4758. {
  4759. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4760. {
  4761. 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))
  4762. {
  4763. currentStatus = Preparing; //OCPP Status: Preparing
  4764. }
  4765. else
  4766. {
  4767. currentStatus = Available; //OCPP Status: Available
  4768. }
  4769. }
  4770. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4771. {
  4772. currentStatus = Preparing; //OCPP Status: Preparing
  4773. }
  4774. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4775. {
  4776. currentStatus = Charging; //OCPP Status: Charging
  4777. }
  4778. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4779. {
  4780. currentStatus = Finishing; //OCPP Status: Finishing
  4781. }
  4782. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4783. {
  4784. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4785. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4786. else
  4787. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4788. }
  4789. 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
  4790. {
  4791. currentStatus = Unavailable; //OCPP Status: Unavailable
  4792. }
  4793. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4794. {
  4795. currentStatus = Faulted; //OCPP Status: Faulted
  4796. }
  4797. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4798. {
  4799. currentStatus = Reserved; //OCPP Status: Reserved
  4800. }
  4801. }//end of the same index
  4802. }//end of for AC_QUANTITY
  4803. }
  4804. //it's option
  4805. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4806. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4807. {
  4808. isStateChanged = FALSE;
  4809. }
  4810. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4811. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4812. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4813. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4814. random_uuid(guid);
  4815. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4816. , MESSAGE_TYPE_CALL
  4817. , guid
  4818. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4819. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4820. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4821. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4822. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4823. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4824. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4825. if((server_sign == TRUE) && isStateChanged)
  4826. {
  4827. LWS_Send(message);
  4828. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4829. 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*/)
  4830. {
  4831. //DEBUG_ERROR("statusNotification mapitem pass");
  4832. result = PASS;
  4833. }
  4834. }
  4835. else
  4836. {
  4837. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4838. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4839. result = PASS;
  4840. }
  4841. return result;
  4842. }
  4843. int sendStopTransactionRequest(int gun_index)
  4844. {
  4845. mtrace();
  4846. int result = FAIL;
  4847. //char message[1500]={0};
  4848. char guid[37]={0};
  4849. char tempdata[65]={0};
  4850. int tempIndex = 0;
  4851. char TempStopTransaction[256];
  4852. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4853. //int idx_sample=0;
  4854. DEBUG_INFO("sendStopTransactionRequest \n");
  4855. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4856. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4857. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4858. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4859. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4860. {
  4861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4862. {
  4863. tempIndex = ((gun_index==2) ? 1: 0);
  4864. }
  4865. else
  4866. {
  4867. tempIndex = gun_index;
  4868. }
  4869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4870. {
  4871. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4872. {
  4873. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4874. }
  4875. }// END OF CHAdeMO_QUANTITY
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < CCS_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4890. {
  4891. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4892. }
  4893. }// END OF CCS_QUANTITY
  4894. }
  4895. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4896. {
  4897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4898. {
  4899. tempIndex = ((gun_index==2) ? 1: 0);
  4900. }
  4901. else
  4902. {
  4903. tempIndex = gun_index;
  4904. }
  4905. for (int index = 0; index < GB_QUANTITY; index++)
  4906. {
  4907. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4908. {
  4909. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4910. }
  4911. }// END OF GB_QUANTITY
  4912. }
  4913. else if(gunType[gun_index] == GUN_TYPE_DO)
  4914. {
  4915. tempIndex = gun_index;
  4916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4917. {
  4918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4919. {
  4920. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4921. }
  4922. }// END OF GB_QUANTITY
  4923. }
  4924. else
  4925. {
  4926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4927. {
  4928. tempIndex = 2;
  4929. }
  4930. else
  4931. {
  4932. tempIndex = gun_index;
  4933. }
  4934. for (int index = 0; index < AC_QUANTITY; index++)
  4935. {
  4936. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4937. {
  4938. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4939. }
  4940. }// END OF AC_QUANTITY
  4941. }
  4942. //====================================== Stop Transaction Time =====================================================
  4943. struct timeval tmnow;
  4944. struct tm *tm;
  4945. char buf[28];//, usec_buf[6];
  4946. gettimeofday(&tmnow, NULL);
  4947. time_t t;
  4948. t = time(NULL);
  4949. /*UTC time and date*/
  4950. tm = gmtime(&t);
  4951. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4953. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4954. random_uuid(guid);
  4955. /***********************************transactionData******************************************************/
  4956. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4958. //=================================
  4959. // Transaction_Begin
  4960. //=================================
  4961. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4962. {
  4963. //============================================ Energy.Active.Import.Interval ================================
  4964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4967. 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*/]);
  4968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4969. 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))
  4970. {
  4971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4972. }
  4973. else
  4974. {
  4975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4976. }
  4977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4979. }
  4980. //=================================
  4981. // Transaction_End
  4982. //=================================
  4983. // ================================= Current.Import L1 ===============================================
  4984. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4985. {
  4986. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4987. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4988. {
  4989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4990. {
  4991. tempIndex = ((gun_index==2) ? 1: 0);
  4992. }
  4993. else
  4994. {
  4995. tempIndex = gun_index;
  4996. }
  4997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4998. {
  4999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5000. {
  5001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5002. }
  5003. }// End of for CHAdeMO_QUANTITY
  5004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5005. }
  5006. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5007. {
  5008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5009. {
  5010. tempIndex = ((gun_index==2) ? 1: 0);
  5011. }
  5012. else
  5013. {
  5014. tempIndex = gun_index;
  5015. }
  5016. for (int index = 0; index < CCS_QUANTITY; index++)
  5017. {
  5018. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5019. {
  5020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5021. }
  5022. }// End of for CCS_QUANTITY
  5023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5024. }
  5025. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < GB_QUANTITY; index++)
  5036. {
  5037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5038. {
  5039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5040. }
  5041. }// End of for GB_QUANTITY
  5042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5043. }
  5044. else if(gunType[gun_index] == GUN_TYPE_DO)
  5045. {
  5046. tempIndex = gun_index;
  5047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5048. {
  5049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5050. {
  5051. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5052. }
  5053. }
  5054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5055. }
  5056. else
  5057. {
  5058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5059. {
  5060. tempIndex = 2;
  5061. }
  5062. else
  5063. {
  5064. tempIndex = gun_index;
  5065. }
  5066. for (int index = 0; index < AC_QUANTITY; index++)
  5067. {
  5068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5069. {
  5070. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5071. }
  5072. }// End of for AC_QUANTITY
  5073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5074. }
  5075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5080. }
  5081. // ================================= Energy.Active.Import.Interval ==============================================
  5082. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5083. {
  5084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5085. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5086. {
  5087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5088. {
  5089. tempIndex = ((gun_index==2) ? 1: 0);
  5090. }
  5091. else
  5092. {
  5093. tempIndex = gun_index;
  5094. }
  5095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5098. {
  5099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5100. }
  5101. }// END OF CHAdeMO_QUANTITY
  5102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5103. }
  5104. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5105. {
  5106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5107. {
  5108. tempIndex = ((gun_index==2) ? 1: 0);
  5109. }
  5110. else
  5111. {
  5112. tempIndex = gun_index;
  5113. }
  5114. for (int index = 0; index < CCS_QUANTITY; index++)
  5115. {
  5116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5117. {
  5118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5119. }
  5120. }// END OF CCS_QUANTITY
  5121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5122. }
  5123. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5124. {
  5125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5126. {
  5127. tempIndex = ((gun_index==2) ? 1: 0);
  5128. }
  5129. else
  5130. {
  5131. tempIndex = gun_index;
  5132. }
  5133. for (int index = 0; index < GB_QUANTITY; index++)
  5134. {
  5135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5136. {
  5137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5138. }
  5139. }// END OF GB_QUANTITY
  5140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5141. }
  5142. else if(gunType[gun_index] == GUN_TYPE_DO)
  5143. {
  5144. tempIndex = gun_index;
  5145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5146. {
  5147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5148. {
  5149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5150. }
  5151. }
  5152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5153. }
  5154. else
  5155. {
  5156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5157. {
  5158. tempIndex = 2;
  5159. }
  5160. else
  5161. {
  5162. tempIndex = gun_index;
  5163. }
  5164. for (int index = 0; index < AC_QUANTITY; index++)
  5165. {
  5166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5167. {
  5168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5169. }
  5170. }// END OF AC_QUANTITY
  5171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5172. }
  5173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5178. }
  5179. //=================================== Power.Active.Import ==================================================
  5180. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5181. {
  5182. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5183. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5198. }
  5199. } // End for CHAdeMO_QUANTITY
  5200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5201. }
  5202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5205. {
  5206. tempIndex = ((gun_index==2) ? 1: 0);
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < CCS_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5215. {
  5216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5217. }
  5218. } // END for CCS_QUANTITY
  5219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5220. }
  5221. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5222. {
  5223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5224. {
  5225. tempIndex = ((gun_index==2) ? 1: 0);
  5226. }
  5227. else
  5228. {
  5229. tempIndex = gun_index;
  5230. }
  5231. for (int index = 0; index < GB_QUANTITY; index++)
  5232. {
  5233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5234. {
  5235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5236. }
  5237. }// END for GB_QUANTITY
  5238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5239. }
  5240. else if(gunType[gun_index] == GUN_TYPE_DO)
  5241. {
  5242. tempIndex = gun_index;
  5243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5248. }
  5249. }
  5250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5251. }
  5252. else
  5253. {
  5254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5255. {
  5256. tempIndex = 2;
  5257. }
  5258. else
  5259. {
  5260. tempIndex = gun_index;
  5261. }
  5262. for (int index = 0; index < AC_QUANTITY; index++)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5265. {
  5266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5267. }
  5268. } // END for AC_QUANTITY
  5269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5270. }
  5271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5276. }
  5277. //============================ Voltage L1 ====================================
  5278. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5279. {
  5280. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5281. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5282. {
  5283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5284. {
  5285. tempIndex = ((gun_index==2) ? 1: 0);
  5286. }
  5287. else
  5288. {
  5289. tempIndex = gun_index;
  5290. }
  5291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5294. {
  5295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5296. }
  5297. } // END OF FOR CHAdeMO_QUANTITY
  5298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5299. }
  5300. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5301. {
  5302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5303. {
  5304. tempIndex = ((gun_index==2) ? 1: 0);
  5305. }
  5306. else
  5307. {
  5308. tempIndex = gun_index;
  5309. }
  5310. for (int index = 0; index < CCS_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5313. {
  5314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5315. }
  5316. } // END OF FOR CCS_QUANTITY
  5317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5318. }
  5319. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5320. {
  5321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5322. {
  5323. tempIndex = ((gun_index==2) ? 1: 0);
  5324. }
  5325. else
  5326. {
  5327. tempIndex = gun_index;
  5328. }
  5329. for (int index = 0; index < GB_QUANTITY; index++)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5332. {
  5333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5334. }
  5335. } // END OF FOR GB_QUANTITY
  5336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5337. }
  5338. else if(gunType[gun_index] == GUN_TYPE_DO)
  5339. {
  5340. tempIndex = gun_index;
  5341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5342. {
  5343. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5344. {
  5345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5346. }
  5347. }
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5349. }
  5350. else
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5353. {
  5354. tempIndex = 2;
  5355. }
  5356. else
  5357. {
  5358. tempIndex = gun_index;
  5359. }
  5360. for (int index = 0; index < AC_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5363. {
  5364. 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
  5365. }
  5366. } // END OF FOR AC_QUANTITY
  5367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5368. }
  5369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5374. }
  5375. //====================== End SoC ================================
  5376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5377. {
  5378. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5379. 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))
  5380. {
  5381. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5382. {
  5383. tempIndex = ((gun_index==2) ? 1: 0);
  5384. }
  5385. else
  5386. {
  5387. tempIndex = gun_index;
  5388. }
  5389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5390. {
  5391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5392. {
  5393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5394. {
  5395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5396. }
  5397. }
  5398. }
  5399. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5400. {
  5401. for (int index = 0; index < CCS_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5404. {
  5405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5406. }
  5407. }
  5408. }
  5409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5410. {
  5411. for (int index = 0; index < GB_QUANTITY; index++)
  5412. {
  5413. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5414. {
  5415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5416. }
  5417. }
  5418. }
  5419. else if(gunType[gun_index] == GUN_TYPE_DO)
  5420. {
  5421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5426. }
  5427. }
  5428. }
  5429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5435. } // END FOR DC CASE
  5436. }
  5437. // ================================= Current.Import L2 ===============================================
  5438. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5439. {
  5440. // AC 3 phse L2 current
  5441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5444. {
  5445. tempIndex = 2;
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < AC_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5454. {
  5455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5456. }
  5457. }// End of for AC_QUANTITY
  5458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5465. }
  5466. // ================================= Current.Import L3 ===============================================
  5467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5468. {
  5469. // AC 3 phse L3 current
  5470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5473. {
  5474. tempIndex = 2;
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < AC_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5483. {
  5484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5485. }
  5486. }// End of for AC_QUANTITY
  5487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5488. }
  5489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5494. }
  5495. //============================ Voltage L2 ====================================
  5496. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5497. {
  5498. // AC 3 phse L2 voltage
  5499. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5500. {
  5501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5502. {
  5503. tempIndex = 2;
  5504. }
  5505. else
  5506. {
  5507. tempIndex = gun_index;
  5508. }
  5509. for (int index = 0; index < AC_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5512. {
  5513. 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
  5514. }
  5515. } // END OF FOR AC_QUANTITY
  5516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5517. }
  5518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5523. }
  5524. //============================ Voltage L3 ====================================
  5525. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5526. {
  5527. // AC 3 phse L3 voltage
  5528. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5529. {
  5530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5531. {
  5532. tempIndex = 2;
  5533. }
  5534. else
  5535. {
  5536. tempIndex = gun_index;
  5537. }
  5538. for (int index = 0; index < AC_QUANTITY; index++)
  5539. {
  5540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5541. {
  5542. 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
  5543. }
  5544. } // END OF FOR AC_QUANTITY
  5545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5546. }
  5547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5552. }
  5553. //====================== Start SoC ================================
  5554. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5555. {
  5556. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5557. 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))
  5558. {
  5559. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5560. {
  5561. tempIndex = ((gun_index==2) ? 1: 0);
  5562. }
  5563. else
  5564. {
  5565. tempIndex = gun_index;
  5566. }
  5567. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5568. {
  5569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5570. {
  5571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5572. {
  5573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5574. }
  5575. }
  5576. }
  5577. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5578. {
  5579. for (int index = 0; index < CCS_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5582. {
  5583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5584. }
  5585. }
  5586. }
  5587. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5588. {
  5589. for (int index = 0; index < GB_QUANTITY; index++)
  5590. {
  5591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5592. {
  5593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5594. }
  5595. }
  5596. }
  5597. else if(gunType[gun_index] == GUN_TYPE_DO)
  5598. {
  5599. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5600. {
  5601. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5602. {
  5603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5604. }
  5605. }
  5606. }
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5613. } // END FOR DC CASE
  5614. }
  5615. //================================================ Message create ====================================================
  5616. json_object *StopTransaction = json_object_new_object();
  5617. json_object *transactionDatas = json_object_new_array();
  5618. json_object *sampledValues = json_object_new_array();
  5619. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5620. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5621. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5622. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5623. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5624. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5625. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5626. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5627. {
  5628. json_object *transactionData = json_object_new_object();
  5629. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5630. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5631. {
  5632. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5633. {
  5634. json_object *sampledValue = json_object_new_object();
  5635. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5636. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5637. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5638. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5639. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5640. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5641. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5642. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5643. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5644. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5645. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5646. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5647. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5648. json_object_array_add(sampledValues, sampledValue);
  5649. }
  5650. }
  5651. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5652. json_object_array_add(transactionDatas, transactionData);
  5653. }
  5654. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5655. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5656. ,MESSAGE_TYPE_CALL
  5657. ,guid
  5658. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5659. json_object_put(StopTransaction);
  5660. #if 1 // for TempStopTransaction
  5661. //Delete TempStopTransaction
  5662. if((access(TempStopTransaction,F_OK))!=-1)
  5663. {
  5664. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5665. }
  5666. #endif
  5667. #if 1
  5668. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5669. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5670. {
  5671. result = PASS;
  5672. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5673. }
  5674. #endif
  5675. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5676. OCPP_insert_transaction_msg(NO, queuedata);
  5677. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5678. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5679. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5680. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5681. {
  5682. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5683. }
  5684. //for test
  5685. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5686. return result;
  5687. }
  5688. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5689. {
  5690. mtrace();
  5691. int result = FAIL;
  5692. char guid[37]={0};
  5693. char tempdata[65]={0};
  5694. int tempIndex = 0;
  5695. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5696. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5697. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5698. //set value
  5699. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5700. 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) )?
  5701. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5702. -1);
  5703. random_uuid(guid);
  5704. //UTC Date time
  5705. struct timeval tmnow;
  5706. struct tm *tm;
  5707. char buf[28];//, usec_buf[6];
  5708. gettimeofday(&tmnow, NULL);
  5709. time_t t;
  5710. t = time(NULL);
  5711. /*UTC time and date*/
  5712. tm = gmtime(&t);
  5713. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5715. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5716. //********************************(1)Current.Import L1************************************************/
  5717. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5718. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5719. (dataType == ReadingContext_Trigger))
  5720. {
  5721. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5722. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5723. {
  5724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5725. {
  5726. tempIndex = ((gun_index==2) ? 1: 0);
  5727. }
  5728. else
  5729. {
  5730. tempIndex = gun_index;
  5731. }
  5732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5733. {
  5734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5735. {
  5736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5737. }
  5738. }
  5739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5740. }
  5741. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5742. {
  5743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5744. {
  5745. tempIndex = ((gun_index==2) ? 1: 0);
  5746. }
  5747. else
  5748. {
  5749. tempIndex = gun_index;
  5750. }
  5751. for (int index = 0; index < CCS_QUANTITY; index++)
  5752. {
  5753. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5754. {
  5755. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5756. }
  5757. }
  5758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5759. }
  5760. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5761. {
  5762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5763. {
  5764. tempIndex = ((gun_index==2) ? 1: 0);
  5765. }
  5766. else
  5767. {
  5768. tempIndex = gun_index;
  5769. }
  5770. for (int index = 0; index < GB_QUANTITY; index++)
  5771. {
  5772. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5773. {
  5774. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5775. }
  5776. }
  5777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5778. }
  5779. else if(gunType[gun_index] == GUN_TYPE_DO)
  5780. {
  5781. tempIndex = gun_index;
  5782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5783. {
  5784. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5785. {
  5786. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5787. }
  5788. }
  5789. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5790. }
  5791. else
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5794. {
  5795. tempIndex = 2;
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < AC_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5804. {
  5805. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5806. }
  5807. }
  5808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5809. }
  5810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5815. }
  5816. //********************************(2)Energy.Active.Import.Register ************************************************/
  5817. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5818. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5819. (dataType == ReadingContext_Trigger))
  5820. {
  5821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5822. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5823. {
  5824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5825. {
  5826. tempIndex = ((gun_index==2) ? 1: 0);
  5827. }
  5828. else
  5829. {
  5830. tempIndex = gun_index;
  5831. }
  5832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5833. {
  5834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5835. {
  5836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5837. }
  5838. }
  5839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5840. }
  5841. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5842. {
  5843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5844. {
  5845. tempIndex = ((gun_index==2) ? 1: 0);
  5846. }
  5847. else
  5848. {
  5849. tempIndex = gun_index;
  5850. }
  5851. for (int index = 0; index < CCS_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5856. }
  5857. }
  5858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5859. }
  5860. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5863. {
  5864. tempIndex = ((gun_index==2) ? 1: 0);
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < GB_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5873. {
  5874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5875. }
  5876. }
  5877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5878. }
  5879. else if(gunType[gun_index] == GUN_TYPE_DO)
  5880. {
  5881. tempIndex = gun_index;
  5882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5883. {
  5884. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5885. {
  5886. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5887. }
  5888. }
  5889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5890. }
  5891. else
  5892. {
  5893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5894. {
  5895. tempIndex = 2;
  5896. }
  5897. else
  5898. {
  5899. tempIndex = gun_index;
  5900. }
  5901. for (int index = 0; index < AC_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5906. }
  5907. }
  5908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5909. }
  5910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5915. }
  5916. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5917. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5918. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5919. (dataType == ReadingContext_Trigger))
  5920. {
  5921. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5922. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5923. {
  5924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5925. {
  5926. tempIndex = ((gun_index==2) ? 1: 0);
  5927. }
  5928. else
  5929. {
  5930. tempIndex = gun_index;
  5931. }
  5932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5933. {
  5934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5935. {
  5936. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5937. }
  5938. } // END OF FOR CHAdeMO_QUANTITY
  5939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5940. }
  5941. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5942. {
  5943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5944. {
  5945. tempIndex = ((gun_index==2) ? 1: 0);
  5946. }
  5947. else
  5948. {
  5949. tempIndex = gun_index;
  5950. }
  5951. for (int index = 0; index < CCS_QUANTITY; index++)
  5952. {
  5953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5954. {
  5955. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5956. }
  5957. } // END OF CCS_QUANTITY
  5958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5959. }
  5960. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5961. {
  5962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5963. {
  5964. tempIndex = ((gun_index==2) ? 1: 0);
  5965. }
  5966. else
  5967. {
  5968. tempIndex = gun_index;
  5969. }
  5970. for (int index = 0; index < GB_QUANTITY; index++)
  5971. {
  5972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5973. {
  5974. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5975. }
  5976. } // END OF GB_QUANTITY
  5977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5978. }
  5979. else if(gunType[gun_index] == GUN_TYPE_DO)
  5980. {
  5981. tempIndex = gun_index;
  5982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5983. {
  5984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5985. {
  5986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5987. }
  5988. }
  5989. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5990. }
  5991. else
  5992. {
  5993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5994. {
  5995. tempIndex = 2;
  5996. }
  5997. else
  5998. {
  5999. tempIndex = gun_index;
  6000. }
  6001. for (int index = 0; index < AC_QUANTITY; index++)
  6002. {
  6003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6004. {
  6005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6006. }
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6009. }
  6010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6015. }
  6016. //********************************(4)Power.Active.Import************************************************/
  6017. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6018. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6019. (dataType == ReadingContext_Trigger))
  6020. {
  6021. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6022. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6023. {
  6024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6025. {
  6026. tempIndex = ((gun_index==2) ? 1: 0);
  6027. }
  6028. else
  6029. {
  6030. tempIndex = gun_index;
  6031. }
  6032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6033. {
  6034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6035. {
  6036. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6037. }
  6038. } // END OF FOR
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6040. }
  6041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6042. {
  6043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6044. {
  6045. tempIndex = ((gun_index==2) ? 1: 0);
  6046. }
  6047. else
  6048. {
  6049. tempIndex = gun_index;
  6050. }
  6051. for (int index = 0; index < CCS_QUANTITY; index++)
  6052. {
  6053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6054. {
  6055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6056. }
  6057. }
  6058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6059. }
  6060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6063. {
  6064. tempIndex = ((gun_index==2) ? 1: 0);
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < GB_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6073. {
  6074. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6076. }
  6077. }
  6078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6079. }
  6080. else if(gunType[gun_index] == GUN_TYPE_DO)
  6081. {
  6082. tempIndex = gun_index;
  6083. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6084. {
  6085. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6086. {
  6087. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6089. }
  6090. }
  6091. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6092. }
  6093. else
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6108. }
  6109. }
  6110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6111. }
  6112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6117. }
  6118. //***********************************************(5)VOLTAGE L1******************************************************/
  6119. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6120. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6121. (dataType == ReadingContext_Trigger))
  6122. {
  6123. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6124. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6125. {
  6126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6127. {
  6128. tempIndex = ((gun_index==2) ? 1: 0);
  6129. }
  6130. else
  6131. {
  6132. tempIndex = gun_index;
  6133. }
  6134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6137. {
  6138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6139. }
  6140. }
  6141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6142. }
  6143. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6144. {
  6145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6146. {
  6147. tempIndex = ((gun_index==2) ? 1: 0);
  6148. }
  6149. else
  6150. {
  6151. tempIndex = gun_index;
  6152. }
  6153. for (int index = 0; index < CCS_QUANTITY; index++)
  6154. {
  6155. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6156. {
  6157. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6158. }
  6159. }
  6160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6161. }
  6162. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6163. {
  6164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6165. {
  6166. tempIndex = ((gun_index==2) ? 1: 0);
  6167. }
  6168. else
  6169. {
  6170. tempIndex = gun_index;
  6171. }
  6172. for (int index = 0; index < GB_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6175. {
  6176. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6177. }
  6178. }
  6179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6180. }
  6181. else if(gunType[gun_index] == GUN_TYPE_DO)
  6182. {
  6183. tempIndex = gun_index;
  6184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6185. {
  6186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6187. {
  6188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6189. }
  6190. }
  6191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6192. }
  6193. else
  6194. {
  6195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6196. {
  6197. tempIndex = 2;
  6198. }
  6199. else
  6200. {
  6201. tempIndex = gun_index;
  6202. }
  6203. for (int index = 0; index < AC_QUANTITY; index++)
  6204. {
  6205. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6206. {
  6207. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6208. }
  6209. }
  6210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6211. }
  6212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6213. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6214. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6215. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6217. }
  6218. //***********************************************(6)SOC******************************************************/
  6219. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6220. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6221. (dataType == ReadingContext_Trigger))
  6222. {
  6223. 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))
  6224. {
  6225. //idx_sample=5;
  6226. //sampledValue = NULL;
  6227. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6228. {
  6229. tempIndex = ((gun_index==2) ? 1: 0);
  6230. }
  6231. else
  6232. {
  6233. tempIndex = gun_index;
  6234. }
  6235. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6236. {
  6237. //tempIndex = ((gun_index==2) ? 1: 0);
  6238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6239. {
  6240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6241. {
  6242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6243. }
  6244. }
  6245. }
  6246. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6247. {
  6248. //tempIndex = ((gun_index==2) ? 1: 0);
  6249. for (int index = 0; index < CCS_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6254. }
  6255. }
  6256. }
  6257. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6258. {
  6259. //tempIndex = ((gun_index==2) ? 1: 0);
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6263. {
  6264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6265. }
  6266. }
  6267. }
  6268. else if(gunType[gun_index] == GUN_TYPE_DO)
  6269. {
  6270. //tempIndex = ((gun_index==2) ? 1: 0);
  6271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6272. {
  6273. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6274. {
  6275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6276. }
  6277. }
  6278. }
  6279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6285. }
  6286. }
  6287. //********************************(7)Current.Import L2************************************************/
  6288. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6289. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6290. (dataType == ReadingContext_Trigger))
  6291. {
  6292. // Only for AC 3 phase
  6293. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6294. {
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6296. {
  6297. tempIndex = 2;
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. for (int index = 0; index < AC_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6308. }
  6309. }
  6310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6311. }
  6312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6317. }
  6318. //********************************(8)Current.Import L3************************************************/
  6319. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6320. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6321. (dataType == ReadingContext_Trigger))
  6322. {
  6323. // Only for AC 3 phase
  6324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6325. {
  6326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6327. {
  6328. tempIndex = 2;
  6329. }
  6330. else
  6331. {
  6332. tempIndex = gun_index;
  6333. }
  6334. for (int index = 0; index < AC_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6337. {
  6338. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6339. }
  6340. }
  6341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6342. }
  6343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6348. }
  6349. //***********************************************(9)VOLTAGE L2******************************************************/
  6350. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6351. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6352. (dataType == ReadingContext_Trigger))
  6353. {
  6354. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6357. {
  6358. tempIndex = 2;
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < AC_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6369. }
  6370. }
  6371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6372. }
  6373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6378. }
  6379. //***********************************************(10)VOLTAGE L3******************************************************/
  6380. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6381. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6382. (dataType == ReadingContext_Trigger))
  6383. {
  6384. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6387. {
  6388. tempIndex = 2;
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < AC_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6399. }
  6400. }
  6401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6402. }
  6403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6408. }
  6409. //***********************************************(11)Current.Offered******************************************************/
  6410. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6411. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6412. (dataType == ReadingContext_Trigger))
  6413. {
  6414. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6415. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6416. {
  6417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6418. {
  6419. tempIndex = ((gun_index==2) ? 1: 0);
  6420. }
  6421. else
  6422. {
  6423. tempIndex = gun_index;
  6424. }
  6425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6430. }
  6431. } // END OF FOR CHAdeMO_QUANTITY
  6432. }
  6433. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6434. {
  6435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6436. {
  6437. tempIndex = ((gun_index==2) ? 1: 0);
  6438. }
  6439. else
  6440. {
  6441. tempIndex = gun_index;
  6442. }
  6443. for (int index = 0; index < CCS_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6446. {
  6447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6448. }
  6449. } // END OF CCS_QUANTITY
  6450. }
  6451. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6452. {
  6453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6454. {
  6455. tempIndex = ((gun_index==2) ? 1: 0);
  6456. }
  6457. else
  6458. {
  6459. tempIndex = gun_index;
  6460. }
  6461. for (int index = 0; index < GB_QUANTITY; index++)
  6462. {
  6463. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6464. {
  6465. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6466. }
  6467. } // END OF GB_QUANTITY
  6468. }
  6469. else if(gunType[gun_index] == GUN_TYPE_DO)
  6470. {
  6471. tempIndex = gun_index;
  6472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6477. }
  6478. }
  6479. }
  6480. else
  6481. {
  6482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6483. {
  6484. tempIndex = 2;
  6485. }
  6486. else
  6487. {
  6488. tempIndex = gun_index;
  6489. }
  6490. for (int index = 0; index < AC_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6493. {
  6494. uint16_t currentOffer;
  6495. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6496. {
  6497. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6498. }
  6499. else
  6500. {
  6501. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6502. }
  6503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6504. }
  6505. }
  6506. }
  6507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6512. }
  6513. //***********************************************(12)Power.Offered******************************************************/
  6514. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6515. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6516. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6517. {
  6518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6520. {
  6521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6522. {
  6523. tempIndex = ((gun_index==2) ? 1: 0);
  6524. }
  6525. else
  6526. {
  6527. tempIndex = gun_index;
  6528. }
  6529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6532. {
  6533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6534. }
  6535. } // END OF FOR CHAdeMO_QUANTITY
  6536. }
  6537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6538. {
  6539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6540. {
  6541. tempIndex = ((gun_index==2) ? 1: 0);
  6542. }
  6543. else
  6544. {
  6545. tempIndex = gun_index;
  6546. }
  6547. for (int index = 0; index < CCS_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6550. {
  6551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6552. }
  6553. } // END OF CCS_QUANTITY
  6554. }
  6555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6558. {
  6559. tempIndex = ((gun_index==2) ? 1: 0);
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < GB_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6568. {
  6569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6570. }
  6571. } // END OF GB_QUANTITY
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_DO)
  6574. {
  6575. tempIndex = gun_index;
  6576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6579. {
  6580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6581. }
  6582. }
  6583. }
  6584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6589. }
  6590. // Message create ====================================================================================================
  6591. if(TRUE)
  6592. {
  6593. json_object *MeterValueReq = json_object_new_object();
  6594. json_object *MeterValues = json_object_new_array();
  6595. json_object *sampledValues = json_object_new_array();
  6596. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6597. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6598. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6599. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6600. {
  6601. json_object *MeterValue = json_object_new_object();
  6602. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6603. {
  6604. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6605. {
  6606. json_object *sampledValue = json_object_new_object();
  6607. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6608. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6609. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6610. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6611. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6612. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6613. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6614. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6615. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6616. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6617. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6618. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6619. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6620. json_object_array_add(sampledValues, sampledValue);
  6621. }
  6622. }
  6623. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6624. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6625. json_object_array_add(MeterValues, MeterValue);
  6626. }
  6627. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6628. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6629. ,gun_index + 1
  6630. ,MESSAGE_TYPE_CALL
  6631. ,guid
  6632. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6633. json_object_put(MeterValueReq);
  6634. }
  6635. // Put request guid to hash map
  6636. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6637. 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*/)
  6638. {
  6639. result = PASS;
  6640. //DEBUG_INFO("MeterValues mapitem pass\n");
  6641. }
  6642. if((dataType != ReadingContext_Trigger) &&
  6643. (dataType != ReadingContext_Sample_Clock) &&
  6644. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6645. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6646. else
  6647. {
  6648. if(FirstHeartBeat)
  6649. LWS_Send(queuedata +2);
  6650. }
  6651. return result;
  6652. }
  6653. int sendLogStatusNotificationRequest(char *status)
  6654. {
  6655. mtrace();
  6656. int result = PASS;
  6657. char message[4096]={0};
  6658. char guid[37]={0};
  6659. char tempdata[128]={0};
  6660. json_object *LogStatusNotification = json_object_new_object();
  6661. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6662. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6663. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6664. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6665. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6666. random_uuid(guid);
  6667. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6668. json_object_put(LogStatusNotification);
  6669. LWS_Send(message);
  6670. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6671. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6672. {
  6673. result = PASS;
  6674. }
  6675. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6676. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6677. return result;
  6678. }
  6679. int sendSecurityEventNotificationRequest()
  6680. {
  6681. mtrace();
  6682. int result = PASS;
  6683. char message[4096]={0};
  6684. char guid[37]={0};
  6685. char tempdata[128]={0};
  6686. json_object *SecurityEventNotification = json_object_new_object();
  6687. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6688. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6689. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6690. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6691. random_uuid(guid);
  6692. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6693. json_object_put(SecurityEventNotification);
  6694. LWS_Send(message);
  6695. sprintf(tempdata, "SecurityEventNotification,0");
  6696. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6697. {
  6698. result = PASS;
  6699. }
  6700. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6701. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6702. return result;
  6703. }
  6704. int sendSignCertificateRequest()
  6705. {
  6706. mtrace();
  6707. int result = PASS;
  6708. char message[4096]={0};
  6709. char guid[37]={0};
  6710. char tempdata[128]={0};
  6711. json_object *SignCertificate = json_object_new_object();
  6712. DEBUG_INFO("sendSignCertificateRequest...\n");
  6713. // Read csr file content
  6714. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6715. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6716. char *line = NULL;
  6717. size_t len = 0;
  6718. while(getline(&line, &len, fp) != -1)
  6719. {
  6720. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6721. {
  6722. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6723. }
  6724. }
  6725. fclose(fp);
  6726. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6727. random_uuid(guid);
  6728. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6729. json_object_put(SignCertificate);
  6730. LWS_Send(message);
  6731. sprintf(tempdata, "SignCertificate,0");
  6732. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6733. {
  6734. result = PASS;
  6735. }
  6736. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6737. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6738. return result;
  6739. }
  6740. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6741. {
  6742. mtrace();
  6743. int result = PASS;
  6744. char message[110]={0};
  6745. char guid[37]={0};
  6746. char tempdata[65]={0};
  6747. json_object *FirmwareStatusNotification = json_object_new_object();
  6748. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6749. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6750. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6751. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6752. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6753. random_uuid(guid);
  6754. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6755. json_object_put(FirmwareStatusNotification);
  6756. LWS_Send(message);
  6757. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6758. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6759. {
  6760. result = PASS;
  6761. }
  6762. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6763. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6764. return result;
  6765. }
  6766. //==========================================
  6767. // send confirm routine
  6768. //==========================================
  6769. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6770. {
  6771. mtrace();
  6772. int result = FAIL;
  6773. char message[100]={0};
  6774. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6776. LWS_Send(message);
  6777. result = TRUE;
  6778. return result;
  6779. }
  6780. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char message[100]={0};
  6785. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6786. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6787. LWS_Send(message);
  6788. result = TRUE;
  6789. return result;
  6790. }
  6791. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6792. {
  6793. mtrace();
  6794. int result = FAIL;
  6795. char message[100]={0};
  6796. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6797. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6798. LWS_Send(message);
  6799. result = TRUE;
  6800. return result;
  6801. }
  6802. int sendClearCacheConfirmation(char *uuid,char *payload)
  6803. {
  6804. mtrace();
  6805. int result = FAIL;
  6806. char message[500]={0};
  6807. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6808. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6809. LWS_Send(message);
  6810. return result;
  6811. }
  6812. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6813. {
  6814. mtrace();
  6815. int result = FAIL;
  6816. char message[500]={0};
  6817. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6818. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6819. LWS_Send(message);
  6820. return result;
  6821. }
  6822. int sendDataTransferConfirmation(char *uuid,char *payload)
  6823. {
  6824. mtrace();
  6825. char statusStr[20]={0};
  6826. char dataStr[10]={0};
  6827. char sstr[20]={0};
  6828. int c = 0;
  6829. char *loc;
  6830. int result = FAIL;
  6831. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6832. /**********************status**************************/
  6833. loc = strstr(payload, "status");
  6834. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6835. c = 0;
  6836. while (loc[3+strlen("status")+c] != '\"')
  6837. {
  6838. sstr[c] = loc[3+strlen("status")+c];
  6839. c++;
  6840. }
  6841. sstr[c] = '\0';
  6842. strcpy(statusStr, sstr);
  6843. /**********************data**************************/
  6844. loc = strstr(payload, "data");
  6845. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6846. c = 0;
  6847. while (loc[3+strlen("data")+c] != '\"')
  6848. {
  6849. sstr[c] = loc[3+strlen("data")+c];
  6850. c++;
  6851. }
  6852. sstr[c] = '\0';
  6853. strcpy(dataStr, sstr);
  6854. return result;
  6855. }
  6856. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6857. {
  6858. mtrace();
  6859. int result = FAIL;
  6860. char message[1000]={0};
  6861. int CompositeScheduleIndex = 0;
  6862. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6863. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6864. if(nPeriod == 0)
  6865. {
  6866. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6867. {
  6868. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6869. ,MESSAGE_TYPE_CALLRESULT
  6870. ,uuid
  6871. ,payload
  6872. ,connectorIdInt);
  6873. }
  6874. else
  6875. {
  6876. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6877. ,MESSAGE_TYPE_CALLRESULT
  6878. ,uuid
  6879. ,payload
  6880. ,connectorIdInt
  6881. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6882. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6883. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6884. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6885. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6886. }
  6887. }
  6888. else
  6889. {
  6890. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6891. ,MESSAGE_TYPE_CALLRESULT
  6892. ,uuid
  6893. ,payload
  6894. ,connectorIdInt
  6895. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6896. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6897. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6898. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6899. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6900. {
  6901. if (idx_sample == 0)
  6902. {
  6903. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6904. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6905. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6906. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6907. }
  6908. else
  6909. {
  6910. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6911. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6912. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6913. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6914. }
  6915. }
  6916. sprintf(message + strlen(message), "]}}]");
  6917. }
  6918. LWS_Send(message);
  6919. result = TRUE;
  6920. return result;
  6921. }
  6922. int sendGetConfigurationConfirmation(char *uuid)
  6923. {
  6924. mtrace();
  6925. int result = FAIL;
  6926. int MaxKeySupported = 0;
  6927. int sentConfigurationNumber= 0;
  6928. int sentunConfigurationNumber= 0;
  6929. char message[1024*10]={0};
  6930. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6931. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6932. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6933. ,MESSAGE_TYPE_CALLRESULT
  6934. ,uuid );
  6935. //configuration key
  6936. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6937. {
  6938. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6939. {
  6940. if (sentConfigurationNumber == 0)
  6941. {
  6942. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6943. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6944. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6945. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6946. }
  6947. else
  6948. {
  6949. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6950. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6951. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6952. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6953. }
  6954. sentConfigurationNumber = sentConfigurationNumber + 1;
  6955. }
  6956. }
  6957. sprintf(message + strlen(message), "]");
  6958. if(UnknownKeynum != 0)
  6959. {
  6960. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6961. //unkown key
  6962. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6963. {
  6964. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6965. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6966. if(sentunConfigurationNumber == 0)
  6967. {
  6968. sprintf(message + strlen(message), "\"%s\""
  6969. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6970. }
  6971. else
  6972. {
  6973. sprintf(message + strlen(message), ",\"%s\""
  6974. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6975. }
  6976. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6977. }
  6978. sprintf(message + strlen(message), "]");
  6979. }
  6980. sprintf(message + strlen(message), "}]");
  6981. LWS_Send(message);
  6982. return result;
  6983. }
  6984. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6985. {
  6986. mtrace();
  6987. int result = FAIL;
  6988. char message[400]={0};
  6989. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6990. if(strcmp(payload,"")==0)
  6991. {
  6992. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6993. }
  6994. else
  6995. {
  6996. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6997. }
  6998. LWS_Send(message);
  6999. result = TRUE;
  7000. return result;
  7001. }
  7002. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7003. {
  7004. mtrace();
  7005. int result = FAIL;
  7006. char message[80]={0};
  7007. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7008. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7009. LWS_Send(message);
  7010. result = TRUE;
  7011. return result;
  7012. }
  7013. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7014. {
  7015. mtrace();
  7016. int result = FAIL;
  7017. char message[80]={0};
  7018. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7019. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7020. LWS_Send(message);
  7021. result = TRUE;
  7022. return result;
  7023. }
  7024. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7025. {
  7026. mtrace();
  7027. int result = FAIL;
  7028. char message[80]={0};
  7029. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7031. LWS_Send(message);
  7032. result = TRUE;
  7033. return result;
  7034. }
  7035. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7036. {
  7037. mtrace();
  7038. int result = FAIL;
  7039. char message[80]={0};
  7040. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7041. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7043. LWS_Send(message);
  7044. result = TRUE;
  7045. return result;
  7046. }
  7047. int sendResetConfirmation(char *uuid,char *payload)
  7048. {
  7049. mtrace();
  7050. int result = FAIL;
  7051. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7052. char message[80]={0};
  7053. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7054. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7055. LWS_Send(message);
  7056. result = TRUE;
  7057. return result;
  7058. }
  7059. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7060. {
  7061. mtrace();
  7062. int result = FAIL;
  7063. char message[500]={0};
  7064. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7065. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7066. LWS_Send(message);
  7067. result = TRUE;
  7068. return result;
  7069. }
  7070. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7071. {
  7072. mtrace();
  7073. int result = FAIL;
  7074. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7075. char message[80]={0};
  7076. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7077. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7078. LWS_Send(message);
  7079. result = TRUE;
  7080. return result;
  7081. }
  7082. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7083. {
  7084. mtrace();
  7085. int result = FAIL;
  7086. char message[80]={0};
  7087. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7089. LWS_Send(message);
  7090. result = TRUE;
  7091. return result;
  7092. }
  7093. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7094. {
  7095. mtrace();
  7096. int result = FAIL;
  7097. char message[80]={0};
  7098. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7099. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7100. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7101. LWS_Send(message);
  7102. result = TRUE;
  7103. return result;
  7104. }
  7105. int sendUpdateFirmwareConfirmation(char *uuid)
  7106. {
  7107. mtrace();
  7108. int result = FAIL;
  7109. char message[60]={0};
  7110. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7111. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7112. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7113. LWS_Send(message);
  7114. result = TRUE;
  7115. return result;
  7116. }
  7117. int sendCertificateSignedConfirmation(char *uuid)
  7118. {
  7119. mtrace();
  7120. int result = PASS;
  7121. char message[4096]={0};
  7122. json_object *CertificateSigned = json_object_new_object();
  7123. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7124. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7125. sprintf(message,"[%d,\"%s\",%s]"
  7126. ,MESSAGE_TYPE_CALLRESULT
  7127. ,uuid
  7128. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7129. json_object_put(CertificateSigned);
  7130. LWS_Send(message);
  7131. return result;
  7132. }
  7133. int sendDeleteCertificateConfirmation(char *uuid)
  7134. {
  7135. mtrace();
  7136. int result = PASS;
  7137. char message[4096]={0};
  7138. json_object *DeleteCertificate = json_object_new_object();
  7139. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7140. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7141. sprintf(message,"[%d,\"%s\",%s]"
  7142. ,MESSAGE_TYPE_CALLRESULT
  7143. ,uuid
  7144. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7145. json_object_put(DeleteCertificate);
  7146. LWS_Send(message);
  7147. return result;
  7148. }
  7149. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7150. {
  7151. mtrace();
  7152. int result = PASS;
  7153. char message[4096]={0};
  7154. json_object *ExtendedTriggerMessage = json_object_new_object();
  7155. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7156. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7157. sprintf(message,"[%d,\"%s\",%s]"
  7158. ,MESSAGE_TYPE_CALLRESULT
  7159. ,uuid
  7160. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7161. json_object_put(ExtendedTriggerMessage);
  7162. LWS_Send(message);
  7163. return result;
  7164. }
  7165. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7166. {
  7167. mtrace();
  7168. int result = PASS;
  7169. char message[4096]={0};
  7170. json_object *GetInstalledCertificateIds = json_object_new_object();
  7171. json_object *certificateHashDataDatas = json_object_new_array();
  7172. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7173. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7174. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7175. {
  7176. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7177. {
  7178. json_object *certificateHashData = json_object_new_object();
  7179. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7180. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7181. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7182. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7183. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7184. }
  7185. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7186. }
  7187. else
  7188. {
  7189. json_object_put(certificateHashDataDatas);
  7190. }
  7191. sprintf(message,"[%d,\"%s\",%s]"
  7192. ,MESSAGE_TYPE_CALLRESULT
  7193. ,uuid
  7194. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7195. json_object_put(GetInstalledCertificateIds);
  7196. LWS_Send(message);
  7197. return result;
  7198. }
  7199. int sendGetLogConfirmation(char *uuid)
  7200. {
  7201. mtrace();
  7202. int result = PASS;
  7203. char message[4096]={0};
  7204. json_object *GetLog = json_object_new_object();
  7205. DEBUG_INFO("sendGetLogConfirmation...\n");
  7206. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7207. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7208. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7209. sprintf(message,"[%d,\"%s\",%s]"
  7210. ,MESSAGE_TYPE_CALLRESULT
  7211. ,uuid
  7212. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7213. json_object_put(GetLog);
  7214. LWS_Send(message);
  7215. return result;
  7216. }
  7217. int sendInstallCertificateConfirmation(char *uuid)
  7218. {
  7219. mtrace();
  7220. int result = PASS;
  7221. char message[4096]={0};
  7222. json_object *InstallCertificate = json_object_new_object();
  7223. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7224. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7225. sprintf(message,"[%d,\"%s\",%s]"
  7226. ,MESSAGE_TYPE_CALLRESULT
  7227. ,uuid
  7228. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7229. json_object_put(InstallCertificate);
  7230. LWS_Send(message);
  7231. return result;
  7232. }
  7233. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7234. {
  7235. mtrace();
  7236. int result = PASS;
  7237. char message[4096]={0};
  7238. json_object *SignedUpdateFirmware = json_object_new_object();
  7239. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7240. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7241. sprintf(message,"[%d,\"%s\",%s]"
  7242. ,MESSAGE_TYPE_CALLRESULT
  7243. ,uuid
  7244. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7245. json_object_put(SignedUpdateFirmware);
  7246. LWS_Send(message);
  7247. return result;
  7248. }
  7249. int sendUnknownConfirmation(char *uuid)
  7250. {
  7251. mtrace();
  7252. int result = PASS;
  7253. char message[256]={0};
  7254. DEBUG_INFO("sendUnknownConfirmation...\n");
  7255. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7256. LWS_Send(message);
  7257. return result;
  7258. }
  7259. //==========================================
  7260. // Handle server request routine Start
  7261. //==========================================
  7262. int handleCancelReservationRequest(char *uuid, char *payload)
  7263. {
  7264. mtrace();
  7265. int result = FAIL;
  7266. int gunNO = 0;
  7267. int reservationIdInt = -1;
  7268. char comfirmstr[20];
  7269. DEBUG_INFO("handleCancelReservationRequest...\n");
  7270. json_object *CancelReservation;
  7271. CancelReservation = json_tokener_parse(payload);
  7272. if(!is_error(CancelReservation))
  7273. {
  7274. // Required data
  7275. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7276. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7277. }
  7278. json_object_put(CancelReservation);
  7279. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7280. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7281. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7282. if(reservationIdInt != -1)
  7283. {
  7284. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7285. //check Transaction active
  7286. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7288. {
  7289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7290. {
  7291. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7292. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7293. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7294. {
  7295. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7296. }
  7297. else
  7298. {
  7299. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7300. }
  7301. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7302. goto end;
  7303. }
  7304. }
  7305. for (int index = 0; index < CCS_QUANTITY; index++)
  7306. {
  7307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7308. {
  7309. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7310. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7311. if(gunType[2] == GUN_TYPE_CCS)
  7312. {
  7313. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7314. }
  7315. else
  7316. {
  7317. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7318. }
  7319. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7320. goto end;
  7321. }
  7322. }
  7323. for (int index = 0; index < GB_QUANTITY; index++)
  7324. {
  7325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7326. {
  7327. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7328. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7329. if(gunType[2] == GUN_TYPE_GBT)
  7330. {
  7331. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7332. }
  7333. else
  7334. {
  7335. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7336. }
  7337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7338. goto end;
  7339. }
  7340. }
  7341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7342. {
  7343. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7344. {
  7345. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7346. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7347. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7348. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7349. goto end;
  7350. }
  7351. }
  7352. for (int index = 0; index < AC_QUANTITY; index++)
  7353. {
  7354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7355. {
  7356. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7357. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7359. {
  7360. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7361. }
  7362. else
  7363. {
  7364. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7365. }
  7366. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7367. goto end;
  7368. }
  7369. }
  7370. }
  7371. //The reservationId does NOT match the reservationId
  7372. sendCancelReservationConfirmation(uuid, comfirmstr);
  7373. end:
  7374. // Fill in ocpp packet uuid
  7375. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7376. return result;
  7377. }
  7378. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7379. {
  7380. mtrace();
  7381. int result = FAIL;
  7382. int gunIndex = 0;
  7383. char typeStr[16]={0};
  7384. char comfirmstr[20];
  7385. int specificId = FALSE;
  7386. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7387. json_object *ChangeAvailability;
  7388. ChangeAvailability = json_tokener_parse(payload);
  7389. if(!is_error(ChangeAvailability))
  7390. {
  7391. // Required data
  7392. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7393. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7394. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7395. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7396. }
  7397. json_object_put(ChangeAvailability);
  7398. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7399. {
  7400. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7401. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7402. }
  7403. else if(gunIndex == 0)
  7404. {
  7405. for(int i=0; i < gunTotalNumber; i++)
  7406. {
  7407. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7408. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7409. }
  7410. }
  7411. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7413. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7414. {
  7415. specificId = TRUE;
  7416. }
  7417. if(specificId == FALSE)
  7418. goto end;
  7419. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7420. {
  7421. //----------------------gunIndex is 0 ------------------------------------------------//
  7422. if(gunIndex == 0)
  7423. {
  7424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7425. {
  7426. for(int i=0; i < gunTotalNumber; i++)
  7427. {
  7428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7429. {
  7430. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7431. {
  7432. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7433. {
  7434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7435. goto end;
  7436. }
  7437. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7438. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7439. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7440. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7441. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7442. {
  7443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7444. goto end;
  7445. }
  7446. }
  7447. }//END FOR CHAdeMO_QUANTITY
  7448. for (int index = 0; index < CCS_QUANTITY; index++)
  7449. {
  7450. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7451. {
  7452. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7453. {
  7454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7455. goto end;
  7456. }
  7457. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7458. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7459. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7460. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7461. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7462. {
  7463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7464. goto end;
  7465. }
  7466. }
  7467. }//END FOR CCS_QUANTITY
  7468. for (int index = 0; index < GB_QUANTITY; index++)
  7469. {
  7470. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7471. {
  7472. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7473. {
  7474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7475. goto end;
  7476. }
  7477. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7478. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7479. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7480. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7481. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7482. {
  7483. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7484. goto end;
  7485. }
  7486. }
  7487. }// END FOR GB_QUANTITY
  7488. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7489. {
  7490. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7491. {
  7492. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7493. {
  7494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7495. goto end;
  7496. }
  7497. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7498. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7499. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7500. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7501. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7502. {
  7503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7504. goto end;
  7505. }
  7506. }
  7507. }// END FOR GENERAL_GUN_QUANTITY
  7508. for (int index = 0; index < AC_QUANTITY; index++)
  7509. {
  7510. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7511. {
  7512. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7513. {
  7514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7515. goto end;
  7516. }
  7517. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7518. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7519. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7520. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7521. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7522. {
  7523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7524. goto end;
  7525. }
  7526. }
  7527. }//END FOR AC_QUANTITY
  7528. }// END FOR gunTotalNumber
  7529. }
  7530. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7531. {
  7532. for(int i=0; i < gunTotalNumber; i++)
  7533. {
  7534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7535. {
  7536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7537. goto end;
  7538. }
  7539. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7540. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7541. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7542. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7543. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7544. {
  7545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7546. goto end;
  7547. }
  7548. }
  7549. }
  7550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7551. goto end;
  7552. }
  7553. //----------------------gunIndex is not 0 ------------------------------------------------//
  7554. //check Transaction active
  7555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7556. {
  7557. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7558. {
  7559. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7560. {
  7561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7562. goto end;
  7563. }
  7564. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7565. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7566. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7569. {
  7570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7571. goto end;
  7572. }
  7573. else
  7574. {
  7575. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7577. goto end;
  7578. }
  7579. }
  7580. }//END FOR CHAdeMO_QUANTITY
  7581. for (int index = 0; index < CCS_QUANTITY; index++)
  7582. {
  7583. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7584. {
  7585. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7586. {
  7587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7588. goto end;
  7589. }
  7590. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7591. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7592. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7593. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7594. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7595. {
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7597. goto end;
  7598. }
  7599. else
  7600. {
  7601. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7603. goto end;
  7604. }
  7605. }
  7606. }//END FOR CCS_QUANTITY
  7607. for (int index = 0; index < GB_QUANTITY; index++)
  7608. {
  7609. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7610. {
  7611. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7612. {
  7613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7614. goto end;
  7615. }
  7616. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7617. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7618. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7619. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7620. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7621. {
  7622. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7623. goto end;
  7624. }
  7625. else
  7626. {
  7627. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7628. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7629. goto end;
  7630. }
  7631. }
  7632. }// END FOR GB_QUANTITY
  7633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7634. {
  7635. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7636. {
  7637. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7638. {
  7639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7640. goto end;
  7641. }
  7642. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7643. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7644. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7645. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7646. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7647. {
  7648. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7649. goto end;
  7650. }
  7651. else
  7652. {
  7653. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7655. goto end;
  7656. }
  7657. }
  7658. }// END FOR GENERAL_GUN_QUANTITY
  7659. for (int index = 0; index < AC_QUANTITY; index++)
  7660. {
  7661. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7662. {
  7663. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7664. {
  7665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7666. goto end;
  7667. }
  7668. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7669. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7673. {
  7674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7675. goto end;
  7676. }
  7677. else
  7678. {
  7679. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7681. goto end;
  7682. }
  7683. }
  7684. }//END FOR AC_QUANTITY
  7685. }//END FOR AvailabilityTypeStr[Inoperative]
  7686. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7687. {
  7688. //----------------------gunIndex is 0 ------------------------------------------------//
  7689. if(gunIndex == 0)
  7690. {
  7691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7692. {
  7693. for(int i=0; i < gunTotalNumber; i++)
  7694. {
  7695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7696. {
  7697. 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
  7698. {
  7699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7700. goto end;
  7701. }
  7702. }//END FOR CHAdeMO_QUANTITY
  7703. for (int index = 0; index < CCS_QUANTITY; index++)
  7704. {
  7705. 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
  7706. {
  7707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7708. goto end;
  7709. }
  7710. }//END FOR CCS_QUANTITY
  7711. for (int index = 0; index < GB_QUANTITY; index++)
  7712. {
  7713. 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
  7714. {
  7715. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7717. goto end;
  7718. }
  7719. }// END FOR GB_QUANTITY
  7720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7721. {
  7722. 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
  7723. {
  7724. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7726. goto end;
  7727. }
  7728. }// END FOR GENERAL_GUN_QUANTITY
  7729. for (int index = 0; index < AC_QUANTITY; index++)
  7730. {
  7731. 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
  7732. {
  7733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7734. goto end;
  7735. }
  7736. }//END FOR CHAdeMO_QUANTITY
  7737. }// END FOR gunTotalNumber
  7738. }
  7739. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7740. {
  7741. for(int i=0; i < gunTotalNumber; i++)
  7742. {
  7743. for (int index = 0; index < AC_QUANTITY; index++)
  7744. {
  7745. 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
  7746. {
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7748. goto end;
  7749. }
  7750. }//END FOR CHAdeMO_QUANTITY
  7751. } // END FOR gunTotalNumber
  7752. }
  7753. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7754. goto end;
  7755. }
  7756. //----------------------gunIndex is not 0 ------------------------------------------------//
  7757. //check Transaction active
  7758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7759. {
  7760. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7761. {
  7762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7763. goto end;
  7764. }
  7765. }//END FOR CHAdeMO_QUANTITY
  7766. for (int index = 0; index < CCS_QUANTITY; index++)
  7767. {
  7768. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7769. {
  7770. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7771. goto end;
  7772. }
  7773. }//END FOR CCS_QUANTITY
  7774. for (int index = 0; index < GB_QUANTITY; index++)
  7775. {
  7776. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7777. {
  7778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7779. goto end;
  7780. }
  7781. }// END FOR GB_QUANTITY
  7782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7783. {
  7784. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7785. {
  7786. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7787. goto end;
  7788. }
  7789. }// END FOR GENERAL_GUN_QUANTITY
  7790. for (int index = 0; index < AC_QUANTITY; index++)
  7791. {
  7792. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7793. {
  7794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7795. goto end;
  7796. }
  7797. }//END FOR AC_QUANTITY
  7798. }//END FOR AvailabilityTypeStr[Operative]
  7799. end:
  7800. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7801. {
  7802. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7803. }
  7804. else
  7805. {
  7806. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7807. }
  7808. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7809. {
  7810. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7811. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7812. }
  7813. else if(gunIndex == 0)
  7814. {
  7815. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7816. {
  7817. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7818. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7819. }
  7820. }
  7821. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7822. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7823. return result;
  7824. }
  7825. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7826. {
  7827. mtrace();
  7828. int result = FAIL;
  7829. char keystr[40]={0};
  7830. char valuestr[256]={0};
  7831. char comfirmstr[20]={0};
  7832. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7833. json_object *ChangeConfiguration;
  7834. ChangeConfiguration = json_tokener_parse(payload);
  7835. if(!is_error(ChangeConfiguration))
  7836. {
  7837. // Required data
  7838. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7839. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7840. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7841. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7842. }
  7843. json_object_put(ChangeConfiguration);
  7844. if((uuid==NULL) || (payload ==NULL) )
  7845. {
  7846. DEBUG_ERROR("Payload is null\n");
  7847. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7848. }
  7849. else
  7850. {
  7851. int status = setKeyValue(keystr, valuestr);
  7852. switch(status)
  7853. {
  7854. case ConfigurationStatus_Accepted:
  7855. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7856. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7857. StoreConfigurationTable();
  7858. break;
  7859. case RebootRequired:
  7860. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7861. StoreConfigurationTable();
  7862. break;
  7863. case NotSupported:
  7864. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7865. break;
  7866. case ConfigurationStatus_Rejected:
  7867. default:
  7868. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7869. break;
  7870. }
  7871. }
  7872. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7873. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7874. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7875. {
  7876. ChageWebSocketPingInterval(atoi(valuestr));
  7877. }
  7878. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7879. {
  7880. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7881. SetOcppConnStatus(FALSE);
  7882. }
  7883. return result;
  7884. }
  7885. int handleClearCacheRequest(char *uuid, char *payload)
  7886. {
  7887. mtrace();
  7888. int result = FAIL;
  7889. char comfirmstr[20];
  7890. char rmFileCmd[100]={0};
  7891. struct stat stats;
  7892. DEBUG_INFO("handleClearCacheRequest...\n");
  7893. stat("/Storage/OCPP", &stats);
  7894. // Check for directory existence
  7895. if (S_ISDIR(stats.st_mode) == 1)
  7896. {}
  7897. else
  7898. {
  7899. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7900. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7901. system(rmFileCmd);
  7902. }
  7903. if(OCPP_cleanLocalCache())
  7904. {
  7905. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7906. }
  7907. else
  7908. {
  7909. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7910. }
  7911. sendClearCacheConfirmation(uuid, comfirmstr);
  7912. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7913. return result;
  7914. }
  7915. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7916. {
  7917. mtrace();
  7918. int result = FAIL;
  7919. int resultRename;
  7920. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7921. char chargingProfilePurposeStr[26]={0};
  7922. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7923. char tempchargingProfilePurposeStr[26]={0};
  7924. char str[100]={0};
  7925. char fname[200]={0};
  7926. char comfirmstr[20]={0};
  7927. char word[1600]={0};
  7928. int clearflag = FALSE;
  7929. int chargingProfileIdIsNULL = FALSE;
  7930. int connectorIsNULL = FALSE;
  7931. int chargingProfilePurposeIsNULL = FALSE;
  7932. int stackLevelIsNULL = FALSE;
  7933. //int GotoEnd = FALSE;
  7934. FILE *fptr1, *fptr2;
  7935. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7936. int n_chargingProfile=0;
  7937. int isEmptyFile = FALSE;
  7938. char sLineWord[1600]={0};
  7939. char chargingProfiles[10][100]={0};
  7940. int ChargeProfileCount = 0;
  7941. int ch;
  7942. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7943. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7944. json_object *ClearChargingProfile;
  7945. ClearChargingProfile = json_tokener_parse(payload);
  7946. if(!is_error(ClearChargingProfile))
  7947. {
  7948. // Optional data
  7949. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7950. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7951. else
  7952. chargingProfileIdIsNULL = TRUE;
  7953. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7954. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7955. else
  7956. connectorIsNULL = TRUE;
  7957. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7958. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7959. else
  7960. chargingProfilePurposeIsNULL = TRUE;
  7961. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7962. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7963. else
  7964. stackLevelIsNULL = TRUE;
  7965. }
  7966. json_object_put(ClearChargingProfile);
  7967. if(connectorIsNULL == FALSE)
  7968. {
  7969. switch(connectorIdInt)
  7970. {
  7971. case 0:
  7972. if(chargingProfilePurposeIsNULL == TRUE)
  7973. {
  7974. int l = 0;
  7975. strcpy(fname, ChargePointMaxProfile_JSON);
  7976. if((access(fname,F_OK))!=-1)
  7977. {
  7978. strcpy(chargingProfiles[l], fname);
  7979. l = l + 1;
  7980. }
  7981. strcpy(fname, TxDefaultProfile_0_JSON);
  7982. if((access(fname,F_OK))!=-1)
  7983. {
  7984. strcpy(chargingProfiles[l], fname);
  7985. l = l + 1;
  7986. }
  7987. ChargeProfileCount = l;
  7988. }
  7989. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7990. {
  7991. strcpy(fname, ChargePointMaxProfile_JSON);
  7992. if((access(fname,F_OK))!=-1)
  7993. {
  7994. strcpy(chargingProfiles[0], fname);
  7995. ChargeProfileCount = 1;
  7996. }
  7997. }
  7998. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7999. {
  8000. strcpy(fname, TxDefaultProfile_0_JSON);
  8001. if((access(fname,F_OK))!=-1)
  8002. {
  8003. strcpy(chargingProfiles[0], fname);
  8004. ChargeProfileCount = 1;
  8005. }
  8006. }
  8007. break;
  8008. default:
  8009. if(chargingProfilePurposeIsNULL == TRUE)
  8010. {
  8011. int m = 0;
  8012. memset(fname, 0, ARRAY_SIZE(fname));
  8013. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8014. if((access(fname,F_OK))!=-1)
  8015. {
  8016. strcpy(chargingProfiles[m], fname);
  8017. m = m + 1;
  8018. }
  8019. memset(fname, 0, ARRAY_SIZE(fname));
  8020. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8021. if((access(fname,F_OK))!=-1)
  8022. {
  8023. strcpy(chargingProfiles[m], fname);
  8024. m = m + 1;
  8025. }
  8026. ChargeProfileCount = m;
  8027. }
  8028. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8029. {
  8030. //strcpy(fname, TxDefaultProfile_1_JSON);
  8031. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8032. if((access(fname,F_OK))!=-1)
  8033. {
  8034. strcpy(chargingProfiles[0], fname);
  8035. ChargeProfileCount = 1;
  8036. }
  8037. }
  8038. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8039. {
  8040. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8041. if((access(fname,F_OK))!=-1)
  8042. {
  8043. strcpy(chargingProfiles[0], fname);
  8044. ChargeProfileCount = 1;
  8045. }
  8046. //strcpy(fname, TxProfile_1_JSON);
  8047. }
  8048. //strcpy(fname, ChargePointMaxProfile_JSON );
  8049. break;
  8050. }
  8051. }
  8052. else // Check all Charging Profiles
  8053. {
  8054. int i = 0;
  8055. char fnametemp[200]={0};
  8056. ChargeProfileCount = 0;
  8057. //Check ChargePointMaxProfile.json exit
  8058. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8059. {
  8060. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8061. i = i + 1;
  8062. }
  8063. //Check TxDefaultProfile_0.json exit
  8064. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8065. {
  8066. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8067. i = i + 1;
  8068. }
  8069. //Check TxDefaultProfile_%d.json
  8070. for(int j=1; j <= gunTotalNumber; j++)
  8071. {
  8072. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8073. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8074. if((access(fnametemp,F_OK))!=-1)
  8075. {
  8076. strcpy(chargingProfiles[i], fnametemp);
  8077. i = i + 1;
  8078. }
  8079. }
  8080. //Check TxProfile_%d.json
  8081. for(int j=1; j <= gunTotalNumber; j++)
  8082. {
  8083. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8084. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8085. if((access(fnametemp,F_OK))!=-1)
  8086. {
  8087. strcpy(chargingProfiles[i], fnametemp);
  8088. i = i + 1;
  8089. }
  8090. }
  8091. ChargeProfileCount = i;
  8092. }// End connectorIsNULL is TRUE
  8093. if(ChargeProfileCount == 0)
  8094. {
  8095. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8096. goto end;
  8097. }
  8098. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8099. {
  8100. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8101. goto end;
  8102. }
  8103. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8104. {
  8105. memset(str, 0, ARRAY_SIZE(str));
  8106. // clear temp file
  8107. sprintf(str,"rm -f %s",temp);
  8108. system(str);
  8109. for(int k=0; k < ChargeProfileCount; k++)
  8110. {
  8111. memset(str, 0, ARRAY_SIZE(str));
  8112. //clear file in C
  8113. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8114. system(str);
  8115. }
  8116. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8117. goto end;
  8118. }
  8119. else if(connectorIsNULL == TRUE)
  8120. {
  8121. for(int k=0; k < ChargeProfileCount; k++)
  8122. {
  8123. fptr1 = fopen(chargingProfiles[k], "r");
  8124. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8125. //Check Charging Profile Count
  8126. while(fscanf(fptr1, "%s", word) != EOF)
  8127. {
  8128. //DEBUG_INFO("word=%s\n",word);
  8129. if(strstr(word, "chargingProfileId")!= NULL)
  8130. {
  8131. //DEBUG_INFO("test chargingProfileId \n");
  8132. n_chargingProfile = n_chargingProfile + 1;
  8133. //DEBUG_INFO("chargingProfileId Found\n");
  8134. }
  8135. }
  8136. rewind(fptr1);
  8137. //search Charging Profile Element
  8138. //int i= 0;
  8139. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8140. {
  8141. json_object *tmpProfilee;
  8142. tmpProfilee = json_tokener_parse(sLineWord);
  8143. if(!is_error(tmpProfilee))
  8144. {
  8145. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8146. {
  8147. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8148. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8149. }
  8150. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8151. {
  8152. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8153. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8154. }
  8155. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8156. {
  8157. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8158. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8159. }
  8160. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8161. {
  8162. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8163. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8164. }
  8165. }
  8166. json_object_put(tmpProfilee);
  8167. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8168. {
  8169. //------- not write to fptr2-------//
  8170. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8171. //clearflag = TRUE;
  8172. }
  8173. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8174. {
  8175. //------- not write to fptr2-------//
  8176. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8177. }
  8178. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8179. {
  8180. //------- not write to fptr2-------//
  8181. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8182. }
  8183. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8184. {
  8185. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8186. }
  8187. else
  8188. {
  8189. fprintf(fptr2, sLineWord);//writing data into file
  8190. }
  8191. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8192. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8193. if(clearflag == TRUE)
  8194. {
  8195. fclose(fptr1);
  8196. fclose(fptr2);
  8197. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8198. system(str);
  8199. // clear temp file
  8200. sprintf(str,"rm -f %s",temp);
  8201. system(str);
  8202. }
  8203. else
  8204. {
  8205. fclose(fptr1);
  8206. fclose(fptr2);
  8207. memset(str, 0, ARRAY_SIZE(str));
  8208. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8209. system(str);
  8210. resultRename = rename(temp, chargingProfiles[k]);
  8211. if(resultRename == 0)
  8212. {
  8213. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8214. }
  8215. else
  8216. {
  8217. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8218. }
  8219. if(comfirmstr[0]== 0)
  8220. {
  8221. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8222. }
  8223. //Check chargingProfile is empty file
  8224. /*------ Read the file ----------------*/
  8225. fptr1=fopen(chargingProfiles[k],"r");
  8226. ch=fgetc(fptr1);
  8227. rewind(fptr1);
  8228. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8229. if(ch!=EOF)
  8230. {
  8231. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8232. {
  8233. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8234. if(sLineWord[0]=='\0')
  8235. {
  8236. isEmptyFile = TRUE;
  8237. break;
  8238. }
  8239. else
  8240. {
  8241. isEmptyFile = FALSE;
  8242. break;
  8243. }
  8244. }
  8245. }
  8246. else
  8247. isEmptyFile = TRUE;
  8248. fclose(fptr1);
  8249. if(isEmptyFile == TRUE)
  8250. {
  8251. memset(str, 0, ARRAY_SIZE(str));
  8252. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8253. system(str);
  8254. }
  8255. }
  8256. }// End of while(int k=0; k < ChargePointCount; k++)
  8257. }
  8258. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8259. {
  8260. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8261. for(int k=0; k < ChargeProfileCount; k++)
  8262. {
  8263. fptr1 = fopen(chargingProfiles[k], "r");
  8264. fptr2 = fopen(temp, "w+");
  8265. //Check Charging Profile Count
  8266. while(fscanf(fptr1, "%s", word) != EOF)
  8267. {
  8268. //DEBUG_INFO("word=%s\n",word);
  8269. if(strstr(word, "chargingProfileId")!= NULL)
  8270. {
  8271. n_chargingProfile = n_chargingProfile + 1;
  8272. }
  8273. }
  8274. rewind(fptr1);
  8275. //search Charging Profile Element
  8276. //int i= 0;
  8277. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8278. {
  8279. json_object *tmpProfilee;
  8280. tmpProfilee = json_tokener_parse(sLineWord);
  8281. if(!is_error(tmpProfilee))
  8282. {
  8283. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8284. {
  8285. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8286. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8287. }
  8288. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8289. {
  8290. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8291. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8292. }
  8293. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8294. {
  8295. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8296. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8297. }
  8298. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8299. {
  8300. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8301. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8302. }
  8303. }
  8304. json_object_put(tmpProfilee);
  8305. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8306. {
  8307. //------- not write to fptr2-------//
  8308. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8309. //clearflag = TRUE;
  8310. }
  8311. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8312. {
  8313. //------- not write to fptr2-------//
  8314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8315. }
  8316. else if(stackLevelIsNULL == TRUE)
  8317. {
  8318. //Clear Whole File
  8319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8320. clearflag = TRUE;
  8321. break;
  8322. }
  8323. else
  8324. {
  8325. fprintf(fptr2, sLineWord);//writing data into file
  8326. }
  8327. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8328. }
  8329. if(clearflag == TRUE)
  8330. {
  8331. fclose(fptr1);
  8332. fclose(fptr2);
  8333. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8334. system(str);
  8335. // clear temp file
  8336. sprintf(str,"rm -f %s",temp);
  8337. system(str);
  8338. }
  8339. else
  8340. {
  8341. fclose(fptr1);
  8342. fclose(fptr2);
  8343. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8344. system(str);
  8345. resultRename = rename(temp, chargingProfiles[k]);
  8346. if(resultRename == 0)
  8347. {
  8348. DEBUG_INFO("File ChargingProfile renamed successfully");
  8349. }
  8350. else
  8351. {
  8352. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8353. }
  8354. if(comfirmstr[0]== 0)
  8355. {
  8356. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8357. }
  8358. //Check chargingProfile is empty file
  8359. /*------ Read the file ----------------*/
  8360. fptr1=fopen(chargingProfiles[k],"r");
  8361. ch=fgetc(fptr1);
  8362. rewind(fptr1);
  8363. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8364. if(ch!=EOF)
  8365. {
  8366. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8367. {
  8368. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8369. if(sLineWord[0]=='\0')
  8370. {
  8371. isEmptyFile = TRUE;
  8372. break;
  8373. }
  8374. else
  8375. {
  8376. isEmptyFile = FALSE;
  8377. break;
  8378. }
  8379. }
  8380. }
  8381. else
  8382. isEmptyFile = TRUE;
  8383. fclose(fptr1);
  8384. if(isEmptyFile == TRUE)
  8385. {
  8386. memset(str, 0, ARRAY_SIZE(str));
  8387. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8388. system(str);
  8389. }
  8390. /*------- End of reading ---------------*/
  8391. }
  8392. } // while(int k=0; k < ChargeProfileCount; k++)
  8393. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8394. end:
  8395. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8396. {
  8397. if(connectorIdInt == 0)
  8398. {
  8399. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8400. {
  8401. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8402. }
  8403. }
  8404. else
  8405. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8406. }
  8407. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8408. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8409. return result;
  8410. }
  8411. void createFirmwareVersionByDataTransfer(void)
  8412. {
  8413. json_object *FirmwareDataTransfer = json_object_new_object();
  8414. // AC & DC model
  8415. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8416. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8417. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8418. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8419. // DC model
  8420. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8421. {
  8422. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8423. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8424. (gunType[3] != GUN_TYPE_UNKNOWN))
  8425. {
  8426. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8427. }
  8428. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8429. {
  8430. // DS DM DW
  8431. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8432. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8433. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8434. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8435. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8436. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8437. }
  8438. else
  8439. {
  8440. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8441. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8442. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8443. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8444. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8445. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8446. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8447. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8448. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8449. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8450. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8451. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8452. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8453. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8454. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8455. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8456. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8457. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8458. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8459. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8460. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8461. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8462. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8463. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8464. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8465. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8466. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8467. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8468. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8469. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8470. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8471. }
  8472. }
  8473. // 4G model
  8474. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8475. {
  8476. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8477. }
  8478. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8479. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8480. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8481. json_object_put(FirmwareDataTransfer);
  8482. }
  8483. int handleDataTransferRequest(char *uuid, char *payload)
  8484. {
  8485. mtrace();
  8486. json_object *response = json_object_new_object();
  8487. int result = FAIL;
  8488. char tempvendorId[255]={0};
  8489. char tempmessageId[50]={0};
  8490. char tempdata[512]={0};
  8491. char message[2048]={0};
  8492. DEBUG_INFO("handleDataTransferRequest...\n");
  8493. if((uuid != NULL) && (payload != NULL))
  8494. {
  8495. json_object *DataTransfer;
  8496. DataTransfer = json_tokener_parse(payload);
  8497. if(!is_error(DataTransfer))
  8498. {
  8499. // Required data
  8500. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8501. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8502. // Optional data
  8503. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8504. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8505. if(json_object_object_get(DataTransfer, "data") != NULL)
  8506. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8507. result = PASS;
  8508. }
  8509. json_object_put(DataTransfer);
  8510. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8511. {
  8512. // Send all moudle firmware version on EVSE
  8513. createFirmwareVersionByDataTransfer();
  8514. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8515. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8516. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8517. json_object_put(response);
  8518. }
  8519. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8520. {
  8521. system("/usr/bin/run_tmate_restart.sh &");
  8522. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8523. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8524. json_object_put(response);
  8525. }
  8526. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8527. {
  8528. json_object *data;
  8529. data = json_tokener_parse(tempdata);
  8530. if(!is_error(data))
  8531. {
  8532. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8533. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8534. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8535. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8536. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8537. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8538. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8539. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8540. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8541. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8542. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8543. }
  8544. else
  8545. {
  8546. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8547. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8548. }
  8549. json_object_put(data);
  8550. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8551. json_object_put(response);
  8552. }
  8553. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8554. {
  8555. json_object *data;
  8556. data = json_tokener_parse(tempdata);
  8557. if(!is_error(data))
  8558. {
  8559. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8560. if(json_object_object_get(data, "idToken") != NULL)
  8561. {
  8562. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8563. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8564. }
  8565. if(json_object_object_get(data, "price") != NULL)
  8566. {
  8567. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8568. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8569. }
  8570. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8571. }
  8572. else
  8573. {
  8574. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8575. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8576. }
  8577. json_object_put(data);
  8578. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8579. json_object_put(response);
  8580. }
  8581. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8582. {
  8583. json_object *data;
  8584. data = json_tokener_parse(tempdata);
  8585. if(!is_error(data))
  8586. {
  8587. if(json_object_object_get(data, "txId") != NULL)
  8588. {
  8589. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8590. for(int idx = 0;idx<gunTotalNumber;idx++)
  8591. {
  8592. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8593. {
  8594. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8595. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8596. if(json_object_object_get(data, "description") != NULL)
  8597. {
  8598. // California pricing V1.0
  8599. DEBUG_INFO("California pricing V1.0\n");
  8600. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8601. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8602. }
  8603. else
  8604. {
  8605. // California pricing V1.1
  8606. DEBUG_INFO("California pricing V1.1\n");
  8607. if(json_object_object_get(data, "timestamp") != NULL)
  8608. {
  8609. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8610. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8611. }
  8612. if(json_object_object_get(data, "meterValue") != NULL)
  8613. {
  8614. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8615. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8616. }
  8617. if(json_object_object_get(data, "cost") != NULL)
  8618. {
  8619. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8620. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8621. }
  8622. if(json_object_object_get(data, "state") != NULL)
  8623. {
  8624. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8625. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8626. }
  8627. if(json_object_object_get(data, "chargingPrice") != NULL)
  8628. {
  8629. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8630. {
  8631. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8632. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8633. }
  8634. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8635. {
  8636. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8637. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8638. }
  8639. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8640. {
  8641. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8642. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8643. }
  8644. }
  8645. if(json_object_object_get(data, "idlePrice") != NULL)
  8646. {
  8647. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8648. {
  8649. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8650. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8651. }
  8652. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8653. {
  8654. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8655. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8656. }
  8657. }
  8658. if(json_object_object_get(data, "nextPeriod") != NULL)
  8659. {
  8660. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8661. {
  8662. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8663. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8664. }
  8665. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8666. {
  8667. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8668. {
  8669. 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")));
  8670. 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"));
  8671. }
  8672. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8673. {
  8674. 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")));
  8675. 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"));
  8676. }
  8677. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8678. {
  8679. 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")));
  8680. 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"));
  8681. }
  8682. }
  8683. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8684. {
  8685. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8686. {
  8687. 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")));
  8688. 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"));
  8689. }
  8690. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8691. {
  8692. 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")));
  8693. 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"));
  8694. }
  8695. }
  8696. }
  8697. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8698. {
  8699. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8700. {
  8701. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8702. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8703. }
  8704. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8705. {
  8706. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8707. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8708. }
  8709. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8710. {
  8711. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8712. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8713. }
  8714. }
  8715. }
  8716. }
  8717. }
  8718. }
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. }
  8721. else
  8722. {
  8723. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8724. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8725. }
  8726. json_object_put(data);
  8727. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8728. json_object_put(response);
  8729. }
  8730. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8731. {
  8732. json_object *data;
  8733. data = json_tokener_parse(tempdata);
  8734. if(!is_error(data))
  8735. {
  8736. if(json_object_object_get(data, "txId") != NULL)
  8737. {
  8738. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8739. for(int idx = 0;idx<gunTotalNumber;idx++)
  8740. {
  8741. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8742. {
  8743. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8744. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8745. if(json_object_object_get(data, "description") != NULL)
  8746. {
  8747. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8748. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8749. }
  8750. }
  8751. }
  8752. }
  8753. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8754. }
  8755. else
  8756. {
  8757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8759. }
  8760. json_object_put(data);
  8761. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8762. json_object_put(response);
  8763. }
  8764. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8765. {
  8766. json_object *data;
  8767. data = json_tokener_parse(tempdata);
  8768. if(!is_error(data))
  8769. {
  8770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8771. if(json_object_object_get(data, "Content_Type") != NULL)
  8772. {
  8773. 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))
  8774. {
  8775. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8776. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8777. {
  8778. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8779. }
  8780. }
  8781. else
  8782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8783. }
  8784. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8785. }
  8786. else
  8787. {
  8788. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8789. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8790. }
  8791. json_object_put(data);
  8792. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8793. json_object_put(response);
  8794. }
  8795. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8796. {
  8797. json_object *data;
  8798. data = json_tokener_parse(tempdata);
  8799. if(!is_error(data))
  8800. {
  8801. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8802. if(json_object_object_get(data, "Page_Index") != NULL)
  8803. {
  8804. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8805. }
  8806. if(json_object_object_get(data, "Duration") != NULL)
  8807. {
  8808. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8809. }
  8810. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8811. }
  8812. else
  8813. {
  8814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8816. }
  8817. json_object_put(data);
  8818. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8819. json_object_put(response);
  8820. }
  8821. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8822. {
  8823. json_object *data;
  8824. data = json_tokener_parse(tempdata);
  8825. if(!is_error(data))
  8826. {
  8827. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8828. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8829. {
  8830. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8831. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8832. else
  8833. {
  8834. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8835. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8836. }
  8837. }
  8838. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8839. {
  8840. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8841. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8842. else
  8843. {
  8844. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8845. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8846. }
  8847. }
  8848. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8849. {
  8850. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8851. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8852. else
  8853. {
  8854. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8855. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8856. }
  8857. }
  8858. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8859. {
  8860. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8861. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8862. else
  8863. {
  8864. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8865. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8866. }
  8867. }
  8868. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8869. {
  8870. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8871. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8872. else
  8873. {
  8874. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8875. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8876. }
  8877. }
  8878. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8879. {
  8880. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8881. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8882. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8883. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8884. else
  8885. {
  8886. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8887. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8888. }
  8889. }
  8890. if(json_object_object_get(data, "isAuthentication") != NULL)
  8891. {
  8892. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8893. {
  8894. case 0:
  8895. case 1:
  8896. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8897. break;
  8898. default:
  8899. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8900. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8901. break;
  8902. }
  8903. }
  8904. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8905. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8906. }
  8907. else
  8908. {
  8909. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8910. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8911. }
  8912. json_object_put(data);
  8913. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8914. json_object_put(response);
  8915. }
  8916. else
  8917. {
  8918. // Can not find valid message id
  8919. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8920. }
  8921. }
  8922. else
  8923. {
  8924. // Payload is null
  8925. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8926. }
  8927. LWS_Send(message);
  8928. return result;
  8929. }
  8930. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8931. {
  8932. mtrace();
  8933. int result = FAIL;
  8934. int connectorIdInt, durationInt;
  8935. char chargingRateUnitStr[4]={0};
  8936. char comfirmstr[20];
  8937. int confirmPeriods = 0;
  8938. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8939. json_object *GetCompositeSchedule;
  8940. GetCompositeSchedule = json_tokener_parse(payload);
  8941. if(!is_error(GetCompositeSchedule))
  8942. {
  8943. // Required data
  8944. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8945. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8946. else
  8947. connectorIdInt = -1;
  8948. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8949. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8950. else
  8951. durationInt = 86400;
  8952. // Optional data
  8953. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8954. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8955. }
  8956. json_object_put(GetCompositeSchedule);
  8957. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8958. if((connectorIdInt == 0) ||
  8959. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8960. {
  8961. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8962. struct StructChargingProfile tmpProfile[1];
  8963. if(strstr(chargingRateUnitStr, "W") != NULL)
  8964. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8965. else
  8966. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8967. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8968. {
  8969. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8970. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8971. }
  8972. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8973. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8974. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8975. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8976. {
  8977. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8978. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8979. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8980. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8981. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8982. {
  8983. confirmPeriods = idx;
  8984. break;
  8985. }
  8986. }
  8987. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8988. {
  8989. confirmPeriods += 1;
  8990. }
  8991. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8992. }
  8993. else
  8994. {
  8995. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8996. }
  8997. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8998. return result;
  8999. }
  9000. int handleGetConfigurationRequest(char *uuid, char *payload)
  9001. {
  9002. mtrace();
  9003. int result = FAIL;
  9004. int MaxKeySupported = 0;
  9005. int n_keys = 0;
  9006. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9007. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9008. json_object *GetConfiguration;
  9009. GetConfiguration = json_tokener_parse(payload);
  9010. if(!is_error(GetConfiguration))
  9011. {
  9012. // Optional data
  9013. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9014. {
  9015. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9016. {
  9017. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9018. n_keys = idx + 1;
  9019. }
  9020. }
  9021. }
  9022. json_object_put(GetConfiguration);
  9023. UnknownKeynum = 0;
  9024. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9025. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9026. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9027. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9028. if(n_keys != 0)
  9029. {
  9030. for(int i=0;i<n_keys;i++)
  9031. {
  9032. getKeyValue(requestKey[i]);
  9033. }
  9034. }
  9035. else
  9036. {
  9037. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9038. getKeyValue("");
  9039. }
  9040. processUnkownKey();
  9041. sendGetConfigurationConfirmation(uuid);
  9042. return result;
  9043. }
  9044. static char fnamePlusPath[100]={0};
  9045. static char fnamePWithNoPath[60]={0};
  9046. void checkUploadLog(void)
  9047. {
  9048. FILE *fp;
  9049. /* Open the command for reading. */
  9050. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9051. if (fp == NULL) {
  9052. DEBUG_WARN("Failed to run command\n" );
  9053. exit(1);
  9054. }
  9055. int ftppathlen = 0;
  9056. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9057. int i = 0;
  9058. /* Read the output a line at a time - output it. */
  9059. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9060. if(i==0)
  9061. {
  9062. ftppathlen = strlen(fnamePlusPath);
  9063. DEBUG_INFO("%s\n", fnamePlusPath);
  9064. fnamePlusPath[ftppathlen]='\0';
  9065. break;
  9066. }
  9067. i= i+1;
  9068. }
  9069. /* close */
  9070. pclose(fp);
  9071. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9072. {
  9073. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9074. {
  9075. fnamePlusPath[k]='\0';
  9076. }
  9077. }
  9078. i=1;
  9079. //char fname[60]={0};
  9080. while(i < ftppathlen)
  9081. {
  9082. int len=ftppathlen-i;
  9083. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9084. {
  9085. DEBUG_INFO("compare '/' all right\n");
  9086. break;
  9087. }
  9088. i=i+1;
  9089. }
  9090. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9091. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9092. fnamePWithNoPath[i+1] = '\0';
  9093. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9094. {
  9095. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9096. {
  9097. fnamePWithNoPath[j]='\0';
  9098. }
  9099. }
  9100. FILE* fp1 = fopen(fnamePlusPath, "r");
  9101. if (fp1)
  9102. {
  9103. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9104. // file exists
  9105. fclose(fp1);
  9106. }
  9107. else
  9108. {
  9109. // file doesn't exist
  9110. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9111. }
  9112. }
  9113. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9114. {
  9115. mtrace();
  9116. int result = FAIL;
  9117. time_t CurrentTime;
  9118. struct tm *tm;
  9119. pthread_t th_Status;
  9120. CurrentTime = time(NULL);
  9121. tm = localtime(&CurrentTime);
  9122. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9123. 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);
  9124. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9125. if(!interLock.isGetDiagnosticGoing)
  9126. {
  9127. interLock.isGetDiagnosticGoing = 1;
  9128. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9129. sleep(1);
  9130. }
  9131. else
  9132. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9133. return result;
  9134. }
  9135. void* GetDiagnosticsProcess(void* data)
  9136. {
  9137. pthread_detach(pthread_self());
  9138. mtrace();
  9139. int retriesInt=0, retryIntervalInt=0;
  9140. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9141. 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};
  9142. int port=0;
  9143. int isSuccess = FALSE;
  9144. char cmdBuf[2048];
  9145. struct tm *tmNow;
  9146. time_t CurrentTime;
  9147. struct tm tmStart;
  9148. struct tm tmStop;
  9149. CurrentTime = time(NULL);
  9150. tmNow=localtime(&CurrentTime);
  9151. uint16_t targetYear, targetMonth;
  9152. json_object *GetDiagnostics;
  9153. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9154. GetDiagnostics = json_tokener_parse(data);
  9155. if(!is_error(GetDiagnostics))
  9156. {
  9157. // Required data
  9158. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9159. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9160. // Optional data
  9161. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9162. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9163. else
  9164. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9165. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9166. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9167. else
  9168. retryIntervalInt = 30;
  9169. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9170. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9171. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9172. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9173. }
  9174. json_object_put(GetDiagnostics);
  9175. // Pack log to compress file
  9176. 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) &&
  9177. (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))
  9178. {
  9179. // Pack system log
  9180. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9181. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9182. targetYear = tmStart.tm_year;
  9183. targetMonth = tmStart.tm_mon;
  9184. do
  9185. {
  9186. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9187. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9188. if(targetMonth+1>=13)
  9189. {
  9190. targetYear += 1;
  9191. targetMonth = 1;
  9192. }
  9193. else
  9194. {
  9195. targetMonth += 1;
  9196. }
  9197. }while((targetYear < (tmNow->tm_year+1900)) ||
  9198. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9199. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9200. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9201. system(cmdBuf);
  9202. // Pack charging & event log
  9203. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9204. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9205. targetYear = tmStart.tm_year;
  9206. targetMonth = tmStart.tm_mon;
  9207. do
  9208. {
  9209. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9210. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9211. if(targetMonth+1>=13)
  9212. {
  9213. targetYear += 1;
  9214. targetMonth = 1;
  9215. }
  9216. else
  9217. {
  9218. targetMonth += 1;
  9219. }
  9220. }while((targetYear < (tmNow->tm_year+1900)) ||
  9221. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9222. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9223. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9224. system(cmdBuf);
  9225. // Combine log file
  9226. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9227. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9228. }
  9229. else
  9230. {
  9231. system("exec /root/logPackTools 'log' 6");
  9232. }
  9233. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9234. system(cmdBuf);
  9235. checkUploadLog();
  9236. //****************location*******************/
  9237. if(strcmp(locationstr,"")==0)
  9238. {
  9239. DEBUG_INFO("location is <Empty>!\n");
  9240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9242. goto end;
  9243. }
  9244. memset(protocol, 0, ARRAY_SIZE(protocol));
  9245. memset(user, 0, ARRAY_SIZE(user) );
  9246. memset(password, 0, ARRAY_SIZE(password));
  9247. memset(host, 0, ARRAY_SIZE(host));
  9248. memset(path, 0, ARRAY_SIZE(path));
  9249. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9250. memset(host1, 0, ARRAY_SIZE(host1));
  9251. memset(path1, 0, ARRAY_SIZE(path1));
  9252. /*location: ftp://user:password@host:port/path*/
  9253. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9254. if((access(fnamePlusPath,F_OK))!=-1)
  9255. {
  9256. DEBUG_INFO("fnamePlusPath exist.\n");
  9257. }
  9258. else
  9259. {
  9260. DEBUG_INFO("fnamePlusPath not exist!\n");
  9261. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9262. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9263. goto end;
  9264. }
  9265. if(strchr(locationstr,'@')==NULL)
  9266. {
  9267. sscanf(locationstr,
  9268. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9269. protocol, host, &port, path);
  9270. strcpy(user,"anonymous");
  9271. strcpy(password,"");
  9272. }
  9273. else
  9274. {
  9275. //DEBUG_INFO("pch=%s\n", pch);
  9276. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9277. protocol, user, password, host, &port, path);
  9278. }
  9279. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9280. {
  9281. DEBUG_INFO("protocol is not ftp/http ! \n");
  9282. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9283. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9284. goto end;
  9285. }
  9286. if(strncmp(locationstr,"http", 4) == 0)
  9287. {
  9288. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9289. sprintf(ftppath,"/%s", path);
  9290. do
  9291. {
  9292. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9293. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9294. sleep(3);
  9295. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9296. if(!isSuccess)
  9297. {
  9298. DEBUG_INFO("Diagnostics fail.\n");
  9299. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9300. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9301. sleep(retryIntervalInt);
  9302. }
  9303. else
  9304. {
  9305. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9306. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9307. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9308. }
  9309. retriesInt--;
  9310. }while((isSuccess == 0)&&(retriesInt >= 0));
  9311. }
  9312. else
  9313. {
  9314. sscanf(host,"%[^/]%s",host1, path1);
  9315. if(strlen(path) > 0)
  9316. sprintf(ftppath,"/%s", path);
  9317. else
  9318. sprintf(ftppath,"/%s", path1);
  9319. int ftppathlen=strlen(ftppath);
  9320. int i=1;
  9321. char filenametemp[50];
  9322. while(i < ftppathlen)
  9323. {
  9324. int len=ftppathlen-i;
  9325. if(ftppath[len]== 47) // '/' ascll code: 47
  9326. {
  9327. DEBUG_INFO("find '/' all right\n");
  9328. break;
  9329. }
  9330. i=i+1;
  9331. }
  9332. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9333. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9334. filenametemp[i+1] = 0;
  9335. if(port == 0)
  9336. port = 21;
  9337. do
  9338. {
  9339. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9340. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9341. sleep(3);
  9342. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9343. if(!isSuccess)
  9344. {
  9345. DEBUG_INFO("Diagnostics fail.\n");
  9346. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9347. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9348. sleep(retryIntervalInt);
  9349. }
  9350. else
  9351. {
  9352. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9353. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9354. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9355. }
  9356. retriesInt--;
  9357. }while((!isSuccess)&&(retriesInt >= 0));
  9358. }
  9359. end:
  9360. system("rm -f /mnt/*");
  9361. sleep(5);
  9362. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9363. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9364. interLock.isGetDiagnosticGoing = 0;
  9365. pthread_exit(NULL);
  9366. }
  9367. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9368. {
  9369. mtrace();
  9370. int result = FAIL;
  9371. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9372. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9373. {
  9374. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9375. locallistVersion = -1;
  9376. }
  9377. else
  9378. {
  9379. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9380. OCPP_getListVerion();
  9381. }
  9382. //from db.OCPP_getListVerion
  9383. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9384. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9385. sendGetLocalListVersionConfirmation(uuid,"");
  9386. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9387. return result;
  9388. }
  9389. int handleRemoteStartRequest(char *uuid, char *payload)
  9390. {
  9391. mtrace();
  9392. int result = FAIL;
  9393. int connectorIdInt=-1;
  9394. int tempIndex = 0;
  9395. int connectorIdIsNULL, chargingProfileIsNULL;
  9396. char comfirmstr[20]={0};
  9397. char cmdBuf[512];
  9398. json_object *RemoteStartTransaction;
  9399. FILE *fp;
  9400. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9401. if(server_pending == TRUE)
  9402. {
  9403. return 0;
  9404. }
  9405. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9406. RemoteStartTransaction = json_tokener_parse(payload);
  9407. if(!is_error(RemoteStartTransaction))
  9408. {
  9409. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9410. {
  9411. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9412. }
  9413. else
  9414. {
  9415. connectorIdIsNULL = TRUE;
  9416. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9417. {
  9418. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9419. {
  9420. connectorIdIsNULL = FALSE;
  9421. connectorIdInt = (gun_index+1);
  9422. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9423. break;
  9424. }
  9425. }
  9426. }
  9427. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9428. {
  9429. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9430. // Required data
  9431. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9432. // Optional data
  9433. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9434. {
  9435. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9436. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9437. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9438. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9439. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9440. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9441. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9442. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9443. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9444. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9445. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9446. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9447. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9448. {
  9449. 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")));
  9450. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9451. 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"));
  9452. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9453. 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"));
  9454. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9455. 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")));
  9456. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9457. {
  9458. 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++)
  9459. {
  9460. 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"));
  9461. 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"));
  9462. 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)
  9463. 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"));
  9464. }
  9465. }
  9466. }
  9467. }
  9468. else
  9469. {
  9470. chargingProfileIsNULL = TRUE;
  9471. }
  9472. }
  9473. }
  9474. else
  9475. {
  9476. connectorIdIsNULL = TRUE;
  9477. }
  9478. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9479. {
  9480. DEBUG_WARN("Connector id is NULL\n.");
  9481. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9482. goto end;
  9483. }
  9484. /*
  9485. enum _SYSTEM_STATUS
  9486. {
  9487. S_BOOTING = 0,
  9488. S_IDLE, = 1
  9489. S_AUTHORIZING, = 2
  9490. S_REASSIGN_CHECK, = 3
  9491. S_REASSIGN, = 4
  9492. S_PRECHARGE, = 5
  9493. S_PREPARING_FOR_EV, = 6
  9494. S_PREPARING_FOR_EVSE, = 7
  9495. S_CHARGING, = 8
  9496. S_TERMINATING, = 9
  9497. S_COMPLETE, = 10
  9498. S_ALARM, = 11
  9499. S_FAULT = 12
  9500. }
  9501. */
  9502. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9503. {
  9504. //check Transaction active
  9505. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9506. {
  9507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9508. {
  9509. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9510. }
  9511. else
  9512. {
  9513. tempIndex = connectorIdInt -1;
  9514. }
  9515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9516. {
  9517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9518. {
  9519. 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))
  9520. {
  9521. //Reserved
  9522. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9523. }
  9524. 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))
  9525. {
  9526. //Reserved
  9527. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9529. goto end;
  9530. }
  9531. else
  9532. {
  9533. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9534. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9535. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9536. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9537. {
  9538. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9539. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9540. goto end;
  9541. }
  9542. }//END FOR ELSE
  9543. }
  9544. }// END FOR CHAdeMO_QUANTITY
  9545. }
  9546. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9547. {
  9548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9549. {
  9550. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9551. }
  9552. else
  9553. {
  9554. tempIndex = connectorIdInt -1;
  9555. }
  9556. for (int index = 0; index < CCS_QUANTITY; index++)
  9557. {
  9558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9559. {
  9560. 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))
  9561. {
  9562. //Reserved
  9563. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9564. }
  9565. 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))
  9566. {
  9567. //Reserved
  9568. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9569. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9570. goto end;
  9571. }
  9572. else
  9573. {
  9574. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9575. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9576. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9577. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9578. {
  9579. DEBUG_WARN("CCS connector not allow start\n.");
  9580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9581. goto end;
  9582. }
  9583. }// END FOR ELSE
  9584. }
  9585. }// END FOR CCS_QUANTITY
  9586. }
  9587. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9588. {
  9589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9590. {
  9591. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9592. }
  9593. else
  9594. {
  9595. tempIndex = connectorIdInt -1;
  9596. }
  9597. for (int index = 0; index < GB_QUANTITY; index++)
  9598. {
  9599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9600. {
  9601. 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))
  9602. {
  9603. //Reserved
  9604. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9605. }
  9606. 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))
  9607. {
  9608. //Reserved
  9609. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9610. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9611. goto end;
  9612. }
  9613. else
  9614. {
  9615. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9616. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9617. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9618. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9619. {
  9620. DEBUG_WARN("GB connector not allow start\n.");
  9621. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9622. goto end;
  9623. }
  9624. }// END FOR ELSE
  9625. }
  9626. } // END FOR GB_QUANTITY
  9627. }
  9628. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9629. {
  9630. tempIndex = connectorIdInt -1;
  9631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9632. {
  9633. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9634. {
  9635. 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))
  9636. {
  9637. //Reserved
  9638. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9639. }
  9640. 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))
  9641. {
  9642. //Reserved
  9643. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9644. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9645. goto end;
  9646. }
  9647. else
  9648. {
  9649. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9650. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9651. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9652. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9653. {
  9654. DEBUG_WARN("GB connector not allow start\n.");
  9655. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9656. goto end;
  9657. }
  9658. }// END FOR ELSE
  9659. }
  9660. } // END FOR GB_QUANTITY
  9661. }
  9662. else
  9663. {
  9664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9665. {
  9666. tempIndex = 2;
  9667. }
  9668. else
  9669. {
  9670. tempIndex = connectorIdInt -1;
  9671. }
  9672. for (int index = 0; index < AC_QUANTITY; index++)
  9673. {
  9674. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9675. {
  9676. 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))
  9677. {
  9678. //Reserved
  9679. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9680. }
  9681. 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))
  9682. {
  9683. //Reserved
  9684. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9685. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9686. goto end;
  9687. }
  9688. else
  9689. {
  9690. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9691. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9692. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9693. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9694. {
  9695. DEBUG_WARN("AC connector not allow start\n.");
  9696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9697. goto end;
  9698. }
  9699. }//END FOR ELSE
  9700. }
  9701. }// END FOR AC_QUANTITY
  9702. }
  9703. if(chargingProfileIsNULL == FALSE)
  9704. {
  9705. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9706. {
  9707. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9708. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9709. //memset idTag
  9710. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9711. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9712. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9713. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9714. // Save profile to file
  9715. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9716. system(cmdBuf);
  9717. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9718. fp = fopen(cmdBuf, "w");
  9719. 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));
  9720. fclose(fp);
  9721. }
  9722. else
  9723. {
  9724. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9725. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9726. }
  9727. }
  9728. else
  9729. {
  9730. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9732. //memset idTag
  9733. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9734. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9735. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9736. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9737. }
  9738. }
  9739. else
  9740. {
  9741. DEBUG_WARN("Connector id over\n.");
  9742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9743. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9744. }
  9745. end:
  9746. json_object_put(RemoteStartTransaction);
  9747. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9748. {
  9749. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9750. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9751. }
  9752. //OCPP send RemoteStartConfirmation by first.
  9753. sendRemoteStartConfirmation(uuid, comfirmstr);
  9754. return result;
  9755. }
  9756. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9757. {
  9758. mtrace();
  9759. int result = FAIL;
  9760. int match = FALSE;
  9761. int GunNO = 0;
  9762. int tempIndex = 0;
  9763. int transactionIdInt=0;
  9764. int transactionIdIsNULL= TRUE;
  9765. char comfirmstr[20];
  9766. json_object *RemoteStopTransaction;
  9767. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9768. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9769. if(server_pending == TRUE)
  9770. {
  9771. return 0;
  9772. }
  9773. RemoteStopTransaction = json_tokener_parse(payload);
  9774. if(!is_error(RemoteStopTransaction))
  9775. {
  9776. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9777. {
  9778. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9779. transactionIdIsNULL = FALSE;
  9780. }
  9781. }
  9782. json_object_put(RemoteStopTransaction);
  9783. if(transactionIdIsNULL == FALSE)
  9784. {
  9785. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9786. {
  9787. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9788. {
  9789. //check Transaction active
  9790. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9791. {
  9792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9793. {
  9794. tempIndex = ((gun_index==2) ? 1: 0);
  9795. }
  9796. else
  9797. {
  9798. tempIndex = gun_index;
  9799. }
  9800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9801. {
  9802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9803. {
  9804. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9805. {
  9806. match = TRUE;
  9807. GunNO = gun_index;
  9808. }
  9809. }
  9810. }// END FOR CHAdeMO_QUANTITY
  9811. }
  9812. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9813. {
  9814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9815. {
  9816. tempIndex = ((gun_index==2) ? 1: 0);
  9817. }
  9818. else
  9819. {
  9820. tempIndex = gun_index;
  9821. }
  9822. for (int index = 0; index < CCS_QUANTITY; index++)
  9823. {
  9824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9825. {
  9826. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9827. {
  9828. match = TRUE;
  9829. GunNO = gun_index;
  9830. }
  9831. }
  9832. }// END FOR CCS_QUANTITY
  9833. }
  9834. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9835. {
  9836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9837. {
  9838. tempIndex = ((gun_index==2) ? 1: 0);
  9839. }
  9840. else
  9841. {
  9842. tempIndex = gun_index;
  9843. }
  9844. for (int index = 0; index < GB_QUANTITY; index++)
  9845. {
  9846. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9847. {
  9848. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9849. {
  9850. match = TRUE;
  9851. GunNO = gun_index;
  9852. }
  9853. }
  9854. }// END FOR GB_QUANTITY
  9855. }
  9856. else if(gunType[gun_index] == GUN_TYPE_DO)
  9857. {
  9858. tempIndex = gun_index;
  9859. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9860. {
  9861. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9862. {
  9863. 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
  9864. {
  9865. match = TRUE;
  9866. GunNO = gun_index;
  9867. }
  9868. }
  9869. }// END FOR GB_QUANTITY
  9870. }
  9871. else
  9872. {
  9873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9874. {
  9875. tempIndex = 2;
  9876. }
  9877. else
  9878. {
  9879. tempIndex = gun_index;
  9880. }
  9881. for (int index = 0; index < AC_QUANTITY; index++)
  9882. {
  9883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9884. {
  9885. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9886. {
  9887. match = TRUE;
  9888. GunNO = gun_index;
  9889. }
  9890. }
  9891. }// END FOR CHAdeMO_QUANTITY
  9892. } // END FOR AC ELSE
  9893. }// CHECK IF ResponseTransactionId == transactionIdInt
  9894. }//END FOR
  9895. if( match == TRUE)
  9896. {
  9897. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9899. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9900. }
  9901. else
  9902. {
  9903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9904. }
  9905. }
  9906. else
  9907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9908. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9909. return result;
  9910. }
  9911. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9912. {
  9913. mtrace();
  9914. int result = FAIL;
  9915. int connectorIdInt=0, reservationIdInt=0;
  9916. int tempIndex = 0;
  9917. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9918. char comfirmstr[20]={0};
  9919. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9920. int c = 0;
  9921. char *loc;
  9922. //char *ptr;
  9923. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9924. strcpy(sstrtemp, stringtrimspace(payload));
  9925. //***(1)connectorId ****/
  9926. c=0;
  9927. loc = strstr(sstrtemp, "connectorId");
  9928. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9929. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9930. {
  9931. sstr[c] = loc[strlen("connectorId")+2+c];
  9932. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9933. c++;
  9934. }
  9935. sstr[c] = '\0';
  9936. connectorIdInt = atoi(sstr);
  9937. //***(2)expiryDate ****/
  9938. loc = strstr(sstrtemp, "expiryDate");
  9939. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9940. c = 0;
  9941. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9942. {
  9943. sstr[c] = loc[3+strlen("expiryDate")+c];
  9944. c++;
  9945. }
  9946. sstr[c] = '\0';
  9947. strcpy(expiryDatestr, sstr);
  9948. //***(3)idTag ****/
  9949. loc = strstr(sstrtemp, "idTag");
  9950. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9951. c = 0;
  9952. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9953. {
  9954. sstr[c] = loc[3+strlen("idTag")+c];
  9955. c++;
  9956. }
  9957. sstr[c] = '\0';
  9958. strcpy(idTagstr, sstr);
  9959. //***(4)parentIdTag ****/
  9960. loc = strstr(sstrtemp, "parentIdTag");
  9961. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9962. c = 0;
  9963. if(loc == NULL)
  9964. {
  9965. strcpy(parentIdTagstr, "");
  9966. }
  9967. else
  9968. {
  9969. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9970. {
  9971. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9972. c++;
  9973. }
  9974. sstr[c] = '\0';
  9975. strcpy(parentIdTagstr, sstr);
  9976. }
  9977. //***(5)reservationId ****/
  9978. c=0;
  9979. loc = strstr(sstrtemp, "reservationId");
  9980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9981. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9982. {
  9983. sstr[c] = loc[strlen("reservationId")+2+c];
  9984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9985. c++;
  9986. }
  9987. sstr[c] = '\0';
  9988. reservationIdInt = atoi(sstr);
  9989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9990. /*
  9991. enum SYSTEM_STATUS
  9992. {
  9993. SYS_MODE_BOOTING = 0,
  9994. SYS_MODE_IDLE = 1,
  9995. SYS_MODE_AUTHORIZING = 2,
  9996. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9997. SYS_MODE_REASSIGN = 4,
  9998. SYS_MODE_PREPARING = 5,
  9999. SYS_MODE_PREPARE_FOR_EV = 6,
  10000. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10001. SYS_MODE_CHARGING = 8,
  10002. SYS_MODE_TERMINATING = 9,
  10003. SYS_MODE_COMPLETE = 10,
  10004. SYS_MODE_ALARM = 11,
  10005. SYS_MODE_FAULT = 12,
  10006. SYS_MODE_RESERVATION = 13,
  10007. SYS_MODE_BOOKING = 14,
  10008. SYS_MODE_MAINTAIN = 15,
  10009. SYS_MODE_DEBUG = 16,
  10010. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10011. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10012. SYS_MODE_UPDATE = 19
  10013. };
  10014. */
  10015. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10016. {
  10017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10018. goto end;
  10019. }
  10020. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10021. {
  10022. //check Transaction active
  10023. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10024. {
  10025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10026. {
  10027. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10028. }
  10029. else
  10030. {
  10031. tempIndex = connectorIdInt -1;
  10032. }
  10033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10034. {
  10035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10036. {
  10037. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10038. {
  10039. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10040. {
  10041. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10042. {
  10043. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10045. }
  10046. 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'))
  10047. {
  10048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10049. }
  10050. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10051. {
  10052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10053. }
  10054. else
  10055. {
  10056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10057. }
  10058. }
  10059. 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
  10060. {
  10061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10062. }
  10063. }
  10064. else
  10065. {
  10066. //replace reservation
  10067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10069. }
  10070. }
  10071. } // END FOR CHAdeMO_QUANTITY
  10072. }
  10073. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10074. {
  10075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10076. {
  10077. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10078. }
  10079. else
  10080. {
  10081. tempIndex = connectorIdInt -1;
  10082. }
  10083. for (int index = 0; index < CCS_QUANTITY; index++)
  10084. {
  10085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10086. {
  10087. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10088. {
  10089. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10090. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10091. {
  10092. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10093. {
  10094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10096. }
  10097. 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'))
  10098. {
  10099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10100. }
  10101. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10102. {
  10103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10104. }
  10105. else
  10106. {
  10107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10108. }
  10109. }
  10110. 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
  10111. {
  10112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10113. }
  10114. }
  10115. else
  10116. {
  10117. //replace reservation
  10118. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10120. }
  10121. }
  10122. } // END FOR CCS_QUANTITY
  10123. }
  10124. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10125. {
  10126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10127. {
  10128. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10129. }
  10130. else
  10131. {
  10132. tempIndex = connectorIdInt -1;
  10133. }
  10134. for (int index = 0; index < GB_QUANTITY; index++)
  10135. {
  10136. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10137. {
  10138. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10139. {
  10140. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10141. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10142. {
  10143. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10144. {
  10145. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10147. }
  10148. 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'))
  10149. {
  10150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10151. }
  10152. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10153. {
  10154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10155. }
  10156. else
  10157. {
  10158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10159. }
  10160. }
  10161. 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
  10162. {
  10163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10164. }
  10165. }
  10166. else
  10167. {
  10168. //replace reservation
  10169. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10171. }
  10172. }
  10173. }// END FOR GB_QUANTITY
  10174. }
  10175. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10176. {
  10177. tempIndex = connectorIdInt -1;
  10178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10179. {
  10180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10181. {
  10182. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10183. {
  10184. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10185. 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
  10186. {
  10187. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10188. {
  10189. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10191. }
  10192. 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'))
  10193. {
  10194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10195. }
  10196. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10197. {
  10198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10199. }
  10200. else
  10201. {
  10202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10203. }
  10204. }
  10205. 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
  10206. {
  10207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10208. }
  10209. }
  10210. else
  10211. {
  10212. //replace reservation
  10213. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10215. }
  10216. }
  10217. }// END FOR GB_QUANTITY
  10218. }
  10219. else
  10220. {
  10221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10222. {
  10223. tempIndex = 2;
  10224. }
  10225. else
  10226. {
  10227. tempIndex = (connectorIdInt -1);
  10228. }
  10229. for (int index = 0; index < AC_QUANTITY; index++)
  10230. {
  10231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10232. {
  10233. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10234. {
  10235. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10236. {
  10237. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10238. {
  10239. 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))
  10240. {
  10241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10242. }
  10243. else
  10244. {
  10245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10247. }
  10248. }
  10249. 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'))
  10250. {
  10251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10252. }
  10253. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10254. {
  10255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10256. }
  10257. else
  10258. {
  10259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10260. }
  10261. }
  10262. 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
  10263. {
  10264. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10265. }
  10266. }
  10267. else
  10268. {
  10269. //replace reservation
  10270. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10272. }
  10273. }
  10274. } // END FOR AC_QUANTITY
  10275. }
  10276. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10277. }
  10278. else if(connectorIdInt == 0)
  10279. {
  10280. //check Transaction active
  10281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10282. {
  10283. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10284. {
  10285. 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'))
  10286. {
  10287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10288. goto end;
  10289. }
  10290. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10291. {
  10292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10293. goto end;
  10294. }
  10295. 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
  10296. {
  10297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10298. goto end;
  10299. }
  10300. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10301. {
  10302. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10303. goto end;
  10304. }
  10305. }
  10306. }// END FOR CHAdeMO_QUANTITY
  10307. for (int index = 0; index < CCS_QUANTITY; index++)
  10308. {
  10309. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10310. {
  10311. 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'))
  10312. {
  10313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10314. goto end;
  10315. }
  10316. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10317. {
  10318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10319. goto end;
  10320. }
  10321. 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
  10322. {
  10323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10324. goto end;
  10325. }
  10326. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10327. {
  10328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10329. goto end;
  10330. }
  10331. }
  10332. } // END FOR CCS_QUANTITY
  10333. for (int index = 0; index < GB_QUANTITY; index++)
  10334. {
  10335. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10336. {
  10337. 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'))
  10338. {
  10339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10340. goto end;
  10341. }
  10342. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10343. {
  10344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10345. goto end;
  10346. }
  10347. 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
  10348. {
  10349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10350. goto end;
  10351. }
  10352. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10353. {
  10354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10355. goto end;
  10356. }
  10357. }
  10358. } // END FOR GB_QUANTITY
  10359. for (int index = 0; index < AC_QUANTITY; index++)
  10360. {
  10361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10362. {
  10363. 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'))
  10364. {
  10365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10366. goto end;
  10367. }
  10368. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10369. {
  10370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10371. goto end;
  10372. }
  10373. 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
  10374. {
  10375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10376. goto end;
  10377. }
  10378. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10379. {
  10380. 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))
  10381. {
  10382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10383. goto end;
  10384. }
  10385. }
  10386. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10387. {
  10388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10389. goto end;
  10390. }
  10391. }
  10392. }// END FOR AC_QUANTITY
  10393. //The connectorId is 0
  10394. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10396. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10397. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10398. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10399. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10400. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10401. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10402. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10403. result = TRUE;
  10404. return result;
  10405. }
  10406. else
  10407. {
  10408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10409. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10410. }
  10411. if(strcmp(comfirmstr,"Accepted") == 0)
  10412. {
  10413. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10414. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10415. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10416. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10417. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10418. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10419. result = TRUE;
  10420. return result;
  10421. }
  10422. end:
  10423. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10424. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10425. return result;
  10426. }
  10427. int handleResetRequest(char *uuid, char *payload)
  10428. {
  10429. mtrace();
  10430. int result = FAIL;
  10431. char sstr[10]={0},sstrtemp[30]={ 0 };
  10432. char typestr[10]={0};
  10433. char comfirmstr[20]={0};
  10434. int c = 0;
  10435. char *loc;
  10436. DEBUG_INFO("handleResetRequest...\n");
  10437. strcpy(sstrtemp, stringtrimspace(payload));
  10438. loc = strstr(sstrtemp, "type");
  10439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10440. c = 0;
  10441. while (loc[3+strlen("type")+c] != '\"')
  10442. {
  10443. sstr[c] = loc[3+strlen("type")+c];
  10444. c++;
  10445. }
  10446. sstr[c] = '\0';
  10447. strcpy(typestr,sstr);
  10448. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10449. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10450. {
  10451. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10452. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10453. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10454. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10455. }
  10456. else
  10457. {
  10458. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10459. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10460. result = PASS;
  10461. }
  10462. sendResetConfirmation(uuid, comfirmstr);
  10463. return result;
  10464. }
  10465. int handleSendLocalListRequest(char *uuid, char *payload)
  10466. {
  10467. mtrace();
  10468. int result = FAIL;
  10469. char comfirmstr[20];
  10470. int checkState_Faulted = FALSE;
  10471. json_object *SendLocalList;
  10472. DEBUG_INFO("handleSendLocalListRequest...\n");
  10473. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10474. {
  10475. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10476. goto end;
  10477. }
  10478. //check Charge Point state
  10479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10480. {
  10481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10482. {
  10483. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10484. }
  10485. }
  10486. for (int index = 0; index < CCS_QUANTITY; index++)
  10487. {
  10488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10489. {
  10490. checkState_Faulted = TRUE; //OCPP Status
  10491. }
  10492. }
  10493. for (int index = 0; index < GB_QUANTITY; index++)
  10494. {
  10495. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10496. {
  10497. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10498. }
  10499. }
  10500. //check Charge Point state
  10501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10502. {
  10503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10504. {
  10505. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10506. }
  10507. }
  10508. //check Charge Point state
  10509. for (int index = 0; index < AC_QUANTITY; index++)
  10510. {
  10511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10512. {
  10513. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10514. }
  10515. }
  10516. if(checkState_Faulted == TRUE)
  10517. {
  10518. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10519. goto end;
  10520. }
  10521. // Parsing payload
  10522. SendLocalList = json_tokener_parse(payload);
  10523. if(!is_error(SendLocalList))
  10524. {
  10525. // Required data
  10526. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10527. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10528. // Optional data
  10529. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10530. {
  10531. //Check UpdateType
  10532. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10533. {
  10534. //Local list full update
  10535. DEBUG_INFO("Local list full update.\n");
  10536. OCPP_getListVerion();
  10537. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10538. {
  10539. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10540. goto end;
  10541. }
  10542. OCPP_cleanLocalList();
  10543. }
  10544. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10545. {
  10546. //Local list different update
  10547. DEBUG_INFO("Local list different update.\n");
  10548. OCPP_getListVerion();
  10549. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10550. {
  10551. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10552. goto end;
  10553. }
  10554. }
  10555. else
  10556. {
  10557. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10558. goto end;
  10559. }
  10560. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10561. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10562. {
  10563. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10564. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10565. {
  10566. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10567. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10568. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10569. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10570. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10571. }
  10572. // Add to db
  10573. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10574. {
  10575. //Local list full update
  10576. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10577. idx,
  10578. ShmOCPP16Data->SendLocalList.ListVersion,
  10579. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10580. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10581. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10582. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10583. // update list
  10584. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10585. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10586. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10587. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10588. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10589. }
  10590. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10591. {
  10592. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10593. idx,
  10594. ShmOCPP16Data->SendLocalList.ListVersion,
  10595. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10596. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10597. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10598. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10599. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10600. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10601. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10602. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10603. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10604. }
  10605. }
  10606. }
  10607. else
  10608. {
  10609. //Check UpdateType
  10610. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10611. {
  10612. //Local list full update
  10613. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10614. OCPP_cleanLocalList();
  10615. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10616. goto end;
  10617. }
  10618. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10619. {
  10620. //Local list different update
  10621. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10622. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10623. goto end;
  10624. }
  10625. }
  10626. result = PASS;
  10627. }
  10628. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10629. end:
  10630. json_object_put(SendLocalList);
  10631. sendSendLocalListConfirmation(uuid, comfirmstr);
  10632. return result;
  10633. }
  10634. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10635. {
  10636. mtrace();
  10637. int result = FAIL;
  10638. struct StructSetChargingProfile SetProfileReq = {0};
  10639. int tempchargingProfileIdInt;
  10640. int chargingSchedulePeriodCount = 0;
  10641. char comfirmstr[20]={0};
  10642. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10643. char rmFileCmd[128]={0};
  10644. int profileQuantity = 0;
  10645. json_object *SetChargingProfile;
  10646. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10647. SetChargingProfile = json_tokener_parse(payload);
  10648. if(!is_error(SetChargingProfile))
  10649. {
  10650. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10651. {
  10652. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10653. }
  10654. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10655. {
  10656. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10657. {
  10658. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10659. }
  10660. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10661. {
  10662. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10663. }
  10664. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10665. {
  10666. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10667. }
  10668. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10669. {
  10670. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10671. }
  10672. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10673. {
  10674. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10675. }
  10676. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10677. {
  10678. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10679. }
  10680. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10681. {
  10682. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10683. }
  10684. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10685. {
  10686. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10687. }
  10688. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10689. {
  10690. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10691. {
  10692. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10693. }
  10694. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10695. {
  10696. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10697. }
  10698. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10699. {
  10700. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10701. }
  10702. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10703. {
  10704. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10705. }
  10706. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10707. {
  10708. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10709. if(chargingSchedulePeriodCount <= 10)
  10710. {
  10711. 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++)
  10712. {
  10713. 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)
  10714. {
  10715. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10716. }
  10717. 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)
  10718. {
  10719. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10720. }
  10721. 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)
  10722. {
  10723. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10724. }
  10725. }
  10726. }
  10727. }
  10728. }
  10729. }
  10730. }
  10731. // Profile periods quantity check
  10732. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10733. {
  10734. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10735. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10736. goto end;
  10737. }
  10738. // Profile purpose info check
  10739. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10740. {
  10741. FILE *fp;
  10742. char dataLine[4096]={0};
  10743. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10744. if(SetProfileReq.ConnectorId != 0)
  10745. {
  10746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10747. DEBUG_WARN("Profile connector id is not 0.\n");
  10748. goto end;
  10749. }
  10750. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10751. if (!fp)
  10752. {
  10753. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10754. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10755. }
  10756. else
  10757. {
  10758. while(fscanf(fp, "%s", dataLine) != EOF)
  10759. {
  10760. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10761. {
  10762. profileQuantity += 1;
  10763. }
  10764. }
  10765. }
  10766. fclose(fp);
  10767. }
  10768. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10769. {
  10770. FILE *fp;
  10771. char dataLine[4096]={0};
  10772. char filename[128]={0};
  10773. int tmpProfileQuantity;
  10774. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10775. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10776. {
  10777. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10778. DEBUG_WARN("Profile connector id is over max gun number.\n");
  10779. goto end;
  10780. }
  10781. if(SetProfileReq.ConnectorId == 0)
  10782. {
  10783. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10784. {
  10785. tmpProfileQuantity = 0;
  10786. memset(filename, 0, ARRAY_SIZE(filename));
  10787. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10788. fp = fopen(filename, "r");
  10789. if (!fp)
  10790. {
  10791. DEBUG_INFO("%s does not create.\n", filename);
  10792. fp = fopen(filename, "w+");
  10793. }
  10794. else
  10795. {
  10796. while(fscanf(fp, "%s", dataLine) != EOF)
  10797. {
  10798. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10799. {
  10800. tmpProfileQuantity += 1;
  10801. }
  10802. }
  10803. }
  10804. fclose(fp);
  10805. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10806. }
  10807. }
  10808. else
  10809. {
  10810. memset(filename, 0, ARRAY_SIZE(filename));
  10811. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10812. fp = fopen(filename, "r");
  10813. if (!fp)
  10814. {
  10815. DEBUG_INFO("%s does not create.\n", filename);
  10816. fp = fopen(filename, "w+");
  10817. }
  10818. else
  10819. {
  10820. while(fscanf(fp, "%s", dataLine) != EOF)
  10821. {
  10822. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10823. {
  10824. profileQuantity += 1;
  10825. }
  10826. }
  10827. }
  10828. fclose(fp);
  10829. }
  10830. }
  10831. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10832. {
  10833. int isMatchTransactiodId= FALSE;
  10834. FILE *fp;
  10835. char dataLine[4096]={0};
  10836. char filename[128]={0};
  10837. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10838. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10839. if(SetProfileReq.ConnectorId == 0)
  10840. {
  10841. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10842. DEBUG_WARN("Profile connector id is 0.\n");
  10843. goto end;
  10844. }
  10845. int tempIndex = 0;
  10846. //check Transaction active
  10847. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10848. {
  10849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10850. {
  10851. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10852. }
  10853. else
  10854. {
  10855. tempIndex = SetProfileReq.ConnectorId -1;
  10856. }
  10857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10858. {
  10859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10860. {
  10861. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10862. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10863. {
  10864. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10865. {
  10866. isMatchTransactiodId = TRUE;
  10867. break;
  10868. }
  10869. }
  10870. }
  10871. }
  10872. }
  10873. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10874. {
  10875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10876. {
  10877. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10878. }
  10879. else
  10880. {
  10881. tempIndex = SetProfileReq.ConnectorId -1;
  10882. }
  10883. for (int index = 0; index < CCS_QUANTITY; index++)
  10884. {
  10885. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10886. {
  10887. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10888. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10889. {
  10890. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10891. {
  10892. isMatchTransactiodId = TRUE;
  10893. break;
  10894. }
  10895. }
  10896. }
  10897. }
  10898. }
  10899. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10900. {
  10901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10902. {
  10903. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10904. }
  10905. else
  10906. {
  10907. tempIndex = SetProfileReq.ConnectorId -1;
  10908. }
  10909. for (int index = 0; index < GB_QUANTITY; index++)
  10910. {
  10911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10912. {
  10913. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10914. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10915. {
  10916. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10917. {
  10918. isMatchTransactiodId = TRUE;
  10919. break;
  10920. }
  10921. }
  10922. }
  10923. }
  10924. }
  10925. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10926. {
  10927. tempIndex = SetProfileReq.ConnectorId -1;
  10928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10929. {
  10930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10931. {
  10932. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10933. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10934. {
  10935. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10936. {
  10937. isMatchTransactiodId = TRUE;
  10938. break;
  10939. }
  10940. }
  10941. }
  10942. }
  10943. }
  10944. else
  10945. {
  10946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10947. {
  10948. tempIndex = 2;
  10949. }
  10950. else
  10951. {
  10952. tempIndex = (SetProfileReq.ConnectorId -1);
  10953. }
  10954. for (int index = 0; index < AC_QUANTITY; index++)
  10955. {
  10956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10957. {
  10958. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10959. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10960. {
  10961. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10962. {
  10963. isMatchTransactiodId = TRUE;
  10964. break;
  10965. }
  10966. }
  10967. }
  10968. }
  10969. }
  10970. //check Transaction active
  10971. if(isMatchTransactiodId == FALSE)
  10972. {
  10973. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10974. DEBUG_WARN("Tx profile transaction id is not match.\n");
  10975. goto end;
  10976. }
  10977. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10978. {
  10979. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10980. DEBUG_WARN("Connector id is over max gun number.\n");
  10981. goto end;
  10982. }
  10983. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10984. fp = fopen(filename, "r");
  10985. if (!fp)
  10986. {
  10987. DEBUG_INFO("%s does not create.\n", filename);
  10988. fp = fopen(filename, "w+");
  10989. }
  10990. else
  10991. {
  10992. //Check Charging Profile Count
  10993. while(fscanf(fp, "%s", dataLine) != EOF)
  10994. {
  10995. //DEBUG_INFO("word=%s\n",word);
  10996. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10997. {
  10998. profileQuantity += 1;
  10999. }
  11000. }
  11001. }
  11002. fclose(fp);
  11003. }
  11004. // Check ChargeProfileMaxStackLevel
  11005. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11006. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11007. {
  11008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11009. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11010. goto end;
  11011. }
  11012. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11013. {
  11014. FILE *fp;
  11015. char dataLine[4096]={0};
  11016. char fnametemp[128]={0};
  11017. int tmpProfileQuantity;
  11018. //Check ChargePointMaxProfile.json exit
  11019. profileQuantity = 0;
  11020. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11021. {
  11022. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11023. //Check Charging Profile Count
  11024. tmpProfileQuantity = 0;
  11025. while(fscanf(fp, "%s", dataLine) != EOF)
  11026. {
  11027. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11028. {
  11029. profileQuantity += 1;
  11030. tmpProfileQuantity += 1;
  11031. }
  11032. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11033. }
  11034. fclose(fp);
  11035. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11036. }
  11037. //Check TxDefaultProfile_%d.json
  11038. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11039. {
  11040. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11041. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11042. if((access(fnametemp,F_OK))!=-1)
  11043. {
  11044. fp = fopen(fnametemp, "r");
  11045. //Check Charging Profile Count
  11046. tmpProfileQuantity = 0;
  11047. while(fscanf(fp, "%s", dataLine) != EOF)
  11048. {
  11049. //DEBUG_INFO("word=%s\n",word);
  11050. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11051. {
  11052. profileQuantity += 1;
  11053. tmpProfileQuantity += 1;
  11054. }
  11055. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11056. }
  11057. fclose(fp);
  11058. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11059. }
  11060. }
  11061. //Check TxProfile_%d.json
  11062. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11063. {
  11064. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11065. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11066. if((access(fnametemp,F_OK))!=-1)
  11067. {
  11068. fp = fopen(fnametemp, "r");
  11069. //Check Charging Profile Count
  11070. tmpProfileQuantity = 0;
  11071. while(fscanf(fp, "%s", dataLine) != EOF)
  11072. {
  11073. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11074. {
  11075. profileQuantity += 1;
  11076. tmpProfileQuantity += 1;
  11077. }
  11078. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11079. }
  11080. fclose(fp);
  11081. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11082. }
  11083. }
  11084. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11085. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11086. {
  11087. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11088. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11089. goto end;
  11090. }
  11091. }
  11092. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11093. //**********************************Write to File********************************************************/
  11094. {
  11095. FILE *infile;
  11096. FILE *outfile;
  11097. char dataLine[4096]={0};
  11098. char filename[128]={0};
  11099. int chkChar=0;
  11100. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11101. {
  11102. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11103. {
  11104. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11105. }
  11106. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11107. {
  11108. if(SetProfileReq.ConnectorId==0)
  11109. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11110. else
  11111. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11112. }
  11113. else
  11114. {
  11115. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11116. }
  11117. infile = fopen (filename, "r");
  11118. outfile = fopen (tempfile, "w");
  11119. chkChar = fgetc(infile);
  11120. rewind(infile);
  11121. if(chkChar == EOF)
  11122. {
  11123. // Profile is empty
  11124. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11125. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11126. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11127. fclose(infile);
  11128. fclose(outfile);
  11129. sprintf(rmFileCmd,"rm -f %s",filename);
  11130. system(rmFileCmd);
  11131. rename(tempfile, filename);
  11132. }
  11133. else
  11134. {
  11135. // Profile is not empty
  11136. int ChargingProfileAdded = FALSE;
  11137. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11138. {
  11139. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11140. json_object *tmpChargingProfile;
  11141. tmpChargingProfile = json_tokener_parse(dataLine);
  11142. if(!is_error(SetChargingProfile))
  11143. {
  11144. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11145. {
  11146. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11147. {
  11148. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11149. }
  11150. }
  11151. }
  11152. json_object_put(tmpChargingProfile);
  11153. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11154. {
  11155. if(ChargingProfileAdded == FALSE)
  11156. {
  11157. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11158. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11159. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11160. ChargingProfileAdded = TRUE;
  11161. }
  11162. }
  11163. else
  11164. {
  11165. fprintf(outfile,"%s\n",dataLine);
  11166. if(ChargingProfileAdded == FALSE)
  11167. {
  11168. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11169. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11170. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11171. ChargingProfileAdded = TRUE;
  11172. }
  11173. }
  11174. } // end of while loop
  11175. fclose(infile);
  11176. fclose(outfile);
  11177. sprintf(rmFileCmd,"rm -f %s",filename);
  11178. system(rmFileCmd);
  11179. rename(tempfile, filename);
  11180. }
  11181. }
  11182. sleep(1);
  11183. result = TRUE;
  11184. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11185. }
  11186. end:
  11187. json_object_put(SetChargingProfile);
  11188. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11189. {
  11190. if(SetProfileReq.ConnectorId == 0)
  11191. {
  11192. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11193. {
  11194. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11195. }
  11196. }
  11197. else
  11198. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11199. }
  11200. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11201. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11202. return result;
  11203. }
  11204. int handleTriggerMessageRequest(char *uuid, char *payload)
  11205. {
  11206. mtrace();
  11207. int result = FAIL;
  11208. int connectorIdIsNULL = FALSE;
  11209. int connectorIdInt =0;
  11210. char sstr[40]={0},sstrtemp[100]={ 0 };
  11211. char requestedMessagestr[40]={0};
  11212. char comfirmstr[20]={0};
  11213. int c = 0;
  11214. char *loc;
  11215. DEBUG_INFO("handleTriggerMessageRequest\n");
  11216. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11217. strcpy(sstrtemp, stringtrimspace(payload));
  11218. c = 0;
  11219. loc = strstr(sstrtemp, "requestedMessage");
  11220. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11221. {
  11222. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11223. c++;
  11224. }
  11225. sstr[c] = '\0';
  11226. strcpy(requestedMessagestr, sstr);
  11227. c = 0;
  11228. loc = strstr(sstrtemp, "connectorId");
  11229. if(loc == NULL)
  11230. {
  11231. connectorIdIsNULL = TRUE;
  11232. }
  11233. else
  11234. {
  11235. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11236. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11237. {
  11238. sstr[c] = loc[strlen("connectorId")+2+c];
  11239. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11240. c++;
  11241. }
  11242. sstr[c] = '\0';
  11243. connectorIdInt = atoi(sstr);
  11244. }
  11245. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11246. {
  11247. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11248. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11249. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11250. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11251. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11252. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11253. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11254. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11255. {
  11256. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11257. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11258. return TRUE;
  11259. }
  11260. else
  11261. {
  11262. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11263. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11264. }
  11265. }
  11266. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11267. {
  11268. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11269. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11270. return TRUE;
  11271. }
  11272. //==========================
  11273. // Trigger message
  11274. //==========================
  11275. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11276. {
  11277. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11278. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11279. {
  11280. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11281. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11282. }
  11283. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11284. }
  11285. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11286. {
  11287. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11288. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11289. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11290. }
  11291. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11292. {
  11293. //sendBootNotificationRequest();
  11294. server_sign = FALSE;
  11295. }
  11296. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11297. {
  11298. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11299. }
  11300. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11301. {
  11302. if(connectorIdIsNULL == FALSE)
  11303. {
  11304. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11305. {
  11306. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11307. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11308. }
  11309. }
  11310. else
  11311. {
  11312. for(int idx=0;idx< gunTotalNumber;idx++)
  11313. {
  11314. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11315. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11316. }
  11317. }
  11318. }
  11319. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11320. {
  11321. if(connectorIdIsNULL == FALSE)
  11322. {
  11323. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11324. {
  11325. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11326. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11327. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11328. }
  11329. }
  11330. else
  11331. {
  11332. for(int idx=0;idx< gunTotalNumber;idx++)
  11333. {
  11334. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11335. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11336. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11337. }
  11338. }
  11339. }
  11340. return result;
  11341. }
  11342. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11343. {
  11344. mtrace();
  11345. int result = FAIL;
  11346. int connectorIdInt =0;
  11347. char comfirmstr[20]={0};
  11348. int tempIndex = 0;
  11349. json_object *UnlockConnector;
  11350. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11351. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11352. UnlockConnector = json_tokener_parse(payload);
  11353. if(!is_error(UnlockConnector))
  11354. {
  11355. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11356. {
  11357. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11358. }
  11359. }
  11360. json_object_put(UnlockConnector);
  11361. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11362. if(gunTotalNumber == 0)
  11363. {
  11364. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11365. goto end;
  11366. }
  11367. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11368. {
  11369. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11370. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11371. goto end;
  11372. }
  11373. else
  11374. {
  11375. //check Transaction active
  11376. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11377. {
  11378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11379. {
  11380. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11381. }
  11382. else
  11383. {
  11384. tempIndex = connectorIdInt -1;
  11385. }
  11386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11387. {
  11388. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11389. {
  11390. //stop Transaction
  11391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11392. }
  11393. }
  11394. }
  11395. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11396. {
  11397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11398. {
  11399. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11400. }
  11401. else
  11402. {
  11403. tempIndex = connectorIdInt -1;
  11404. }
  11405. for (int index = 0; index < CCS_QUANTITY; index++)
  11406. {
  11407. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11408. {
  11409. //stop Transaction
  11410. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11411. }
  11412. }
  11413. }
  11414. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11415. {
  11416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11417. {
  11418. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11419. }
  11420. else
  11421. {
  11422. tempIndex = connectorIdInt -1;
  11423. }
  11424. for (int index = 0; index < GB_QUANTITY; index++)
  11425. {
  11426. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11427. {
  11428. //stop Transaction
  11429. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11430. }
  11431. }
  11432. }
  11433. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11434. {
  11435. tempIndex = connectorIdInt -1;
  11436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11437. {
  11438. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11439. {
  11440. //stop Transaction
  11441. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11442. }
  11443. }
  11444. }
  11445. else
  11446. {
  11447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11448. {
  11449. tempIndex = 2;
  11450. }
  11451. else
  11452. {
  11453. tempIndex = connectorIdInt-1;
  11454. }
  11455. for (int index = 0; index < AC_QUANTITY; index++)
  11456. {
  11457. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11458. {
  11459. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11460. }
  11461. }
  11462. }
  11463. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11464. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11465. result = TRUE;
  11466. return result;
  11467. }
  11468. end:
  11469. //json_object_put(obj); --- remove temporally
  11470. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11471. return result;
  11472. }
  11473. static char UpdateFirmwarepayloadData[300]={0};
  11474. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11475. {
  11476. mtrace();
  11477. int result = FAIL;
  11478. pthread_t t;
  11479. sendUpdateFirmwareConfirmation(uuid);
  11480. memset(UpdateFirmwarepayloadData, 0, 300);
  11481. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11482. if(!interLock.isUpdateFirmwareGoing)
  11483. {
  11484. interLock.isUpdateFirmwareGoing = 1;
  11485. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11486. sleep(1);
  11487. }
  11488. else
  11489. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11490. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11491. return result;
  11492. }
  11493. void *UpdateFirmwareProcess(void *data)
  11494. {
  11495. pthread_detach(pthread_self());
  11496. mtrace();
  11497. int retriesInt =0, retryIntervalInt=0;
  11498. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11499. int port=0;
  11500. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11501. int isSuccess = 0;
  11502. char ftpbuf[1024];
  11503. char temp[1024];
  11504. char * pch;
  11505. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11506. json_object *UpdateFirmware;
  11507. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11508. if(!is_error(UpdateFirmware))
  11509. {
  11510. // Required data
  11511. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11512. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11513. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11514. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11515. // Optional data
  11516. if(json_object_object_get(UpdateFirmware, "retries"))
  11517. {
  11518. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11519. }
  11520. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11521. {
  11522. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11523. }
  11524. }
  11525. json_object_put(UpdateFirmware);
  11526. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11527. memset(path, 0, ARRAY_SIZE(path));
  11528. // Wait retrieveData
  11529. if(strlen(retrieveDatestr) > 10)
  11530. {
  11531. do
  11532. {
  11533. sleep(1);
  11534. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11535. }
  11536. // Ready to download
  11537. system("rm -f /mnt/*");
  11538. if(strncmp(locationstr,"http", 4) == 0)
  11539. {
  11540. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11541. sprintf(ftppath,"/%s", path);
  11542. DEBUG_INFO("locationstr: %s\n", locationstr);
  11543. DEBUG_INFO("protocol: %s\n",protocol);
  11544. DEBUG_INFO("host: %s\n",host);
  11545. DEBUG_INFO("path: %s\n",path);
  11546. DEBUG_INFO("ftppath: %s\n",ftppath);
  11547. int ftppathlen=strlen(ftppath);
  11548. int i=1;
  11549. char filenametemp[50];
  11550. while(i < ftppathlen)
  11551. {
  11552. int len=ftppathlen-i;
  11553. if(ftppath[len]== 47) // '/' ascll code: 47
  11554. {
  11555. DEBUG_INFO("compare '/' all right\n");
  11556. break;
  11557. }
  11558. i=i+1;
  11559. }
  11560. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11561. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11562. filenametemp[i+1] = 0;
  11563. do
  11564. {
  11565. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11566. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11567. sleep(1);
  11568. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11569. if(!isSuccess)
  11570. {
  11571. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11572. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11573. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11574. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11575. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11576. }
  11577. else
  11578. {
  11579. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11580. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11581. }
  11582. retriesInt--;
  11583. }while((isSuccess == 0)&&(retriesInt >= 0));
  11584. }
  11585. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11586. {
  11587. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11588. memset(temp, 0, ARRAY_SIZE(temp));
  11589. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11590. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11591. int ftppathlen=strlen(ftpbuf);
  11592. int i=1;
  11593. char filenametemp[50];
  11594. while(i < ftppathlen)
  11595. {
  11596. int len=ftppathlen-i;
  11597. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11598. {
  11599. DEBUG_INFO(" compare '/' all right\n");
  11600. break;
  11601. }
  11602. i=i+1;
  11603. }
  11604. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11605. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11606. filenametemp[i+1] = 0;
  11607. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11608. pch=strchr(temp,'@');
  11609. if(pch==NULL)
  11610. {
  11611. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11612. protocol, host, &port, path);
  11613. strcpy(user,"anonymous");
  11614. strcpy(password,"");
  11615. }
  11616. else
  11617. {
  11618. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11619. protocol, user, password, host, &port, path);
  11620. }
  11621. sscanf(host,"%[^/]%s",host1, path1);
  11622. sprintf(ftppath,"%s", path1);
  11623. //DEBUG_INFO("protocol =%s\n",protocol);
  11624. //DEBUG_INFO("user =%s\n",user);
  11625. //DEBUG_INFO("password =%s\n",password);
  11626. //DEBUG_INFO("host1 =%s\n",host1);
  11627. //DEBUG_INFO("port =%d\n",port);
  11628. //DEBUG_INFO("path1 =%s\n",path1);
  11629. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11630. //ftpFile(host, user, password, port, ftppath, fname);
  11631. //download firmware pthred
  11632. if(port == 0)
  11633. {
  11634. port = 21;
  11635. }
  11636. do
  11637. {
  11638. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11639. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11640. sleep(1);
  11641. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11642. if(!isSuccess)
  11643. {
  11644. //BulldogUtil.sleepMs(interval*1000);
  11645. DEBUG_INFO("Update firmware request and download file fail.\n");
  11646. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11647. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11648. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11649. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11650. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11651. }
  11652. else
  11653. {
  11654. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11655. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11656. }
  11657. retriesInt--;
  11658. }while((!isSuccess)&&(retriesInt >= 0));
  11659. }
  11660. else
  11661. {
  11662. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11663. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11664. sleep(1);
  11665. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11666. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11667. }
  11668. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11669. interLock.isUpdateFirmwareGoing = 0;
  11670. pthread_exit(NULL);
  11671. }
  11672. int handleCertificateSignedRequest(char *uuid, char *payload)
  11673. {
  11674. mtrace();
  11675. int result = PASS;
  11676. json_object *CertificateSigned;
  11677. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11678. CertificateSigned = json_tokener_parse(payload);
  11679. if(!is_error(CertificateSigned))
  11680. {
  11681. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11682. }
  11683. json_object_put(CertificateSigned);
  11684. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11685. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11686. fclose(fp);
  11687. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11688. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11689. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11690. sendCertificateSignedConfirmation(uuid);
  11691. return result;
  11692. }
  11693. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11694. {
  11695. mtrace();
  11696. int result = PASS;
  11697. json_object *DeleteCertificate;
  11698. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11699. DeleteCertificate = json_tokener_parse(payload);
  11700. if(!is_error(DeleteCertificate))
  11701. {
  11702. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11703. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11704. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11705. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11706. }
  11707. json_object_put(DeleteCertificate);
  11708. /*
  11709. * TODO: Delete certificateSigned process
  11710. */
  11711. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11712. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11713. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11714. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11715. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11716. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11717. sendDeleteCertificateConfirmation(uuid);
  11718. return result;
  11719. }
  11720. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11721. {
  11722. mtrace();
  11723. int result = PASS;
  11724. json_object *ExtendedTriggerMessage;
  11725. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11726. ExtendedTriggerMessage = json_tokener_parse(payload);
  11727. if(!is_error(ExtendedTriggerMessage))
  11728. {
  11729. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11730. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11731. {
  11732. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11733. }
  11734. else
  11735. {
  11736. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11737. }
  11738. }
  11739. json_object_put(ExtendedTriggerMessage);
  11740. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11741. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11742. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11743. {
  11744. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11745. }
  11746. else
  11747. {
  11748. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11749. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11750. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11751. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11752. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11753. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11754. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11755. {
  11756. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11757. }
  11758. else
  11759. {
  11760. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11761. }
  11762. }
  11763. sendExtendedTriggerMessageConfirmation(uuid);
  11764. //==========================
  11765. // Trigger message
  11766. //==========================
  11767. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11768. {
  11769. //sendBootNotificationRequest();
  11770. server_sign = FALSE;
  11771. }
  11772. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11773. {
  11774. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11775. }
  11776. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11777. {
  11778. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11779. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11780. {
  11781. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11782. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11783. }
  11784. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11785. }
  11786. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11787. {
  11788. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11789. }
  11790. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11791. {
  11792. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11793. {
  11794. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11795. }
  11796. else
  11797. {
  11798. for(int idx=0;idx< gunTotalNumber;idx++)
  11799. {
  11800. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11801. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11802. }
  11803. }
  11804. }
  11805. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11806. {
  11807. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11808. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11809. {
  11810. 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\" &");
  11811. }
  11812. }
  11813. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11814. {
  11815. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11816. {
  11817. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11818. }
  11819. else
  11820. {
  11821. for(int idx=0;idx< gunTotalNumber;idx++)
  11822. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11823. }
  11824. }
  11825. return result;
  11826. }
  11827. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11828. {
  11829. mtrace();
  11830. int result = PASS;
  11831. json_object *GetInstalledCertificateIds;
  11832. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11833. GetInstalledCertificateIds = json_tokener_parse(payload);
  11834. if(!is_error(GetInstalledCertificateIds))
  11835. {
  11836. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11837. }
  11838. json_object_put(GetInstalledCertificateIds);
  11839. /*
  11840. * TODO: Return installed certificate process
  11841. */
  11842. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11843. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11844. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11845. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11846. sendGetInstalledCertificateIdsConfirmation(uuid);
  11847. return result;
  11848. }
  11849. int handleGetLogRequest(char *uuid, char *payload)
  11850. {
  11851. mtrace();
  11852. int result = PASS;
  11853. json_object *GetLog;
  11854. DEBUG_INFO("handleGetLogRequest...\n");
  11855. GetLog = json_tokener_parse(payload);
  11856. if(!is_error(GetLog))
  11857. {
  11858. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11859. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11860. if(json_object_object_get(GetLog, "retries") != NULL)
  11861. {
  11862. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11863. }
  11864. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11865. {
  11866. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11867. }
  11868. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11869. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11870. {
  11871. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11872. }
  11873. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11874. {
  11875. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11876. }
  11877. }
  11878. json_object_put(GetLog);
  11879. /*
  11880. * TODO: Upload log process
  11881. */
  11882. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11883. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11884. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11885. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11886. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11887. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11888. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11889. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11890. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11891. sendGetLogConfirmation(uuid);
  11892. return result;
  11893. }
  11894. int handleInstallCertificateRequest(char *uuid, char *payload)
  11895. {
  11896. mtrace();
  11897. int result = PASS;
  11898. json_object *InstallCertificate;
  11899. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11900. InstallCertificate = json_tokener_parse(payload);
  11901. if(!is_error(InstallCertificate))
  11902. {
  11903. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11904. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11905. /*
  11906. * TODO: Install certificate process
  11907. */
  11908. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11909. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11910. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11911. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11912. sendInstallCertificateConfirmation(uuid);
  11913. }
  11914. json_object_put(InstallCertificate);
  11915. return result;
  11916. }
  11917. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11918. {
  11919. mtrace();
  11920. int result = PASS;
  11921. json_object *SignedUpdateFirmware;
  11922. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11923. SignedUpdateFirmware = json_tokener_parse(payload);
  11924. if(!is_error(SignedUpdateFirmware))
  11925. {
  11926. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11927. {
  11928. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11929. }
  11930. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11931. {
  11932. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11933. }
  11934. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11935. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11936. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11937. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11938. {
  11939. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11940. }
  11941. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11942. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11943. }
  11944. json_object_put(SignedUpdateFirmware);
  11945. /*
  11946. * TODO: Upgrade firmware process
  11947. */
  11948. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11949. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11950. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11951. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11952. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11953. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11954. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11955. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11956. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11957. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11958. sendInstallCertificateConfirmation(uuid);
  11959. return result;
  11960. }
  11961. int handleUnknownRequest(char *uuid, char *payload)
  11962. {
  11963. mtrace();
  11964. int result = PASS;
  11965. DEBUG_INFO("handleUnknownRequest...\n");
  11966. sendUnknownConfirmation(uuid);
  11967. result = PASS;
  11968. return result;
  11969. }
  11970. //==========================================
  11971. // Handle server response routine
  11972. //==========================================
  11973. void handleAuthorizeResponse(char *payload, int gun_index)
  11974. {
  11975. mtrace();
  11976. char expiryDatestr[30]={0};
  11977. char parentIdTagstr[20]={0};
  11978. char statusstr[20]={0};
  11979. int expiryDateISNULL=FALSE;
  11980. int parentIdTagISNULL=FALSE;
  11981. DEBUG_INFO("handleAuthorizeResponse...\n");
  11982. json_object *Authorize;
  11983. Authorize = json_tokener_parse(payload);
  11984. if(!is_error(Authorize))
  11985. {
  11986. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11987. {
  11988. // Required data
  11989. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11990. // Optional data
  11991. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11992. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11993. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11994. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11995. }
  11996. }
  11997. json_object_put(Authorize);
  11998. if(expiryDateISNULL == FALSE)
  11999. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12000. if(parentIdTagISNULL == FALSE)
  12001. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12002. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12003. //Update idTag information to authorization cache if supproted
  12004. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12005. {
  12006. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12007. }
  12008. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12009. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12010. authorizeRetryTimes = 0;
  12011. }
  12012. void handleBootNotificationResponse(char *payload, int gun_index)
  12013. {
  12014. mtrace();
  12015. char statusStr[12]={0};
  12016. char currentTimeStr[30]={0};
  12017. int intervalInt = 0;
  12018. DEBUG_INFO("handleBootNotificationResponse...\n");
  12019. json_object *BootNotification;
  12020. BootNotification = json_tokener_parse(payload);
  12021. if(!is_error(BootNotification))
  12022. {
  12023. // Required data
  12024. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12025. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12026. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12027. }
  12028. json_object_put(BootNotification);
  12029. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12030. BootNotificationInterval = intervalInt;
  12031. HeartBeatWaitTime = intervalInt;
  12032. //write back to ShmOCPP16Data->BootNotification
  12033. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12034. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12035. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12036. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12037. {
  12038. server_sign = TRUE;
  12039. server_pending =FALSE;
  12040. }
  12041. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12042. {
  12043. server_pending = TRUE;
  12044. }
  12045. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12046. srand(time(NULL));
  12047. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12048. SetOcppConnStatus(TRUE);
  12049. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12050. }
  12051. void handleDataTransferResponse(char *payload, int gun_index)
  12052. {
  12053. char sstr[160]={0};//sstr[200]={ 0 };
  12054. int c = 0;
  12055. char *loc;
  12056. DEBUG_INFO("handleDataTransferResponse ...\n");
  12057. loc = strstr(payload, "status");
  12058. c = 0;
  12059. while (loc[3+strlen("status")+c] != '\"')
  12060. {
  12061. sstr[c] = loc[3+strlen("status")+c];
  12062. c++;
  12063. }
  12064. sstr[c] = '\0';
  12065. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12066. }
  12067. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12068. {
  12069. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12070. //struct json_object *obj;
  12071. // obj = json_tokener_parse(payload);
  12072. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12073. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12074. //No fields are defined.
  12075. }
  12076. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12077. {
  12078. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12079. //struct json_object *obj;
  12080. // obj = json_tokener_parse(payload);
  12081. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12082. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12083. //No fields are defined.
  12084. }
  12085. void handleHeartbeatResponse(char *payload, int gun_index)
  12086. {
  12087. mtrace();
  12088. DEBUG_INFO("handleHeartbeatResponse...\n");
  12089. json_object *Heartbeat;
  12090. Heartbeat = json_tokener_parse(payload);
  12091. if(!is_error(Heartbeat))
  12092. {
  12093. // Required data
  12094. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12095. }
  12096. json_object_put(Heartbeat);
  12097. if(FirstHeartBeat == 0)
  12098. {
  12099. FirstHeartBeat = 1;
  12100. DEBUG_INFO("FirstHeartBeat \n");
  12101. }
  12102. HeartBeatWithNOResponse = 0;
  12103. clientTime.Heartbeat=time((time_t*)NULL);
  12104. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12105. }
  12106. void handleMeterValuesResponse(char *payload, int gun_index)
  12107. {
  12108. mtrace();
  12109. DEBUG_INFO("handleMeterValuesResponse...\n");
  12110. }
  12111. void handleStartTransactionResponse(char *payload, int gun_index)
  12112. {
  12113. mtrace();
  12114. //int transactionIdInt = 0;
  12115. FILE *outfile;
  12116. char data[100]={0};
  12117. DEBUG_INFO("handleStartTransactionResponse...\n");
  12118. json_object *StartTransaction;
  12119. StartTransaction = json_tokener_parse(payload);
  12120. if(!is_error(StartTransaction))
  12121. {
  12122. // Required data
  12123. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12124. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12125. // Optional data
  12126. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12127. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12128. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12129. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12130. }
  12131. json_object_put(StartTransaction);
  12132. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12133. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12134. //-----------Start : write to the Queue TransactionId file -----------------//
  12135. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12136. {}
  12137. else
  12138. {
  12139. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12140. if(log == NULL)
  12141. {
  12142. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12143. return ;
  12144. }
  12145. else
  12146. {
  12147. fclose(log);
  12148. }
  12149. }
  12150. // open file for writing
  12151. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12152. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12153. {
  12154. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12155. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12156. fputs(data, outfile);
  12157. fclose (outfile);
  12158. }
  12159. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12160. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12161. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12162. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12163. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12164. }
  12165. void handleStatusNotificationResponse(char *payload, int gun_index)
  12166. {
  12167. mtrace();
  12168. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12169. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12170. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12171. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12172. }
  12173. void handleStopTransactionnResponse(char *payload, int gun_index)
  12174. {
  12175. mtrace();
  12176. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12177. json_object *StopTransaction;
  12178. StopTransaction = json_tokener_parse(payload);
  12179. if(!is_error(StopTransaction))
  12180. {
  12181. // Optional data
  12182. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12183. {
  12184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12185. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12187. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12189. }
  12190. }
  12191. json_object_put(StopTransaction);
  12192. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12193. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12194. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12195. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12196. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12197. }
  12198. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12199. {
  12200. mtrace();
  12201. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12202. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12203. }
  12204. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12205. {
  12206. mtrace();
  12207. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12208. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12209. }
  12210. void handleSignCertificateResponse(char *payload, int gun_index)
  12211. {
  12212. mtrace();
  12213. DEBUG_INFO("handleSignCertificateResponse...\n");
  12214. json_object *SignCertificate;
  12215. SignCertificate = json_tokener_parse(payload);
  12216. if(!is_error(SignCertificate))
  12217. {
  12218. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12219. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12220. }
  12221. json_object_put(SignCertificate);
  12222. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12223. }
  12224. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12225. {
  12226. mtrace();
  12227. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12228. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12229. }
  12230. //==========================================
  12231. // Handle Error routine
  12232. //==========================================
  12233. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12234. {
  12235. mtrace();
  12236. #ifdef SystemLogMessage
  12237. DEBUG_INFO("errorCode: %s\n", errorCode);
  12238. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12239. DEBUG_INFO("errorDetails: %s\n", payload);
  12240. #endif
  12241. }
  12242. //===============================================
  12243. // Common routine
  12244. //===============================================
  12245. int initialConfigurationTable(void)
  12246. {
  12247. //clock_t start_t, end_t, total_t;
  12248. FILE *fp;
  12249. FILE *outfile;
  12250. char str[512]={0};
  12251. char sstr[256]={0};
  12252. int c = 0;
  12253. char *loc;
  12254. int confVersion = 8;
  12255. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12256. //start_t = clock();
  12257. //printf("Starting of the program, start_t = %ld\n", start_t);
  12258. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12259. // Check configuration file size is correct
  12260. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12261. {
  12262. struct stat st;
  12263. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12264. if(st.st_size < 3100)
  12265. {
  12266. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12267. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12268. }
  12269. }
  12270. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12271. {
  12272. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12273. if(outfile == NULL)
  12274. {
  12275. DEBUG_INFO("Error opening file\n");
  12276. return FALSE;
  12277. }
  12278. /*Core Profile*/
  12279. //AllowOfflineTxForUnknownId
  12280. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12284. //AuthorizationCacheEnabled
  12285. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12289. //AuthorizeRemoteTxRequests
  12290. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12294. //BlinkRepeat
  12295. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12299. //ClockAlignedDataInterval
  12300. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12304. //ConnectionTimeOut
  12305. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12309. //GetConfigurationMaxKeys
  12310. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12314. // HeartbeatInterval
  12315. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12319. // LightIntensity
  12320. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12324. // LocalAuthorizeOffline
  12325. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12329. // LocalPreAuthorize
  12330. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12334. // MaxEnergyOnInvalidId
  12335. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12339. // MeterValuesAlignedData
  12340. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12342. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12344. else
  12345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12347. // MeterValuesAlignedDataMaxLength
  12348. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12352. else
  12353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12355. // MeterValuesSampledData
  12356. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12360. else
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12363. // MeterValuesSampledDataMaxLength
  12364. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12368. else
  12369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12371. // MeterValueSampleInterval
  12372. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12376. // MinimumStatusDuration
  12377. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12380. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12382. // NumberOfConnectors
  12383. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12386. {
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12388. }
  12389. else
  12390. {
  12391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12392. }
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12394. // ResetRetries
  12395. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12399. // ConnectorPhaseRotation
  12400. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12404. // ConnectorPhaseRotationMaxLength
  12405. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12409. // StopTransactionOnEVSideDisconnect
  12410. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12414. // StopTransactionOnInvalidId
  12415. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12419. // StopTxnAlignedData
  12420. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12424. // StopTxnAlignedDataMaxLength
  12425. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12429. // StopTxnSampledData
  12430. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12434. else
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12437. // StopTxnSampledDataMaxLength
  12438. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12441. {
  12442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12443. }
  12444. else
  12445. {
  12446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12447. }
  12448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12449. // SupportedFeatureProfiles
  12450. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12454. // SupportedFeatureProfilesMaxLength
  12455. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12459. // TransactionMessageAttempts
  12460. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12463. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12465. // TransactionMessageRetryInterval
  12466. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12469. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12471. // UnlockConnectorOnEVSideDisconnect
  12472. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12476. // WebSocketPingInterval
  12477. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12481. // QueueOffLineMeterValues
  12482. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12486. // AuthorizationKey
  12487. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12491. // SecurityProfile
  12492. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12496. // DefaultPrice
  12497. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12501. // CustomDisplayCostAndPrice
  12502. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12506. // CustomIdleFeeAfterStop
  12507. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12511. // TimeOffset
  12512. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12516. // NextTimeOffsetTransitionDateTime
  12517. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12521. // TimeOffsetNextTransition
  12522. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12526. // Configuration Version
  12527. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12531. //* Local Auth List Management Profile*/
  12532. #if 0
  12533. //For OCTT Test Case
  12534. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12537. #endif
  12538. #if 1
  12539. //LocalAuthListEnabled
  12540. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12544. #endif
  12545. //LocalAuthListMaxLength
  12546. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12550. //SendLocalListMaxLength
  12551. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12555. //ReserveConnectorZeroSupported
  12556. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12560. //* Smart Charging Profile */
  12561. //ChargeProfileMaxStackLevel
  12562. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12566. // ChargingScheduleAllowedChargingRateUnit
  12567. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12571. // ChargingScheduleMaxPeriods
  12572. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12576. // ConnectorSwitch3to1PhaseSupported
  12577. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12581. // MaxChargingProfilesInstalled
  12582. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12586. fclose(outfile);
  12587. }
  12588. else
  12589. {
  12590. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12591. char keystr[60]={0};
  12592. char readonlystr[10]={0};
  12593. char valuestr[256]={0};
  12594. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12595. if(fp == NULL) {
  12596. DEBUG_INFO("Error opening file");
  12597. return FALSE;
  12598. }
  12599. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12600. {
  12601. //DEBUG_INFO("Get Configuration \n");
  12602. if(strlen(str) > 0)
  12603. {
  12604. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12605. //*************************key*********************************/
  12606. if(strstr(str, "key") != NULL)
  12607. {
  12608. loc = strstr(str, "key");
  12609. c = 0;
  12610. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12611. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12612. {
  12613. sstr[c] = loc[strlen("key")+3+c];
  12614. c++;
  12615. }
  12616. sstr[c] = '\0';
  12617. strcpy(keystr,sstr);
  12618. }
  12619. //*************************readonly*********************************/
  12620. if(strstr(str, "readonly") != NULL)
  12621. {
  12622. loc = strstr(str, "readonly");
  12623. c = 0;
  12624. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12625. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12626. {
  12627. sstr[c] = loc[strlen("readonly")+2+c];
  12628. c++;
  12629. }
  12630. sstr[c] = '\0';
  12631. strcpy(readonlystr,sstr);
  12632. }
  12633. //*************************value*********************************/
  12634. if(strstr(str, "value") != NULL)
  12635. {
  12636. loc = strstr(str, "value");
  12637. c = 0;
  12638. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12639. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12640. {
  12641. sstr[c] = loc[strlen("value")+3+c];
  12642. c++;
  12643. }
  12644. sstr[c] = '\0';
  12645. strcpy(valuestr,sstr);
  12646. }
  12647. // DEBUG_INFO("keystr=%s\n",keystr);
  12648. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12649. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12650. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12651. {
  12652. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12653. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12655. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12656. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12657. }
  12658. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12659. {
  12660. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12661. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12663. }
  12664. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12665. {
  12666. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12668. }
  12669. if(strcmp(keystr, "BlinkRepeat") == 0)
  12670. {
  12671. //Charger.BlinkRepeat = Integer.parseInt(value);
  12672. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12674. }
  12675. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12676. {
  12677. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12679. }
  12680. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12681. {
  12682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12684. }
  12685. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12686. {
  12687. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12689. }
  12690. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12691. {
  12692. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12694. HeartBeatWaitTime = atoi(valuestr);
  12695. }
  12696. if(strcmp(keystr, "LightIntensity") == 0)
  12697. {
  12698. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12700. }
  12701. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12702. {
  12703. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12705. }
  12706. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12707. {
  12708. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12710. }
  12711. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12712. {
  12713. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12715. }
  12716. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12717. {
  12718. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12720. }
  12721. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12722. {
  12723. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12725. }
  12726. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12727. {
  12728. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12730. }
  12731. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12732. {
  12733. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12735. }
  12736. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12737. {
  12738. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12740. }
  12741. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12742. {
  12743. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12745. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12746. }
  12747. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12748. {
  12749. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12751. }
  12752. if(strcmp(keystr, "ResetRetries") == 0)
  12753. {
  12754. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12756. }
  12757. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12758. {
  12759. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12761. }
  12762. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12763. {
  12764. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12766. }
  12767. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12768. {
  12769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12771. }
  12772. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12773. {
  12774. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12776. }
  12777. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12778. {
  12779. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12781. }
  12782. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12783. {
  12784. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12786. }
  12787. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12788. {
  12789. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12791. }
  12792. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12793. {
  12794. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12796. }
  12797. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12798. {
  12799. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12801. }
  12802. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12803. {
  12804. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12806. }
  12807. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12808. {
  12809. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12811. TransactionMessageAttemptsValue = atoi(valuestr);
  12812. }
  12813. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12814. {
  12815. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12817. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12818. }
  12819. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12820. {
  12821. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12823. }
  12824. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12825. {
  12826. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12828. }
  12829. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12830. {
  12831. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12833. }
  12834. if(strcmp(keystr, "AuthorizationKey") == 0)
  12835. {
  12836. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12837. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12839. }
  12840. if(strcmp(keystr, "SecurityProfile") == 0)
  12841. {
  12842. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12844. }
  12845. if(strcmp(keystr, "DefaultPrice") == 0)
  12846. {
  12847. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12849. }
  12850. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12851. {
  12852. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12854. }
  12855. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12856. {
  12857. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12859. }
  12860. if(strcmp(keystr, "TimeOffset") == 0)
  12861. {
  12862. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12864. }
  12865. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12866. {
  12867. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12869. }
  12870. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12871. {
  12872. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12874. }
  12875. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12876. {
  12877. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12879. }
  12880. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12881. {
  12882. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12884. }
  12885. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12886. {
  12887. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12889. }
  12890. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12891. {
  12892. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12894. }
  12895. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12896. {
  12897. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12899. }
  12900. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12901. {
  12902. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12904. }
  12905. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12906. {
  12907. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12909. }
  12910. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12911. {
  12912. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12914. }
  12915. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12916. {
  12917. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12919. }
  12920. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12921. {
  12922. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12924. }
  12925. }
  12926. }
  12927. fclose(fp);
  12928. }
  12929. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12930. {
  12931. return PASS;
  12932. }
  12933. else
  12934. {
  12935. return FAIL;
  12936. }
  12937. }
  12938. void StoreConfigurationTable(void)
  12939. {
  12940. FILE *outfile;
  12941. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12942. if(outfile == NULL)
  12943. {
  12944. DEBUG_INFO("Error opening file");
  12945. return ;
  12946. }
  12947. /*Core Profile*/
  12948. //AllowOfflineTxForUnknownId
  12949. /*
  12950. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12951. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12954. */
  12955. //DEBUG_INFO("data=%s\n",data);
  12956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12957. //AuthorizationCacheEnabled
  12958. /*
  12959. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12962. */
  12963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12964. //AuthorizeRemoteTxRequests
  12965. /*
  12966. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12969. */
  12970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12971. //BlinkRepeat
  12972. /*
  12973. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12976. */
  12977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12978. //ClockAlignedDataInterval
  12979. /*
  12980. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12983. */
  12984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12985. //ConnectionTimeOut
  12986. /*
  12987. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12990. */
  12991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12992. //GetConfigurationMaxKeys
  12993. /*
  12994. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12997. */
  12998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12999. // HeartbeatInterval
  13000. /*
  13001. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13004. */
  13005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13006. // LightIntensity
  13007. /*
  13008. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13011. */
  13012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13013. // LocalAuthorizeOffline
  13014. /*
  13015. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13018. */
  13019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13020. // LocalPreAuthorize
  13021. /*
  13022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13025. */
  13026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13027. // MaxEnergyOnInvalidId
  13028. /*
  13029. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13032. */
  13033. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13035. // MeterValuesAlignedData
  13036. /*
  13037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13040. */
  13041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13042. // MeterValuesAlignedDataMaxLength
  13043. /*
  13044. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13047. */
  13048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13049. // MeterValuesSampledData
  13050. /*
  13051. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13054. */
  13055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13056. // MeterValuesSampledDataMaxLength
  13057. /*
  13058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13061. */
  13062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13063. // MeterValueSampleInterval
  13064. /*
  13065. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13068. */
  13069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13070. // MinimumStatusDuration
  13071. /*
  13072. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13075. */
  13076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13077. // NumberOfConnectors
  13078. /*
  13079. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13082. {
  13083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13084. }
  13085. else
  13086. {
  13087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13088. }
  13089. */
  13090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13091. // ResetRetries
  13092. /*
  13093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13096. */
  13097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13098. // ConnectorPhaseRotation
  13099. /*
  13100. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13103. */
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13105. // ConnectorPhaseRotationMaxLength
  13106. /*
  13107. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13110. */
  13111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13112. // StopTransactionOnEVSideDisconnect
  13113. /*
  13114. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13117. */
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13119. // StopTransactionOnInvalidId
  13120. /*
  13121. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13124. */
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13126. // StopTxnAlignedData
  13127. /*
  13128. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13131. */
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13133. // StopTxnAlignedDataMaxLength
  13134. /*
  13135. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13138. */
  13139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13140. // StopTxnSampledData
  13141. /*
  13142. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13145. */
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13147. // StopTxnSampledDataMaxLength
  13148. /*
  13149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13152. */
  13153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13154. // SupportedFeatureProfiles
  13155. /*
  13156. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13159. */
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13161. // SupportedFeatureProfilesMaxLength
  13162. /*
  13163. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13166. */
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13168. // TransactionMessageAttempts
  13169. /*
  13170. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13173. */
  13174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13175. // TransactionMessageRetryInterval
  13176. /*
  13177. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13180. */
  13181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13182. // UnlockConnectorOnEVSideDisconnect
  13183. /*
  13184. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13187. */
  13188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13189. // WebSocketPingInterval
  13190. /*
  13191. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13194. */
  13195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13196. // QueueOffLineMeterValues
  13197. /*
  13198. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13201. */
  13202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13203. // AuthorizationKey
  13204. /*
  13205. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13208. */
  13209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13210. // SecurityProfile
  13211. /*
  13212. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13215. */
  13216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13217. // DefaultPrice
  13218. /*
  13219. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13222. */
  13223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13224. // CustomDisplayCostAndPrice
  13225. /*
  13226. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13229. */
  13230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13231. // CustomIdleFeeAfterStop
  13232. /*
  13233. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13236. */
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13238. // TimeOffset
  13239. /*
  13240. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13243. */
  13244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13245. // NextTimeOffsetTransitionDateTime
  13246. /*
  13247. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13250. */
  13251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13252. // TimeOffsetNextTransition
  13253. /*
  13254. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13257. */
  13258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13259. // ConfigurationVersion
  13260. /*
  13261. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13264. */
  13265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13266. //* Local Auth List Management Profile*/
  13267. //LocalAuthListEnabled
  13268. /*
  13269. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13272. */
  13273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13274. //LocalAuthListMaxLength
  13275. /*
  13276. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13279. */
  13280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13281. //SendLocalListMaxLength
  13282. /*
  13283. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13286. */
  13287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13288. //ReserveConnectorZeroSupported
  13289. /*
  13290. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13293. */
  13294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13295. //* Smart Charging Profile */
  13296. //ChargeProfileMaxStackLevel
  13297. /*
  13298. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13301. */
  13302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13303. // ChargingScheduleAllowedChargingRateUnit
  13304. /*
  13305. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13308. */
  13309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13310. // ChargingScheduleMaxPeriods
  13311. /*
  13312. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13315. */
  13316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13317. // ConnectorSwitch3to1PhaseSupported
  13318. /*
  13319. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13322. */
  13323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13324. // MaxChargingProfilesInstalled
  13325. /*
  13326. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13329. */
  13330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13331. fclose(outfile);
  13332. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13333. }
  13334. void getKeyValue(char *keyReq)
  13335. {
  13336. int isEmpty = FALSE;
  13337. int isKnowKey = FALSE;
  13338. DEBUG_INFO("keyReq = %s\n", keyReq);
  13339. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13340. isEmpty = TRUE;
  13341. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13342. {
  13343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13346. {
  13347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13348. }
  13349. else
  13350. {
  13351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13352. }
  13353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13354. isKnowKey = TRUE;
  13355. }
  13356. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13357. {
  13358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13361. {
  13362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13363. }
  13364. else
  13365. {
  13366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13367. }
  13368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13369. isKnowKey = TRUE;
  13370. }
  13371. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13372. {
  13373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13376. {
  13377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13378. }
  13379. else
  13380. {
  13381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13382. }
  13383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13384. isKnowKey = TRUE;
  13385. }
  13386. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13387. {
  13388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13391. {
  13392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13393. }
  13394. else
  13395. {
  13396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13397. }
  13398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13399. isKnowKey = TRUE;
  13400. }
  13401. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13402. {
  13403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13406. {
  13407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13408. }
  13409. else
  13410. {
  13411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13412. }
  13413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13414. isKnowKey = TRUE;
  13415. }
  13416. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13417. {
  13418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13421. {
  13422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13423. }
  13424. else
  13425. {
  13426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13427. }
  13428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13429. isKnowKey = TRUE;
  13430. }
  13431. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13432. {
  13433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13436. {
  13437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13438. }
  13439. else
  13440. {
  13441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13442. }
  13443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13444. isKnowKey = TRUE;
  13445. }
  13446. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13447. {
  13448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13451. {
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13453. }
  13454. else
  13455. {
  13456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13457. }
  13458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13459. isKnowKey = TRUE;
  13460. }
  13461. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13462. {
  13463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13466. {
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13468. }
  13469. else
  13470. {
  13471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13472. }
  13473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13474. isKnowKey = TRUE;
  13475. }
  13476. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13477. {
  13478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13481. {
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13483. }
  13484. else
  13485. {
  13486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13487. }
  13488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13489. isKnowKey = TRUE;
  13490. }
  13491. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13492. {
  13493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13496. {
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13498. }
  13499. else
  13500. {
  13501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13502. }
  13503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13504. isKnowKey = TRUE;
  13505. }
  13506. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13507. {
  13508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13511. {
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13513. }
  13514. else
  13515. {
  13516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13517. }
  13518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13519. isKnowKey = TRUE;
  13520. }
  13521. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13522. {
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13526. {
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13528. }
  13529. else
  13530. {
  13531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13532. }
  13533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13534. isKnowKey = TRUE;
  13535. }
  13536. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13537. {
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13541. {
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13543. }
  13544. else
  13545. {
  13546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13547. }
  13548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13549. isKnowKey = TRUE;
  13550. }
  13551. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13552. {
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13556. {
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13558. }
  13559. else
  13560. {
  13561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13562. }
  13563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13564. isKnowKey = TRUE;
  13565. }
  13566. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13567. {
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13571. {
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13573. }
  13574. else
  13575. {
  13576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13577. }
  13578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13579. isKnowKey = TRUE;
  13580. }
  13581. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13582. {
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13586. {
  13587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13588. }
  13589. else
  13590. {
  13591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13592. }
  13593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13594. isKnowKey = TRUE;
  13595. }
  13596. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13597. {
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13601. {
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13603. }
  13604. else
  13605. {
  13606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13607. }
  13608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13609. isKnowKey = TRUE;
  13610. }
  13611. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13612. {
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13616. {
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13618. }
  13619. else
  13620. {
  13621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13622. }
  13623. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13625. isKnowKey = TRUE;
  13626. }
  13627. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13628. {
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13634. }
  13635. else
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13638. }
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13640. isKnowKey = TRUE;
  13641. }
  13642. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13643. {
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13649. }
  13650. else
  13651. {
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13653. }
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13655. isKnowKey = TRUE;
  13656. }
  13657. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13658. {
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13664. }
  13665. else
  13666. {
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13668. }
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13670. isKnowKey = TRUE;
  13671. }
  13672. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13673. {
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13679. }
  13680. else
  13681. {
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13683. }
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13685. isKnowKey = TRUE;
  13686. }
  13687. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13688. {
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13694. }
  13695. else
  13696. {
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13698. }
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13700. isKnowKey = TRUE;
  13701. }
  13702. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13703. {
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13707. {
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13709. }
  13710. else
  13711. {
  13712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13713. }
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13715. isKnowKey = TRUE;
  13716. }
  13717. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13718. {
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13722. {
  13723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13724. }
  13725. else
  13726. {
  13727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13728. }
  13729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13730. isKnowKey = TRUE;
  13731. }
  13732. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13733. {
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13737. {
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13739. }
  13740. else
  13741. {
  13742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13743. }
  13744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13745. isKnowKey = TRUE;
  13746. }
  13747. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13748. {
  13749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13752. {
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13754. }
  13755. else
  13756. {
  13757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13758. }
  13759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13760. isKnowKey = TRUE;
  13761. }
  13762. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13763. {
  13764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13767. {
  13768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13769. }
  13770. else
  13771. {
  13772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13773. }
  13774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13775. isKnowKey = TRUE;
  13776. }
  13777. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13778. {
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13782. {
  13783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13784. }
  13785. else
  13786. {
  13787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13788. }
  13789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13790. isKnowKey = TRUE;
  13791. }
  13792. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13793. {
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13797. {
  13798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13799. }
  13800. else
  13801. {
  13802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13803. }
  13804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13805. isKnowKey = TRUE;
  13806. }
  13807. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13808. {
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13812. {
  13813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13814. }
  13815. else
  13816. {
  13817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13818. }
  13819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13820. isKnowKey = TRUE;
  13821. }
  13822. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13823. {
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13827. {
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13829. }
  13830. else
  13831. {
  13832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13833. }
  13834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13835. isKnowKey = TRUE;
  13836. }
  13837. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13838. {
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13844. }
  13845. else
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13848. }
  13849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13850. isKnowKey = TRUE;
  13851. }
  13852. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13853. {
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13859. }
  13860. else
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13863. }
  13864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13865. isKnowKey = TRUE;
  13866. }
  13867. /*
  13868. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13869. {
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13875. }
  13876. else
  13877. {
  13878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13879. }
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13881. isKnowKey = TRUE;
  13882. }*/
  13883. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13884. {
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13890. }
  13891. else
  13892. {
  13893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13894. }
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13896. isKnowKey = TRUE;
  13897. }
  13898. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13899. {
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13903. {
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13905. }
  13906. else
  13907. {
  13908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13909. }
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13911. isKnowKey = TRUE;
  13912. }
  13913. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13914. {
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13918. {
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13920. }
  13921. else
  13922. {
  13923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13924. }
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13926. isKnowKey = TRUE;
  13927. }
  13928. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13929. {
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13933. {
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13935. }
  13936. else
  13937. {
  13938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13939. }
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13941. isKnowKey = TRUE;
  13942. }
  13943. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13944. {
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13948. {
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13950. }
  13951. else
  13952. {
  13953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13954. }
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13956. isKnowKey = TRUE;
  13957. }
  13958. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13959. {
  13960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13963. {
  13964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13965. }
  13966. else
  13967. {
  13968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13969. }
  13970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13971. isKnowKey = TRUE;
  13972. }
  13973. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13974. {
  13975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13978. {
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13980. }
  13981. else
  13982. {
  13983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13984. }
  13985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13986. isKnowKey = TRUE;
  13987. }
  13988. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13989. {
  13990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13993. {
  13994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13995. }
  13996. else
  13997. {
  13998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13999. }
  14000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14001. isKnowKey = TRUE;
  14002. }
  14003. #if 1
  14004. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14005. {
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14008. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14009. {
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14011. }
  14012. else
  14013. {
  14014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14015. }
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14017. isKnowKey = TRUE;
  14018. }
  14019. #endif
  14020. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14021. {
  14022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14024. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14025. {
  14026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14027. }
  14028. else
  14029. {
  14030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14031. }
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14033. isKnowKey = TRUE;
  14034. }
  14035. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14036. {
  14037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14039. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14040. {
  14041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14042. }
  14043. else
  14044. {
  14045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14046. }
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14048. isKnowKey = TRUE;
  14049. }
  14050. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14051. {
  14052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14054. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14055. {
  14056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14057. }
  14058. else
  14059. {
  14060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14061. }
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14063. isKnowKey = TRUE;
  14064. }
  14065. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14066. {
  14067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14069. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14070. {
  14071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14072. }
  14073. else
  14074. {
  14075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14076. }
  14077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14078. isKnowKey = TRUE;
  14079. }
  14080. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14081. {
  14082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14084. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14085. {
  14086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14087. }
  14088. else
  14089. {
  14090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14091. }
  14092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14093. isKnowKey = TRUE;
  14094. }
  14095. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14096. {
  14097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14099. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14100. {
  14101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14102. }
  14103. else
  14104. {
  14105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14106. }
  14107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14108. isKnowKey = TRUE;
  14109. }
  14110. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14111. {
  14112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14114. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14115. {
  14116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14117. }
  14118. else
  14119. {
  14120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14121. }
  14122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14123. isKnowKey = TRUE;
  14124. }
  14125. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14126. {
  14127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14129. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14130. {
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14132. }
  14133. else
  14134. {
  14135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14136. }
  14137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14138. isKnowKey = TRUE;
  14139. }
  14140. //=========================================================
  14141. if(!isEmpty && !isKnowKey)
  14142. {
  14143. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14144. strcpy(unknownkey[UnknownKeynum], keyReq);
  14145. UnknownKeynum = UnknownKeynum + 1;
  14146. }
  14147. }
  14148. void processUnkownKey(void)
  14149. {
  14150. DEBUG_INFO("processUnkownKey...\n");
  14151. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14152. for(int index=0; index < UnknownKeynum; index++)
  14153. {
  14154. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14155. {
  14156. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14157. }
  14158. }
  14159. }
  14160. int setKeyValue(char *key, char *value)
  14161. {
  14162. int isSuccess = NotSupported;
  14163. int check_ascii=0;
  14164. char str[256]={0};
  14165. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14166. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14167. {
  14168. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14170. {
  14171. strcpy(str, (const char*)value);
  14172. for(int i = 0; str[i]; i++){
  14173. str[i] = tolower(str[i]);
  14174. }
  14175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14176. isSuccess = ConfigurationStatus_Accepted;
  14177. }
  14178. else
  14179. {
  14180. isSuccess = ConfigurationStatus_Rejected;
  14181. }
  14182. }
  14183. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14184. {
  14185. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14187. {
  14188. strcpy(str, (const char*)value);
  14189. for(int i = 0; str[i]; i++){
  14190. str[i] = tolower(str[i]);
  14191. }
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14193. isSuccess = ConfigurationStatus_Accepted;
  14194. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14195. }
  14196. else
  14197. {
  14198. isSuccess = ConfigurationStatus_Rejected;
  14199. }
  14200. }
  14201. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14202. {
  14203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14204. {
  14205. strcpy(str, (const char*)value);
  14206. for(int i = 0; str[i]; i++)
  14207. {
  14208. str[i] = tolower(str[i]);
  14209. }
  14210. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14212. isSuccess = ConfigurationStatus_Accepted;
  14213. }
  14214. else
  14215. {
  14216. isSuccess = ConfigurationStatus_Rejected;
  14217. }
  14218. }
  14219. if(strcmp(key, "BlinkRepeat") == 0)
  14220. {
  14221. //Charger.BlinkRepeat = Integer.parseInt(value);
  14222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14223. {
  14224. check_ascii = value[0];
  14225. if( (check_ascii < 48) || (check_ascii > 57) )
  14226. {
  14227. isSuccess = ConfigurationStatus_Rejected;
  14228. }
  14229. else
  14230. {
  14231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14232. isSuccess = ConfigurationStatus_Accepted;
  14233. }
  14234. }
  14235. else
  14236. {
  14237. isSuccess = ConfigurationStatus_Rejected;
  14238. }
  14239. }
  14240. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14241. {
  14242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14243. {
  14244. check_ascii = value[0];
  14245. if( (check_ascii < 48) || (check_ascii > 57) )
  14246. {
  14247. isSuccess = ConfigurationStatus_Rejected;
  14248. }
  14249. else
  14250. {
  14251. if((atoi(value) == 0) || (atoi(value) >= 10))
  14252. {
  14253. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14255. isSuccess = ConfigurationStatus_Accepted;
  14256. }
  14257. else
  14258. isSuccess = ConfigurationStatus_Rejected;
  14259. }
  14260. }
  14261. else
  14262. {
  14263. isSuccess = ConfigurationStatus_Rejected;
  14264. }
  14265. }
  14266. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14267. {
  14268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14269. {
  14270. check_ascii = value[0];
  14271. if( (check_ascii < 48) || (check_ascii > 57) )
  14272. {
  14273. isSuccess = ConfigurationStatus_Rejected;
  14274. }
  14275. else
  14276. {
  14277. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14279. isSuccess = ConfigurationStatus_Accepted;
  14280. }
  14281. }
  14282. else
  14283. {
  14284. isSuccess = ConfigurationStatus_Rejected;
  14285. }
  14286. }
  14287. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14288. {
  14289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14290. {
  14291. check_ascii = value[0];
  14292. if( (check_ascii < 48) || (check_ascii > 57) )
  14293. {
  14294. isSuccess = ConfigurationStatus_Rejected;
  14295. }
  14296. else
  14297. {
  14298. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14300. isSuccess = ConfigurationStatus_Accepted;
  14301. }
  14302. }
  14303. else
  14304. {
  14305. isSuccess = ConfigurationStatus_Rejected;
  14306. }
  14307. }
  14308. if(strcmp(key, "HeartbeatInterval") == 0)
  14309. {
  14310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].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) || (atoi(value) >= 10))
  14320. {
  14321. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14323. HeartBeatWaitTime = atoi(value);
  14324. isSuccess = ConfigurationStatus_Accepted;
  14325. }
  14326. else
  14327. {
  14328. isSuccess = ConfigurationStatus_Rejected;
  14329. }
  14330. }
  14331. }
  14332. else
  14333. {
  14334. isSuccess = ConfigurationStatus_Rejected;
  14335. }
  14336. }
  14337. if(strcmp(key, "LightIntensity") == 0)
  14338. {
  14339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14349. isSuccess = ConfigurationStatus_Accepted;
  14350. }
  14351. }
  14352. else
  14353. {
  14354. isSuccess = ConfigurationStatus_Rejected;
  14355. }
  14356. }
  14357. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14358. {
  14359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14360. {
  14361. strcpy(str, (const char*)value);
  14362. for(int i = 0; str[i]; i++)
  14363. {
  14364. str[i] = tolower(str[i]);
  14365. }
  14366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14367. isSuccess = ConfigurationStatus_Accepted;
  14368. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14369. }
  14370. else
  14371. {
  14372. isSuccess = ConfigurationStatus_Rejected;
  14373. }
  14374. }
  14375. if(strcmp(key, "LocalPreAuthorize") == 0)
  14376. {
  14377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14378. {
  14379. strcpy(str, (const char*)value);
  14380. for(int i = 0; str[i]; i++)
  14381. {
  14382. str[i] = tolower(str[i]);
  14383. }
  14384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14385. isSuccess = ConfigurationStatus_Accepted;
  14386. }
  14387. else
  14388. {
  14389. isSuccess = ConfigurationStatus_Rejected;
  14390. }
  14391. }
  14392. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14393. {
  14394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14395. {
  14396. check_ascii = value[0];
  14397. if( (check_ascii < 48) || (check_ascii > 57) )
  14398. {
  14399. isSuccess = ConfigurationStatus_Rejected;
  14400. }
  14401. else
  14402. {
  14403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14404. isSuccess = ConfigurationStatus_Accepted;
  14405. }
  14406. }
  14407. else
  14408. {
  14409. isSuccess = ConfigurationStatus_Rejected;
  14410. }
  14411. }
  14412. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14413. {
  14414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14415. {
  14416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14417. isSuccess = ConfigurationStatus_Accepted;
  14418. }
  14419. else
  14420. {
  14421. isSuccess = ConfigurationStatus_Rejected;
  14422. }
  14423. }
  14424. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14425. {
  14426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14427. {
  14428. check_ascii = value[0];
  14429. if( (check_ascii < 48) || (check_ascii > 57) )
  14430. {
  14431. isSuccess = ConfigurationStatus_Rejected;
  14432. }
  14433. else
  14434. {
  14435. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14437. isSuccess = ConfigurationStatus_Accepted;
  14438. }
  14439. }
  14440. else
  14441. {
  14442. isSuccess = ConfigurationStatus_Rejected;
  14443. }
  14444. }
  14445. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14446. {
  14447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14448. {
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14450. isSuccess = ConfigurationStatus_Accepted;
  14451. }
  14452. else
  14453. {
  14454. isSuccess = ConfigurationStatus_Rejected;
  14455. }
  14456. }
  14457. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14458. {
  14459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14460. {
  14461. check_ascii = value[0];
  14462. if( (check_ascii < 48) || (check_ascii > 57) )
  14463. {
  14464. isSuccess = ConfigurationStatus_Rejected;
  14465. }
  14466. else
  14467. {
  14468. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14470. isSuccess = ConfigurationStatus_Accepted;
  14471. }
  14472. }
  14473. else
  14474. {
  14475. isSuccess = ConfigurationStatus_Rejected;
  14476. }
  14477. }
  14478. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14479. {
  14480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14481. {
  14482. check_ascii = value[0];
  14483. if( (check_ascii < 48) || (check_ascii > 57) )
  14484. {
  14485. isSuccess = ConfigurationStatus_Rejected;
  14486. }
  14487. else
  14488. {
  14489. if((atoi(value) == 0) || (atoi(value) >= 10))
  14490. {
  14491. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14493. isSuccess = ConfigurationStatus_Accepted;
  14494. }
  14495. else
  14496. {
  14497. isSuccess = ConfigurationStatus_Rejected;
  14498. }
  14499. }
  14500. }
  14501. else
  14502. {
  14503. isSuccess = ConfigurationStatus_Rejected;
  14504. }
  14505. }
  14506. if(strcmp(key, "MinimumStatusDuration") == 0)
  14507. {
  14508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].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. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14518. {
  14519. isSuccess = ConfigurationStatus_Rejected;
  14520. }
  14521. else
  14522. {
  14523. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14525. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14526. isSuccess = ConfigurationStatus_Accepted;
  14527. }
  14528. }
  14529. }
  14530. else
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. }
  14535. if(strcmp(key, "NumberOfConnectors") == 0)
  14536. {
  14537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14538. {
  14539. check_ascii = value[0];
  14540. if( (check_ascii < 48) || (check_ascii > 57) )
  14541. {
  14542. isSuccess = ConfigurationStatus_Rejected;
  14543. }
  14544. else
  14545. {
  14546. //Charger.ResetRetries = Integer.parseInt(value);
  14547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14548. isSuccess = ConfigurationStatus_Accepted;
  14549. }
  14550. }
  14551. else
  14552. {
  14553. isSuccess = ConfigurationStatus_Rejected;
  14554. }
  14555. }
  14556. if(strcmp(key, "ResetRetries") == 0)
  14557. {
  14558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14559. {
  14560. check_ascii = value[0];
  14561. if( (check_ascii < 48) || (check_ascii > 57) )
  14562. {
  14563. isSuccess = ConfigurationStatus_Rejected;
  14564. }
  14565. else
  14566. {
  14567. //Charger.ResetRetries = Integer.parseInt(value);
  14568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14569. isSuccess = ConfigurationStatus_Accepted;
  14570. }
  14571. }
  14572. else
  14573. {
  14574. isSuccess = ConfigurationStatus_Rejected;
  14575. }
  14576. }
  14577. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14578. {
  14579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14580. {
  14581. strcpy(str, (const char*)value);
  14582. for(int i = 0; str[i]; i++)
  14583. {
  14584. str[i] = tolower(str[i]);
  14585. }
  14586. if(strcmp(str, "notapplicable")== 0)
  14587. {
  14588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14589. isSuccess = ConfigurationStatus_Accepted;
  14590. }
  14591. else if(strcmp(str, "unknown")== 0)
  14592. {
  14593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14594. isSuccess = ConfigurationStatus_Accepted;
  14595. }
  14596. else if(strcmp(str, "rst")== 0)
  14597. {
  14598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14599. isSuccess = ConfigurationStatus_Accepted;
  14600. }
  14601. else if(strcmp(str, "rts")== 0)
  14602. {
  14603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14604. isSuccess = ConfigurationStatus_Accepted;
  14605. }
  14606. else if(strcmp(str, "srt")== 0)
  14607. {
  14608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14609. isSuccess = ConfigurationStatus_Accepted;
  14610. }
  14611. else if(strcmp(str, "str")== 0)
  14612. {
  14613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14614. isSuccess = ConfigurationStatus_Accepted;
  14615. }
  14616. else if(strcmp(str, "trs")== 0)
  14617. {
  14618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14619. isSuccess = ConfigurationStatus_Accepted;
  14620. }
  14621. else if(strcmp(str, "tsr")== 0)
  14622. {
  14623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14624. isSuccess = ConfigurationStatus_Accepted;
  14625. }
  14626. else
  14627. {
  14628. isSuccess = ConfigurationStatus_Rejected;
  14629. }
  14630. }
  14631. else
  14632. {
  14633. isSuccess = ConfigurationStatus_Rejected;
  14634. }
  14635. }
  14636. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14637. {
  14638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14639. {
  14640. check_ascii = value[0];
  14641. if( (check_ascii < 48) || (check_ascii > 57) )
  14642. {
  14643. isSuccess = ConfigurationStatus_Rejected;
  14644. }
  14645. else
  14646. {
  14647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14648. isSuccess = ConfigurationStatus_Accepted;
  14649. }
  14650. }
  14651. else
  14652. {
  14653. isSuccess = ConfigurationStatus_Rejected;
  14654. }
  14655. }
  14656. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14657. {
  14658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14659. {
  14660. strcpy(str, (const char*)value);
  14661. for(int i = 0; str[i]; i++)
  14662. {
  14663. str[i] = tolower(str[i]);
  14664. }
  14665. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14667. isSuccess = ConfigurationStatus_Accepted;
  14668. }
  14669. else
  14670. {
  14671. isSuccess = ConfigurationStatus_Rejected;
  14672. }
  14673. }
  14674. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14675. {
  14676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14677. {
  14678. strcpy(str, (const char*)value);
  14679. for(int i = 0; str[i]; i++)
  14680. {
  14681. str[i] = tolower(str[i]);
  14682. }
  14683. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14685. isSuccess = ConfigurationStatus_Accepted;
  14686. }
  14687. else
  14688. {
  14689. isSuccess = ConfigurationStatus_Rejected;
  14690. }
  14691. }
  14692. if(strcmp(key, "StopTxnAlignedData") == 0)
  14693. {
  14694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14695. {
  14696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14697. isSuccess = ConfigurationStatus_Accepted;
  14698. }
  14699. else
  14700. {
  14701. isSuccess = ConfigurationStatus_Rejected;
  14702. }
  14703. }
  14704. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14705. {
  14706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14707. {
  14708. check_ascii = value[0];
  14709. if( (check_ascii < 48) || (check_ascii > 57) )
  14710. {
  14711. isSuccess = ConfigurationStatus_Rejected;
  14712. }
  14713. else
  14714. {
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14716. isSuccess = ConfigurationStatus_Accepted;
  14717. }
  14718. }
  14719. else
  14720. {
  14721. isSuccess = ConfigurationStatus_Rejected;
  14722. }
  14723. }
  14724. if(strcmp(key, "StopTxnSampledData") == 0)
  14725. {
  14726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14727. {
  14728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14729. isSuccess = ConfigurationStatus_Accepted;
  14730. }
  14731. else
  14732. {
  14733. isSuccess = ConfigurationStatus_Rejected;
  14734. }
  14735. }
  14736. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14737. {
  14738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14739. {
  14740. check_ascii = value[0];
  14741. if( (check_ascii < 48) || (check_ascii > 57) )
  14742. {
  14743. isSuccess = ConfigurationStatus_Rejected;
  14744. }
  14745. else
  14746. {
  14747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14748. isSuccess = ConfigurationStatus_Accepted;
  14749. }
  14750. }
  14751. else
  14752. {
  14753. isSuccess = ConfigurationStatus_Rejected;
  14754. }
  14755. }
  14756. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14757. {
  14758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14759. {
  14760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14761. isSuccess = ConfigurationStatus_Accepted;
  14762. }
  14763. else
  14764. {
  14765. isSuccess = ConfigurationStatus_Rejected;
  14766. }
  14767. }
  14768. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14769. {
  14770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14771. {
  14772. check_ascii = value[0];
  14773. if( (check_ascii < 48) || (check_ascii > 57) )
  14774. {
  14775. isSuccess = ConfigurationStatus_Rejected;
  14776. }
  14777. else
  14778. {
  14779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14780. isSuccess = ConfigurationStatus_Accepted;
  14781. }
  14782. }
  14783. else
  14784. {
  14785. isSuccess = ConfigurationStatus_Rejected;
  14786. }
  14787. }
  14788. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14789. {
  14790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14791. {
  14792. check_ascii = value[0];
  14793. if( (check_ascii < 48) || (check_ascii > 57) )
  14794. {
  14795. isSuccess = ConfigurationStatus_Rejected;
  14796. }
  14797. else
  14798. {
  14799. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14801. TransactionMessageAttemptsValue = atoi(value);
  14802. isSuccess = ConfigurationStatus_Accepted;
  14803. }
  14804. }
  14805. else
  14806. {
  14807. isSuccess = ConfigurationStatus_Rejected;
  14808. }
  14809. }
  14810. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14811. {
  14812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14813. {
  14814. check_ascii = value[0];
  14815. if( (check_ascii < 48) || (check_ascii > 57) )
  14816. {
  14817. isSuccess = ConfigurationStatus_Rejected;
  14818. }
  14819. else
  14820. {
  14821. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14823. TransactionMessageRetryIntervalValue = atoi(value);
  14824. isSuccess = ConfigurationStatus_Accepted;
  14825. }
  14826. }
  14827. else
  14828. {
  14829. isSuccess = ConfigurationStatus_Rejected;
  14830. }
  14831. }
  14832. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14833. {
  14834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14835. {
  14836. strcpy(str, (const char*)value);
  14837. for(int i = 0; str[i]; i++)
  14838. {
  14839. str[i] = tolower(str[i]);
  14840. }
  14841. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14843. isSuccess = ConfigurationStatus_Accepted;
  14844. }
  14845. else
  14846. {
  14847. isSuccess = ConfigurationStatus_Rejected;
  14848. }
  14849. }
  14850. if(strcmp(key, "WebSocketPingInterval") == 0)
  14851. {
  14852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14853. {
  14854. check_ascii = value[0];
  14855. if( (check_ascii < 48) || (check_ascii > 57) )
  14856. {
  14857. isSuccess = ConfigurationStatus_Rejected;
  14858. }
  14859. else
  14860. {
  14861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14862. isSuccess = ConfigurationStatus_Accepted;
  14863. }
  14864. }
  14865. else
  14866. {
  14867. isSuccess = ConfigurationStatus_Rejected;
  14868. }
  14869. }
  14870. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14871. {
  14872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14873. {
  14874. strcpy(str, (const char*)value);
  14875. for(int i = 0; str[i]; i++)
  14876. {
  14877. str[i] = tolower(str[i]);
  14878. }
  14879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14880. isSuccess = ConfigurationStatus_Accepted;
  14881. }
  14882. else
  14883. {
  14884. isSuccess = ConfigurationStatus_Rejected;
  14885. }
  14886. }
  14887. if(strcmp(key, "AuthorizationKey") == 0)
  14888. {
  14889. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14890. {
  14891. strcpy(str, (const char*)value);
  14892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14893. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14894. isSuccess = ConfigurationStatus_Accepted;
  14895. }
  14896. else
  14897. {
  14898. isSuccess = ConfigurationStatus_Rejected;
  14899. }
  14900. }
  14901. if(strcmp(key, "SecurityProfile") == 0)
  14902. {
  14903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14904. {
  14905. check_ascii = value[0];
  14906. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14907. {
  14908. isSuccess = ConfigurationStatus_Rejected;
  14909. }
  14910. else if(check_ascii == 0x33)
  14911. {
  14912. isSuccess = NotSupported;
  14913. }
  14914. else
  14915. {
  14916. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14917. {
  14918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14919. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14920. isSuccess = ConfigurationStatus_Accepted;
  14921. }
  14922. else
  14923. isSuccess = ConfigurationStatus_Rejected;
  14924. }
  14925. }
  14926. else
  14927. {
  14928. isSuccess = ConfigurationStatus_Rejected;
  14929. }
  14930. }
  14931. if(strcmp(key, "DefaultPrice") == 0)
  14932. {
  14933. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14934. {
  14935. strcpy(str, (const char*)value);
  14936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14937. isSuccess = ConfigurationStatus_Accepted;
  14938. }
  14939. else
  14940. {
  14941. isSuccess = ConfigurationStatus_Rejected;
  14942. }
  14943. }
  14944. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14945. {
  14946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14947. {
  14948. strcpy(str, (const char*)value);
  14949. for(int i = 0; str[i]; i++)
  14950. {
  14951. str[i] = tolower(str[i]);
  14952. }
  14953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14954. isSuccess = ConfigurationStatus_Accepted;
  14955. }
  14956. else
  14957. {
  14958. isSuccess = ConfigurationStatus_Rejected;
  14959. }
  14960. }
  14961. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14962. {
  14963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14964. {
  14965. strcpy(str, (const char*)value);
  14966. for(int i = 0; str[i]; i++)
  14967. {
  14968. str[i] = tolower(str[i]);
  14969. }
  14970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14971. isSuccess = ConfigurationStatus_Accepted;
  14972. }
  14973. else
  14974. {
  14975. isSuccess = ConfigurationStatus_Rejected;
  14976. }
  14977. }
  14978. if(strcmp(key, "TimeOffset") == 0)
  14979. {
  14980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14981. {
  14982. strcpy(str, (const char*)value);
  14983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14984. isSuccess = ConfigurationStatus_Accepted;
  14985. }
  14986. else
  14987. {
  14988. isSuccess = ConfigurationStatus_Rejected;
  14989. }
  14990. }
  14991. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14992. {
  14993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14994. {
  14995. strcpy(str, (const char*)value);
  14996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14997. isSuccess = ConfigurationStatus_Accepted;
  14998. }
  14999. else
  15000. {
  15001. isSuccess = ConfigurationStatus_Rejected;
  15002. }
  15003. }
  15004. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15005. {
  15006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15007. {
  15008. strcpy(str, (const char*)value);
  15009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15010. isSuccess = ConfigurationStatus_Accepted;
  15011. }
  15012. else
  15013. {
  15014. isSuccess = ConfigurationStatus_Rejected;
  15015. }
  15016. }
  15017. #if 0
  15018. //For OCPP Test Case
  15019. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15020. {
  15021. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15022. {
  15023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15024. isSuccess = ConfigurationStatus_Accepted;
  15025. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15026. }
  15027. else
  15028. {
  15029. isSuccess = ConfigurationStatus_Rejected;
  15030. }
  15031. }
  15032. #endif
  15033. #if 1
  15034. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15035. {
  15036. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15037. {
  15038. strcpy(str, (const char*)value);
  15039. for(int i = 0; str[i]; i++)
  15040. {
  15041. str[i] = tolower(str[i]);
  15042. }
  15043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15044. isSuccess = ConfigurationStatus_Accepted;
  15045. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15046. }
  15047. else
  15048. {
  15049. isSuccess = ConfigurationStatus_Rejected;
  15050. }
  15051. }
  15052. #endif
  15053. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15054. {
  15055. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15056. {
  15057. check_ascii = value[0];
  15058. if( (check_ascii < 48) || (check_ascii > 57) )
  15059. {
  15060. isSuccess = ConfigurationStatus_Rejected;
  15061. }
  15062. else
  15063. {
  15064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15065. isSuccess = ConfigurationStatus_Accepted;
  15066. }
  15067. }
  15068. else
  15069. {
  15070. isSuccess = ConfigurationStatus_Rejected;
  15071. }
  15072. }
  15073. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15074. {
  15075. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15076. {
  15077. check_ascii = value[0];
  15078. if( (check_ascii < 48) || (check_ascii > 57) )
  15079. {
  15080. isSuccess = ConfigurationStatus_Rejected;
  15081. }
  15082. else
  15083. {
  15084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15085. isSuccess = ConfigurationStatus_Accepted;
  15086. }
  15087. }
  15088. else
  15089. {
  15090. isSuccess = ConfigurationStatus_Rejected;
  15091. }
  15092. }
  15093. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15094. {
  15095. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15096. {
  15097. strcpy(str, (const char*)value);
  15098. for(int i = 0; str[i]; i++)
  15099. {
  15100. str[i] = tolower(str[i]);
  15101. }
  15102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15103. isSuccess = ConfigurationStatus_Accepted;
  15104. }
  15105. else
  15106. {
  15107. isSuccess = ConfigurationStatus_Rejected;
  15108. }
  15109. }
  15110. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15111. {
  15112. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15113. {
  15114. check_ascii = value[0];
  15115. if( (check_ascii < 48) || (check_ascii > 57) )
  15116. {
  15117. isSuccess = ConfigurationStatus_Rejected;
  15118. }
  15119. else
  15120. {
  15121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15122. isSuccess = ConfigurationStatus_Accepted;
  15123. }
  15124. }
  15125. else
  15126. {
  15127. isSuccess = ConfigurationStatus_Rejected;
  15128. }
  15129. }
  15130. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15131. {
  15132. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15133. {
  15134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15135. isSuccess = ConfigurationStatus_Accepted;
  15136. }
  15137. else
  15138. {
  15139. isSuccess = ConfigurationStatus_Rejected;
  15140. }
  15141. }
  15142. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15143. {
  15144. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15145. {
  15146. check_ascii = value[0];
  15147. if( (check_ascii < 48) || (check_ascii > 57) )
  15148. {
  15149. isSuccess = ConfigurationStatus_Rejected;
  15150. }
  15151. else
  15152. {
  15153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15154. isSuccess = ConfigurationStatus_Accepted;
  15155. }
  15156. }
  15157. else
  15158. {
  15159. isSuccess = ConfigurationStatus_Rejected;
  15160. }
  15161. }
  15162. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15163. {
  15164. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15165. {
  15166. strcpy(str, (const char*)value);
  15167. for(int i = 0; str[i]; i++)
  15168. {
  15169. str[i] = tolower(str[i]);
  15170. }
  15171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15172. isSuccess = ConfigurationStatus_Accepted;
  15173. }
  15174. else
  15175. {
  15176. isSuccess = ConfigurationStatus_Rejected;
  15177. }
  15178. }
  15179. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15180. {
  15181. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15182. {
  15183. check_ascii = value[0];
  15184. if( (check_ascii < 48) || (check_ascii > 57) )
  15185. {
  15186. isSuccess = ConfigurationStatus_Rejected;
  15187. }
  15188. else
  15189. {
  15190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15191. isSuccess = ConfigurationStatus_Accepted;
  15192. }
  15193. }
  15194. else
  15195. {
  15196. isSuccess = ConfigurationStatus_Rejected;
  15197. }
  15198. }
  15199. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15200. return isSuccess;
  15201. }
  15202. int TransactionMessageAttemptsGet(void)
  15203. {
  15204. return TransactionMessageAttemptsValue;
  15205. }
  15206. int FirstHeartBeatResponse(void)
  15207. {
  15208. return FirstHeartBeat;
  15209. }
  15210. int TransactionMessageRetryIntervalGet(void)
  15211. {
  15212. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15213. }
  15214. int ReadHttpStatus(int sock)
  15215. {
  15216. //char c;
  15217. char buff[1024]="",*ptr=buff+1;
  15218. int bytes_received, status;
  15219. DEBUG_INFO("Begin Response ..\n");
  15220. while((bytes_received = recv(sock, ptr, 1, 0))){
  15221. if(bytes_received==-1){
  15222. perror("ReadHttpStatus");
  15223. exit(1);
  15224. }
  15225. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15226. ptr++;
  15227. }
  15228. *ptr=0;
  15229. ptr=buff+1;
  15230. sscanf(ptr,"%*s %d ", &status);
  15231. DEBUG_INFO("%s\n",ptr);
  15232. DEBUG_INFO("status=%d\n",status);
  15233. DEBUG_INFO("End Response ..\n");
  15234. return (bytes_received>0)?status:0;
  15235. }
  15236. //the only filed that it parsed is 'Content-Length'
  15237. int ParseHeader(int sock)
  15238. {
  15239. //char c;
  15240. char buff[1024]="",*ptr=buff+4;
  15241. int bytes_received;
  15242. DEBUG_INFO("Begin HEADER ..\n");
  15243. while((bytes_received = recv(sock, ptr, 1, 0))){
  15244. if(bytes_received==-1){
  15245. perror("Parse Header");
  15246. exit(1);
  15247. }
  15248. if(
  15249. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15250. (ptr[-1]=='\r') && (*ptr=='\n' )
  15251. ) break;
  15252. ptr++;
  15253. }
  15254. *ptr=0;
  15255. ptr=buff+4;
  15256. //printf("%s",ptr);
  15257. if(bytes_received){
  15258. ptr=strstr(ptr,"Content-Length:");
  15259. if(ptr){
  15260. sscanf(ptr,"%*s %d",&bytes_received);
  15261. }else
  15262. bytes_received=-1; //unknown size
  15263. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15264. }
  15265. DEBUG_INFO("End HEADER ..\n");
  15266. return bytes_received ;
  15267. }
  15268. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15269. {
  15270. int result = TRUE;
  15271. char rmFileCmd[100]={0};
  15272. char FilePath[100]={0};
  15273. char ftpbuf[200];
  15274. int systemresult;
  15275. sprintf(FilePath,"/mnt/%s",filename);
  15276. system("ping 8.8.8.8 &");
  15277. if((access(FilePath,F_OK))!=-1)
  15278. {
  15279. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15280. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15281. system(rmFileCmd);
  15282. }
  15283. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15284. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15285. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15286. systemresult = system(ftpbuf);
  15287. if(systemresult != 0)
  15288. {
  15289. DEBUG_INFO("http DownLoad error!\n");
  15290. result = FALSE;
  15291. }
  15292. system("pkill ping");
  15293. return result;
  15294. }
  15295. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15296. {
  15297. int result = TRUE;
  15298. char rmFileCmd[100]={0};
  15299. char FilePath[100]={0};
  15300. char ftpbuf[200];
  15301. int systemresult;
  15302. sprintf(FilePath,"/mnt/%s",filename);
  15303. system("ping 8.8.8.8 &");
  15304. if((access(FilePath,F_OK))!=-1)
  15305. {
  15306. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15307. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15308. system(rmFileCmd);
  15309. }
  15310. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15311. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15312. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15313. systemresult = system(ftpbuf);
  15314. if(systemresult != 0)
  15315. {
  15316. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15317. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15318. systemresult = system(ftpbuf);
  15319. if(systemresult != 0)
  15320. {
  15321. DEBUG_WARN("wget error!\n");
  15322. result = FALSE;
  15323. }
  15324. }
  15325. system("pkill ping");
  15326. return result;
  15327. }
  15328. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15329. {
  15330. char rmFileCmd[100]={0};
  15331. char FilePath[100]={0};
  15332. char buf[512];
  15333. int systemresult = 0;
  15334. //DEBUG_INFO("filename=%s\n",filename);
  15335. //DEBUG_INFO("url=%s\n",url);
  15336. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15337. if((access(FilePath,F_OK))!=-1)
  15338. {
  15339. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15340. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15341. system(rmFileCmd);
  15342. }
  15343. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15344. if(fp == NULL)
  15345. {
  15346. DEBUG_INFO("log is NULL\n");
  15347. return FALSE;
  15348. }
  15349. else
  15350. {
  15351. fprintf(fp, "%s\n", url);
  15352. fprintf(fp, "%s\n", filename);
  15353. fclose(fp);
  15354. }
  15355. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15356. if(phpFP == NULL)
  15357. {
  15358. DEBUG_INFO("PHP upload fail.\n");
  15359. return FALSE;
  15360. }
  15361. else
  15362. {
  15363. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15364. {
  15365. if(strstr(buf, "result") != NULL)
  15366. {
  15367. sscanf(buf, "result: %d", &systemresult);
  15368. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15369. }
  15370. }
  15371. pclose(phpFP);
  15372. }
  15373. if(systemresult != 1)
  15374. {
  15375. DEBUG_INFO("HTTP upload error!\n");
  15376. return FALSE;
  15377. }
  15378. return TRUE;
  15379. }
  15380. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15381. {
  15382. struct hostent* server;
  15383. char *IPbuffer;
  15384. char ftpbuf[200];
  15385. int systemresult;
  15386. // To retrieve host information
  15387. server = gethostbyname(location);
  15388. // To convert an Internet network
  15389. // address into ASCII string
  15390. IPbuffer = inet_ntoa(*((struct in_addr*)
  15391. server->h_addr_list[0]));
  15392. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15393. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15394. /* format : ftpput -u username -p passwd IP target source*/
  15395. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15396. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15397. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15398. systemresult = system(ftpbuf);
  15399. DEBUG_INFO("systemresult=%d\n",systemresult);
  15400. if(systemresult != 0)
  15401. {
  15402. DEBUG_INFO("ftpput error!\n");
  15403. return FALSE;
  15404. }
  15405. return TRUE;
  15406. }
  15407. int GetOcppServerURL()
  15408. {
  15409. int result = FALSE;
  15410. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15411. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15412. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15413. struct yuarel url;
  15414. char urlStr[512];
  15415. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15416. {
  15417. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15418. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15419. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15420. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15421. if(yuarel_parse(&url, urlStr) != -1)
  15422. {
  15423. sprintf(OcppProtocol, "%s", url.scheme);
  15424. sprintf(OcppHost, "%s", url.host);
  15425. if(url.path == NULL)
  15426. OcppTempPath[0] = '\0';
  15427. else
  15428. {
  15429. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15430. {
  15431. sprintf(OcppTempPath, "%s/", url.path);
  15432. }
  15433. else
  15434. {
  15435. sprintf(OcppTempPath, "%s", url.path);
  15436. }
  15437. }
  15438. if(url.port == 0)
  15439. {
  15440. if(strcmp(OcppProtocol, "wss") == 0)
  15441. OcppPort = 443;
  15442. else
  15443. OcppPort = 80;
  15444. }
  15445. else
  15446. OcppPort = url.port;
  15447. result = TRUE;
  15448. }
  15449. }
  15450. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15451. {
  15452. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15453. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15454. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15455. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15456. if(yuarel_parse(&url, urlStr) != -1)
  15457. {
  15458. sprintf(OcppProtocol, "%s", url.scheme);
  15459. sprintf(OcppHost, "%s", url.host);
  15460. if(url.path == NULL)
  15461. OcppTempPath[0] = '\0';
  15462. else
  15463. sprintf(OcppTempPath, "%s", url.path);
  15464. if(url.port == 0)
  15465. {
  15466. if(strcmp(OcppProtocol, "wss") == 0)
  15467. OcppPort = 443;
  15468. else
  15469. OcppPort = 80;
  15470. }
  15471. else
  15472. OcppPort = url.port;
  15473. result = TRUE;
  15474. }
  15475. }
  15476. else
  15477. {
  15478. strcpy(OcppHost,"");
  15479. }
  15480. return result;
  15481. }
  15482. int GetOcppPath()
  15483. {
  15484. int result = FALSE;
  15485. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15486. {
  15487. if(OcppTempPath == NULL)
  15488. {
  15489. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15490. }
  15491. else
  15492. {
  15493. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15494. }
  15495. result = TRUE;
  15496. goto End;
  15497. }
  15498. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15499. {
  15500. if(OcppTempPath == NULL)
  15501. {
  15502. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15503. }
  15504. else
  15505. {
  15506. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15507. }
  15508. result = TRUE;
  15509. goto End;
  15510. }
  15511. else
  15512. {
  15513. strcpy(OcppPath,"");
  15514. }
  15515. End:
  15516. return result;
  15517. }
  15518. int GetOcppPort()
  15519. {
  15520. return OcppPort;
  15521. }
  15522. int GetOcppConnStatus(void)
  15523. {
  15524. return ShmOCPP16Data->OcppConnStatus;
  15525. }
  15526. void SetOcppConnStatus(uint8_t status)
  15527. {
  15528. ShmOCPP16Data->OcppConnStatus = status;
  15529. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15530. }
  15531. int GetHeartBeatWithNOResponse(void)
  15532. {
  15533. return HeartBeatWithNOResponse;
  15534. }
  15535. void SetHeartBeatWithNOResponse(void)
  15536. {
  15537. HeartBeatWithNOResponse = 0;
  15538. }
  15539. void GetStartTransactionIdTag(int gun_index)
  15540. {
  15541. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15542. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15543. }
  15544. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15545. {
  15546. char ch;
  15547. FILE *fptr1;
  15548. int temptransactionId;
  15549. char str[100]={0};
  15550. temptransactionId = 0;
  15551. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15552. {
  15553. DEBUG_INFO("IdTag is empty.\n");
  15554. return temptransactionId;
  15555. }
  15556. /*------ Read the file ----------------*/
  15557. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15558. if (!fptr1)
  15559. {
  15560. DEBUG_INFO("QueueTransactionId file open error.\n");
  15561. //printf(" File not found or unable to open the input file!!\n");
  15562. return temptransactionId;
  15563. }
  15564. ch=fgetc(fptr1);
  15565. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15566. rewind(fptr1);
  15567. if(ch!=EOF)
  15568. {
  15569. // printf("%c",ch);
  15570. while (fgets(str, 100, fptr1) != NULL)
  15571. {
  15572. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15573. if(str[0]=='\0')
  15574. {
  15575. break;
  15576. }
  15577. char *revbuf[8] = {0}; // Variable store string split
  15578. int num = 0;// Quantity after string split
  15579. DEBUG_INFO("Transaction queue data= %s\n", str);
  15580. splitstring(str,",",revbuf,&num); // String split
  15581. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15582. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15583. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15584. DEBUG_INFO("------------------------------\n");
  15585. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15586. {
  15587. if(isStopTransaction)
  15588. {
  15589. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15590. {
  15591. temptransactionId = atoi(revbuf[2]);
  15592. //break;
  15593. }
  15594. }
  15595. else
  15596. {
  15597. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15598. {
  15599. temptransactionId = atoi(revbuf[2]);
  15600. //break;
  15601. }
  15602. }
  15603. }
  15604. }
  15605. }
  15606. else
  15607. DEBUG_INFO("EOF\n");
  15608. fclose(fptr1);
  15609. /*------- End of reading ---------------*/
  15610. return temptransactionId;
  15611. }
  15612. void SetTransactionIdZero(int transactionId)
  15613. {
  15614. char ch;
  15615. FILE *fptr1, *fptr2;
  15616. int temptransactionId = 0;
  15617. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15618. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15619. if (!fptr1)
  15620. {
  15621. //printf(" File not found or unable to open the input file!!\n");
  15622. return ;
  15623. }
  15624. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15625. if (!fptr2)
  15626. {
  15627. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15628. fclose(fptr1);
  15629. return ;
  15630. }
  15631. ch=fgetc(fptr1);
  15632. rewind(fptr1);
  15633. if(ch!=EOF)
  15634. {
  15635. // copy all contents to the temporary file except the specific line
  15636. while (fgets(str, 100, fptr1) != NULL)
  15637. {
  15638. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15639. if(str[0]=='\0')
  15640. {
  15641. break;
  15642. }
  15643. char *revbuf[8] = {0};
  15644. int num = 0;
  15645. strcpy(strtemp, str);
  15646. splitstring(str,",",revbuf,&num);
  15647. if(revbuf[2][0] != '\0')
  15648. {
  15649. temptransactionId = atoi(revbuf[2]);
  15650. if(transactionId != temptransactionId)
  15651. {
  15652. fprintf(fptr2, "%s\n", strtemp);
  15653. }
  15654. }
  15655. }
  15656. }
  15657. fclose(fptr1);
  15658. fclose(fptr2);
  15659. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15660. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15661. /*------ Read the file ----------------*/
  15662. }
  15663. int InternetDisconnect(void)
  15664. {
  15665. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15666. }
  15667. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15668. void storeTempStopTransaction(int gun_index)
  15669. {
  15670. char guid[37]={0};
  15671. int tempIndex = 0;
  15672. char TempStopTransaction[256];
  15673. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15674. DEBUG_INFO("storeTempStopTransaction...\n");
  15675. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15676. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15677. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15678. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15679. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15680. {
  15681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15682. {
  15683. tempIndex = ((gun_index==2) ? 1: 0);
  15684. }
  15685. else
  15686. {
  15687. tempIndex = gun_index;
  15688. }
  15689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15690. {
  15691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15692. {
  15693. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15694. }
  15695. }// END OF CHAdeMO_QUANTITY
  15696. }
  15697. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15698. {
  15699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15700. {
  15701. tempIndex = ((gun_index==2) ? 1: 0);
  15702. }
  15703. else
  15704. {
  15705. tempIndex = gun_index;
  15706. }
  15707. for (int index = 0; index < CCS_QUANTITY; index++)
  15708. {
  15709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15710. {
  15711. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15712. }
  15713. }// END OF CCS_QUANTITY
  15714. }
  15715. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15716. {
  15717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15718. {
  15719. tempIndex = ((gun_index==2) ? 1: 0);
  15720. }
  15721. else
  15722. {
  15723. tempIndex = gun_index;
  15724. }
  15725. for (int index = 0; index < GB_QUANTITY; index++)
  15726. {
  15727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15728. {
  15729. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15730. }
  15731. }// END OF GB_QUANTITY
  15732. }
  15733. else if(gunType[gun_index] == GUN_TYPE_DO)
  15734. {
  15735. tempIndex = gun_index;
  15736. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15737. {
  15738. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15739. {
  15740. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15741. }
  15742. }
  15743. }
  15744. else
  15745. {
  15746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15747. {
  15748. tempIndex = 2;
  15749. }
  15750. else
  15751. {
  15752. tempIndex = gun_index;
  15753. }
  15754. for (int index = 0; index < AC_QUANTITY; index++)
  15755. {
  15756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15757. {
  15758. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15759. }
  15760. }// END OF AC_QUANTITY
  15761. }
  15762. //Stop Transaction Time
  15763. struct timeval tmnow;
  15764. struct tm *tm;
  15765. char buf[28];//, usec_buf[6];
  15766. gettimeofday(&tmnow, NULL);
  15767. time_t t;
  15768. t = time(NULL);
  15769. /*UTC time and date*/
  15770. tm = gmtime(&t);
  15771. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15773. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15775. random_uuid(guid);
  15776. /***********************************transactionData******************************************************/
  15777. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15779. //=================================
  15780. //1. Transaction_Begin
  15781. //=================================
  15782. //============================== Energy.Active.Import.Interval ===========================================
  15783. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15784. {
  15785. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15788. 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*/]);
  15789. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15790. 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))
  15791. {
  15792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15793. }
  15794. else
  15795. {
  15796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15797. }
  15798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15800. }
  15801. //=================================
  15802. //2. Transaction_End
  15803. //=================================
  15804. //2.1====================================== Current.Import L1 ==============================================
  15805. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15806. {
  15807. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15808. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15809. {
  15810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15811. {
  15812. tempIndex = ((gun_index==2) ? 1: 0);
  15813. }
  15814. else
  15815. {
  15816. tempIndex = gun_index;
  15817. }
  15818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15819. {
  15820. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15821. {
  15822. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15823. }
  15824. }// End of for CHAdeMO_QUANTITY
  15825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15826. }
  15827. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15828. {
  15829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15830. {
  15831. tempIndex = ((gun_index==2) ? 1: 0);
  15832. }
  15833. else
  15834. {
  15835. tempIndex = gun_index;
  15836. }
  15837. for (int index = 0; index < CCS_QUANTITY; index++)
  15838. {
  15839. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15840. {
  15841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15842. }
  15843. }// End of for CCS_QUANTITY
  15844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15845. }
  15846. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15847. {
  15848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15849. {
  15850. tempIndex = ((gun_index==2) ? 1: 0);
  15851. }
  15852. else
  15853. {
  15854. tempIndex = gun_index;
  15855. }
  15856. for (int index = 0; index < GB_QUANTITY; index++)
  15857. {
  15858. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15859. {
  15860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15861. }
  15862. }// End of for GB_QUANTITY
  15863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15864. }
  15865. else if(gunType[gun_index] == GUN_TYPE_DO)
  15866. {
  15867. tempIndex = gun_index;
  15868. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15869. {
  15870. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15871. {
  15872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15873. }
  15874. }
  15875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15876. }
  15877. else
  15878. {
  15879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15880. {
  15881. tempIndex = 2;
  15882. }
  15883. else
  15884. {
  15885. tempIndex = gun_index;
  15886. }
  15887. for (int index = 0; index < AC_QUANTITY; index++)
  15888. {
  15889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15890. {
  15891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15892. }
  15893. }// End of for AC_QUANTITY
  15894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15895. }
  15896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15899. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15902. }
  15903. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15904. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15905. {
  15906. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15907. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15908. {
  15909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15910. {
  15911. tempIndex = ((gun_index==2) ? 1: 0);
  15912. }
  15913. else
  15914. {
  15915. tempIndex = gun_index;
  15916. }
  15917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15918. {
  15919. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15920. {
  15921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15922. }
  15923. }// END OF CHAdeMO_QUANTITY
  15924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15925. }
  15926. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15927. {
  15928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15929. {
  15930. tempIndex = ((gun_index==2) ? 1: 0);
  15931. }
  15932. else
  15933. {
  15934. tempIndex = gun_index;
  15935. }
  15936. for (int index = 0; index < CCS_QUANTITY; index++)
  15937. {
  15938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15939. {
  15940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15941. }
  15942. }// END OF CCS_QUANTITY
  15943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15944. }
  15945. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15946. {
  15947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15948. {
  15949. tempIndex = ((gun_index==2) ? 1: 0);
  15950. }
  15951. else
  15952. {
  15953. tempIndex = gun_index;
  15954. }
  15955. for (int index = 0; index < GB_QUANTITY; index++)
  15956. {
  15957. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15958. {
  15959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15960. }
  15961. }// END OF GB_QUANTITY
  15962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15963. }
  15964. else if(gunType[gun_index] == GUN_TYPE_DO)
  15965. {
  15966. tempIndex = gun_index;
  15967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15968. {
  15969. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15970. {
  15971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15972. }
  15973. }
  15974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15975. }
  15976. else
  15977. {
  15978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15979. {
  15980. tempIndex = 2;
  15981. }
  15982. else
  15983. {
  15984. tempIndex = gun_index;
  15985. }
  15986. for (int index = 0; index < AC_QUANTITY; index++)
  15987. {
  15988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15989. {
  15990. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15991. }
  15992. }// END OF AC_QUANTITY
  15993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15994. }
  15995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15998. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16001. }
  16002. //2.3====================================== Power.Active.Import =========================================
  16003. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16004. {
  16005. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16006. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16007. {
  16008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16009. {
  16010. tempIndex = ((gun_index==2) ? 1: 0);
  16011. }
  16012. else
  16013. {
  16014. tempIndex = gun_index;
  16015. }
  16016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16017. {
  16018. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16019. {
  16020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16021. }
  16022. } // End for CHAdeMO_QUANTITY
  16023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16024. }
  16025. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16026. {
  16027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16028. {
  16029. tempIndex = ((gun_index==2) ? 1: 0);
  16030. }
  16031. else
  16032. {
  16033. tempIndex = gun_index;
  16034. }
  16035. for (int index = 0; index < CCS_QUANTITY; index++)
  16036. {
  16037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16038. {
  16039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16040. }
  16041. } // END for CCS_QUANTITY
  16042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16043. }
  16044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16045. {
  16046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16047. {
  16048. tempIndex = ((gun_index==2) ? 1: 0);
  16049. }
  16050. else
  16051. {
  16052. tempIndex = gun_index;
  16053. }
  16054. for (int index = 0; index < GB_QUANTITY; index++)
  16055. {
  16056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16057. {
  16058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16059. }
  16060. }// END for GB_QUANTITY
  16061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16062. }
  16063. else if(gunType[gun_index] == GUN_TYPE_DO)
  16064. {
  16065. tempIndex = gun_index;
  16066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16067. {
  16068. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16069. {
  16070. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16071. }
  16072. }
  16073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16074. }
  16075. else
  16076. {
  16077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16078. {
  16079. tempIndex = 2;
  16080. }
  16081. else
  16082. {
  16083. tempIndex = gun_index;
  16084. }
  16085. for (int index = 0; index < AC_QUANTITY; index++)
  16086. {
  16087. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16088. {
  16089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16090. }
  16091. } // END for AC_QUANTITY
  16092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16093. }
  16094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16097. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16100. }
  16101. //2.4====================================== Voltage L1 ====================================================
  16102. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16103. {
  16104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16105. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16106. {
  16107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16108. {
  16109. tempIndex = ((gun_index==2) ? 1: 0);
  16110. }
  16111. else
  16112. {
  16113. tempIndex = gun_index;
  16114. }
  16115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16116. {
  16117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16118. {
  16119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16120. }
  16121. } // END OF FOR CHAdeMO_QUANTITY
  16122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16123. }
  16124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16125. {
  16126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16127. {
  16128. tempIndex = ((gun_index==2) ? 1: 0);
  16129. }
  16130. else
  16131. {
  16132. tempIndex = gun_index;
  16133. }
  16134. for (int index = 0; index < CCS_QUANTITY; index++)
  16135. {
  16136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16137. {
  16138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16139. }
  16140. } // END OF FOR CCS_QUANTITY
  16141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16142. }
  16143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16144. {
  16145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16146. {
  16147. tempIndex = ((gun_index==2) ? 1: 0);
  16148. }
  16149. else
  16150. {
  16151. tempIndex = gun_index;
  16152. }
  16153. for (int index = 0; index < GB_QUANTITY; index++)
  16154. {
  16155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16156. {
  16157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16158. }
  16159. } // END OF FOR GB_QUANTITY
  16160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16161. }
  16162. else if(gunType[gun_index] == GUN_TYPE_DO)
  16163. {
  16164. tempIndex = gun_index;
  16165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16166. {
  16167. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16168. {
  16169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16170. }
  16171. }
  16172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16173. }
  16174. else
  16175. {
  16176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16177. {
  16178. tempIndex = 2;
  16179. }
  16180. else
  16181. {
  16182. tempIndex = gun_index;
  16183. }
  16184. for (int index = 0; index < AC_QUANTITY; index++)
  16185. {
  16186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16187. {
  16188. 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
  16189. }
  16190. } // END OF FOR AC_QUANTITY
  16191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16192. }
  16193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16196. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16199. }
  16200. //2.5============================================== End SoC =========================================================
  16201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16202. {
  16203. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16204. 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))
  16205. {
  16206. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16207. {
  16208. tempIndex = ((gun_index==2) ? 1: 0);
  16209. }
  16210. else
  16211. {
  16212. tempIndex = gun_index;
  16213. }
  16214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16215. {
  16216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16217. {
  16218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16219. {
  16220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16221. }
  16222. }
  16223. }
  16224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16225. {
  16226. for (int index = 0; index < CCS_QUANTITY; index++)
  16227. {
  16228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16229. {
  16230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16231. }
  16232. }
  16233. }
  16234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16235. {
  16236. for (int index = 0; index < GB_QUANTITY; index++)
  16237. {
  16238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16239. {
  16240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16241. }
  16242. }
  16243. }
  16244. else if(gunType[gun_index] == GUN_TYPE_DO)
  16245. {
  16246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16247. {
  16248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16249. {
  16250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16251. }
  16252. }
  16253. }
  16254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16260. } // END FOR DC CASE
  16261. }
  16262. //2.6====================================== Current.Import L2 ==============================================
  16263. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16264. {
  16265. // AC 3 phase L2 current
  16266. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16267. {
  16268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16269. {
  16270. tempIndex = 2;
  16271. }
  16272. else
  16273. {
  16274. tempIndex = gun_index;
  16275. }
  16276. for (int index = 0; index < AC_QUANTITY; index++)
  16277. {
  16278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16279. {
  16280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16281. }
  16282. }// End of for AC_QUANTITY
  16283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16284. }
  16285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16290. }
  16291. //2.7====================================== Current.Import L3 ==============================================
  16292. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16293. {
  16294. // AC 3 phase L3 current
  16295. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16296. {
  16297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16298. {
  16299. tempIndex = 2;
  16300. }
  16301. else
  16302. {
  16303. tempIndex = gun_index;
  16304. }
  16305. for (int index = 0; index < AC_QUANTITY; index++)
  16306. {
  16307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16308. {
  16309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16310. }
  16311. }// End of for AC_QUANTITY
  16312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16313. }
  16314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16319. }
  16320. //2.9====================================== Voltage L2 ====================================================
  16321. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16322. {
  16323. // AC 3 phase L2 volatge
  16324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16325. {
  16326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16327. {
  16328. tempIndex = 2;
  16329. }
  16330. else
  16331. {
  16332. tempIndex = gun_index;
  16333. }
  16334. for (int index = 0; index < AC_QUANTITY; index++)
  16335. {
  16336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16337. {
  16338. 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
  16339. }
  16340. } // END OF FOR AC_QUANTITY
  16341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16342. }
  16343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16348. }
  16349. //2.10====================================== Voltage L3 ====================================================
  16350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16351. {
  16352. // AC 3 phase L3 volatge
  16353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16354. {
  16355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16356. {
  16357. tempIndex = 2;
  16358. }
  16359. else
  16360. {
  16361. tempIndex = gun_index;
  16362. }
  16363. for (int index = 0; index < AC_QUANTITY; index++)
  16364. {
  16365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16366. {
  16367. 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
  16368. }
  16369. } // END OF FOR AC_QUANTITY
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16371. }
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16377. }
  16378. //====================== Start SoC ================================
  16379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16380. {
  16381. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16382. 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))
  16383. {
  16384. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16385. {
  16386. tempIndex = ((gun_index==2) ? 1: 0);
  16387. }
  16388. else
  16389. {
  16390. tempIndex = gun_index;
  16391. }
  16392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16393. {
  16394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16395. {
  16396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16397. {
  16398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16399. }
  16400. }
  16401. }
  16402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16403. {
  16404. for (int index = 0; index < CCS_QUANTITY; index++)
  16405. {
  16406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16407. {
  16408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16409. }
  16410. }
  16411. }
  16412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16413. {
  16414. for (int index = 0; index < GB_QUANTITY; index++)
  16415. {
  16416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16417. {
  16418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16419. }
  16420. }
  16421. }
  16422. else if(gunType[gun_index] == GUN_TYPE_DO)
  16423. {
  16424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16425. {
  16426. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16427. {
  16428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16429. }
  16430. }
  16431. }
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16438. } // END FOR DC CASE
  16439. }
  16440. //======================================== Message create ==============================================
  16441. json_object *StopTransaction = json_object_new_object();
  16442. json_object *transactionDatas = json_object_new_array();
  16443. json_object *sampledValues = json_object_new_array();
  16444. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16445. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16446. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16447. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16448. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16449. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16450. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16451. {
  16452. json_object *transactionData = json_object_new_object();
  16453. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16454. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16455. {
  16456. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16457. {
  16458. json_object *sampledValue = json_object_new_object();
  16459. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16460. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16461. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16462. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16463. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16464. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16465. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16466. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16467. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16468. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16469. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16470. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16471. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16472. json_object_array_add(sampledValues, sampledValue);
  16473. }
  16474. }
  16475. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16476. json_object_array_add(transactionDatas, transactionData);
  16477. }
  16478. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16479. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16480. ,MESSAGE_TYPE_CALL
  16481. ,guid
  16482. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16483. json_object_put(StopTransaction);
  16484. // Check File "TempStopTransaction" Exist
  16485. if((access(TempStopTransaction,F_OK))!=-1)
  16486. {
  16487. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16488. fclose(fopen(TempStopTransaction, "w"));
  16489. }
  16490. else
  16491. {
  16492. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16493. FILE *log = fopen(TempStopTransaction, "w+");
  16494. if(log == NULL)
  16495. {
  16496. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16497. return ;
  16498. }
  16499. else
  16500. {
  16501. fclose(log);
  16502. }
  16503. }
  16504. //Add TempStopTransaction | Update TempStopTransaction
  16505. // open file for writing
  16506. FILE *outfile;
  16507. outfile = fopen (TempStopTransaction, "a");
  16508. //DEBUG_INFO("data = %s\n", queuedata);
  16509. fputs(queuedata, outfile);
  16510. fputs("\n", outfile);
  16511. fclose (outfile);
  16512. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16513. }
  16514. void checkTempStopTransaction(int gun_index)
  16515. {
  16516. FILE *fptr1;
  16517. char ch;
  16518. char str[QUEUE_MESSAGE_LENGTH]={0};
  16519. char guid[37]={0};
  16520. char tempdata[65]={0};
  16521. char connectorStr[2]={0};
  16522. char TempStopTransaction[256];
  16523. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16524. fptr1 = fopen(TempStopTransaction, "r");
  16525. //TempStopTransaction格式: 槍號,StopTransaction封包
  16526. if (!fptr1)
  16527. {
  16528. //printf(" File not found or unable to open the input file!!\n");
  16529. return ;
  16530. }
  16531. ch=fgetc(fptr1);
  16532. //printf(" Now the content of the file %s is : \n",fname);
  16533. rewind(fptr1);
  16534. if(ch!=EOF)
  16535. {
  16536. // copy all contents to the temporary file except the specific line
  16537. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16538. {
  16539. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16540. if(str[0]=='\0')
  16541. {
  16542. break;
  16543. }
  16544. //TempStopTransaction格式: 槍號,StopTransaction封包
  16545. strncpy(connectorStr, str, 1);
  16546. if(atoi(connectorStr) != (gun_index+1))
  16547. {
  16548. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16549. fclose(fptr1);
  16550. return ;
  16551. }
  16552. //random_uuid(guid);
  16553. strncpy(guid, str+6, 36); //copy guid
  16554. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16555. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16556. {
  16557. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16558. }
  16559. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16560. OCPP_insert_transaction_msg(NO, str);
  16561. memset(str,0,ARRAY_SIZE(str));
  16562. }
  16563. }
  16564. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16565. fclose(fptr1);
  16566. remove(TempStopTransaction); // remove the original file
  16567. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16568. }
  16569. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16570. {
  16571. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16572. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16573. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16574. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16575. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16576. }
  16577. int GetWebSocketPingInterval(void)
  16578. {
  16579. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16580. }
  16581. int GetServerSign(void)
  16582. {
  16583. return server_sign;
  16584. }
  16585. uint8_t GetOcppSecurityProfile()
  16586. {
  16587. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16588. }
  16589. void GetOcppChargerBoxId(uint8_t *data)
  16590. {
  16591. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16592. }
  16593. void GetOcppSecurityPassword(uint8_t *data)
  16594. {
  16595. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16596. }
  16597. void SetOcppVersion(uint8_t *version)
  16598. {
  16599. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16600. DEBUG_INFO("ocpp version: %s\n", version);
  16601. if(strstr((char*)version, "ocpp1.6") != NULL)
  16602. {
  16603. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16604. }
  16605. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16606. {
  16607. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16608. system("pkill OcppBackend");
  16609. }
  16610. }
  16611. void SetServerSign(int value)
  16612. {
  16613. server_sign = value;
  16614. }
  16615. int GetBootNotificationInterval(void)
  16616. {
  16617. return BootNotificationInterval;
  16618. }
  16619. int GetInternetConn(void)
  16620. {
  16621. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16622. }
  16623. int GetBackendConnectionTimeout(void)
  16624. {
  16625. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16626. }
  16627. int isConnectorInitMode(int gun_index)
  16628. {
  16629. int tempIndex = 0;
  16630. int result = TRUE;
  16631. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16632. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16633. {
  16634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16635. {
  16636. tempIndex = ((gun_index==2) ? 1: 0);
  16637. }
  16638. else
  16639. {
  16640. tempIndex = gun_index;
  16641. }
  16642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16643. {
  16644. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16645. {
  16646. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16647. } //end of the same index
  16648. }//end of for CHAdeMO_QUANTITY
  16649. }
  16650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16651. {
  16652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16653. {
  16654. tempIndex = ((gun_index==2) ? 1: 0);
  16655. }
  16656. else
  16657. {
  16658. tempIndex = gun_index;
  16659. }
  16660. for (int index = 0; index < CCS_QUANTITY; index++)
  16661. {
  16662. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16663. {
  16664. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16665. } //end of the same index
  16666. } // end of for CCS_QUANTITY
  16667. }
  16668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16669. {
  16670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16671. {
  16672. tempIndex = ((gun_index==2) ? 1: 0);
  16673. }
  16674. else
  16675. {
  16676. tempIndex = gun_index;
  16677. }
  16678. for (int index = 0; index < GB_QUANTITY; index++)
  16679. {
  16680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16681. {
  16682. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16683. } //end of the same index
  16684. } // end of for GB_QUANTITY
  16685. }
  16686. else if(gunType[gun_index] == GUN_TYPE_DO)
  16687. {
  16688. tempIndex = gun_index;
  16689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16690. {
  16691. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16692. {
  16693. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16694. } //end of the same index
  16695. }
  16696. }
  16697. else
  16698. {
  16699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16700. {
  16701. tempIndex = 2;
  16702. }
  16703. else
  16704. {
  16705. tempIndex = gun_index;
  16706. }
  16707. for (int index = 0; index < AC_QUANTITY; index++)
  16708. {
  16709. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16710. {
  16711. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16712. }//end of the same index
  16713. }//end of for AC_QUANTITY
  16714. }
  16715. return result;
  16716. }
  16717. void refreshProcDogTimer()
  16718. {
  16719. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16720. }
  16721. void InitialSystemValue(void)
  16722. {
  16723. int connectorIndex = 0;
  16724. //int valueASCII = 0;
  16725. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16726. gunTotalNumber=0;
  16727. SystemInitial = 0;
  16728. locallistVersion=0;
  16729. BootNotificationInterval = 0;
  16730. authorizeRetryTimes = 0;
  16731. GunStatusInterval = 10;
  16732. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16733. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16734. //Hear Beat
  16735. HeartBeatWithNOResponse = 0;
  16736. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16737. FirstHeartBeat = 0;
  16738. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16739. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16740. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16741. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16742. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16743. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16744. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16745. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16746. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16747. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16748. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16749. memset(gunType, 0, ARRAY_SIZE(gunType));
  16750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16751. {
  16752. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16753. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16754. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16755. {
  16756. // DO series
  16757. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16758. {
  16759. SystemInitial = SystemInitial + 1;
  16760. gunTotalNumber = gunTotalNumber + 1;
  16761. gunType[connectorIndex] = GUN_TYPE_DO;
  16762. connectorIndex = connectorIndex + 1;
  16763. }
  16764. }
  16765. else
  16766. {
  16767. // DM, DW, DS series
  16768. //check connector / socket type (index: 8, 9, 10)
  16769. for(int index=7; index <10 ; index++)
  16770. {
  16771. if(index != 8)
  16772. {
  16773. // DC Connector
  16774. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16775. {
  16776. SystemInitial = SystemInitial + 1;
  16777. gunTotalNumber = gunTotalNumber + 1;
  16778. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16779. connectorIndex = connectorIndex + 1;
  16780. }
  16781. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16782. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16783. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16784. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16785. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16786. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16787. {
  16788. SystemInitial = SystemInitial + 1;
  16789. gunTotalNumber = gunTotalNumber + 1;
  16790. gunType[connectorIndex] = GUN_TYPE_CCS;
  16791. connectorIndex = connectorIndex + 1;
  16792. }
  16793. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16794. {
  16795. SystemInitial = SystemInitial + 1;
  16796. gunTotalNumber = gunTotalNumber + 1;
  16797. gunType[connectorIndex] = GUN_TYPE_GBT;
  16798. connectorIndex = connectorIndex + 1;
  16799. }
  16800. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16801. {
  16802. SystemInitial = SystemInitial + 1;
  16803. gunTotalNumber = gunTotalNumber + 1;
  16804. gunType[connectorIndex] = GUN_TYPE_DO;
  16805. connectorIndex = connectorIndex + 1;
  16806. }
  16807. }
  16808. else
  16809. {
  16810. // AC Connector
  16811. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16812. {
  16813. SystemInitial = SystemInitial + 1;
  16814. gunTotalNumber = gunTotalNumber + 1;
  16815. gunType[connectorIndex] = GUN_TYPE_AC;
  16816. connectorIndex = connectorIndex + 1;
  16817. }
  16818. }
  16819. }
  16820. }
  16821. //DEBUG_INFO("DC ...\n");
  16822. }
  16823. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16824. {
  16825. //check connector / socket type (index: 8, 9, 10)
  16826. for(int index=7; index <10 ; index++)
  16827. {
  16828. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16829. {
  16830. SystemInitial = SystemInitial + 1;
  16831. gunTotalNumber = gunTotalNumber + 1;
  16832. gunType[connectorIndex] = GUN_TYPE_AC;
  16833. connectorIndex = connectorIndex + 1;
  16834. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16835. }
  16836. }
  16837. }
  16838. //Status && ConnectorPlugIn Setting
  16839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16840. {
  16841. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16842. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16843. }
  16844. for (int index = 0; index < CCS_QUANTITY; index++)
  16845. {
  16846. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16847. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16848. }
  16849. for (int index = 0; index < GB_QUANTITY; index++)
  16850. {
  16851. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16852. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16853. }
  16854. for (int index = 0; index < AC_QUANTITY; index++)
  16855. {
  16856. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16857. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16858. }
  16859. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16860. {
  16861. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16862. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16863. }
  16864. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16865. {
  16866. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16867. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16868. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16869. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16870. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16871. }
  16872. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16873. clientTime.Heartbeat=time((time_t*)NULL);
  16874. sleep(1);
  16875. }
  16876. void LWS_Send(char *str)
  16877. {
  16878. //=====================================================
  16879. // Check InternetConn 0: disconnected, 1: connected
  16880. //====================================================
  16881. if(GetOcppConnStatus() == 0)
  16882. {
  16883. DEBUG_INFO("offline now !!!\n");
  16884. return;
  16885. }
  16886. // Only disable isWebsocketSendable operation initiated by charger
  16887. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16888. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16889. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16890. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16891. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16892. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16893. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16894. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16895. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16896. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16897. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16898. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16899. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16900. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16901. {
  16902. isWebsocketSendable = 0;
  16903. }
  16904. pthread_mutex_lock(&lock_send);
  16905. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16906. sprintf((char *)SendBuffer, "%s", str);
  16907. SendBufLen = strlen(str);
  16908. pthread_mutex_unlock(&lock_send);
  16909. lws_callback_on_writable(wsi_client);
  16910. //lws_service(context, 0);
  16911. //sleep(1);
  16912. }
  16913. void LWS_SendNow(char *str)
  16914. {
  16915. //=====================================================
  16916. // Check InternetConn 0: disconnected, 1: connected
  16917. //====================================================
  16918. if(GetOcppConnStatus() == 0)
  16919. {
  16920. DEBUG_INFO("offline now !!!\n");
  16921. return;
  16922. }
  16923. // Only disable isWebsocketSendable operation initiated by charger
  16924. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16925. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16926. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16927. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16928. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16929. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16930. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16931. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16932. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16933. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16934. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16935. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16936. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16937. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16938. {
  16939. isWebsocketSendable = 0;
  16940. }
  16941. pthread_mutex_lock(&lock_send);
  16942. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16943. sprintf((char *)SendBuffer, "%s", str);
  16944. SendBufLen = strlen(str);
  16945. pthread_mutex_unlock(&lock_send);
  16946. lws_callback_on_writable(wsi_client);
  16947. lws_service(context, 0);
  16948. //sleep(1);
  16949. }