MessageHandler.c 776 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char :4; //bit 4~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Save configuration
  355. //=========================================
  356. int runShellCmd(const char*cmd)
  357. {
  358. int result = FAIL;
  359. char buf[256];
  360. FILE *fp;
  361. fp = popen(cmd, "r");
  362. if(fp != NULL)
  363. {
  364. while(fgets(buf, sizeof(buf), fp) != NULL)
  365. {
  366. DEBUG_INFO("%s\n", buf);
  367. }
  368. result = PASS;
  369. }
  370. pclose(fp);
  371. return result;
  372. }
  373. int StoreUsrConfigData(struct SysConfigData *UsrData)
  374. {
  375. int result = PASS;
  376. int fd,wrd;
  377. unsigned int i,Chk;
  378. unsigned char *ptr, *BufTmp;
  379. int MtdBlockSize = 0x300000;
  380. Chk=0;
  381. ptr=(unsigned char *)UsrData;
  382. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  383. {
  384. memset(BufTmp,0,MtdBlockSize);
  385. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  386. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  387. Chk+=*(BufTmp+i);
  388. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  389. // Output configuration to file.
  390. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  391. if (fd < 0)
  392. {
  393. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  394. free(BufTmp);
  395. return 0;
  396. }
  397. wrd=write(fd, BufTmp, MtdBlockSize);
  398. close(fd);
  399. if(wrd<MtdBlockSize)
  400. {
  401. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  406. DEBUG_INFO("Erase /dev/mtd10.\n");
  407. runShellCmd("flash_erase /dev/mtd10 0 0");
  408. DEBUG_INFO("Write /dev/mtd10.\n");
  409. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  410. DEBUG_INFO("Erase /dev/mtd11.\n");
  411. runShellCmd("flash_erase /dev/mtd11 0 0");
  412. DEBUG_INFO("Write /dev/mtd11.\n");
  413. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  414. system("rm -f /mnt/EvseConfig.bin");
  415. DEBUG_INFO("EvseConfig write to flash OK\n");
  416. }
  417. else
  418. {
  419. DEBUG_ERROR("alloc BlockSize NG\r\n");
  420. result = FAIL;
  421. }
  422. if(BufTmp!=NULL)
  423. free(BufTmp);
  424. return result;
  425. }
  426. //=========================================
  427. // Sqlite3 related function
  428. //=========================================
  429. static int selectSqlCount = 0;
  430. static int callback(void *data, int argc, char **argv, char **azColName){
  431. int i;
  432. //printf("%s: ", (const char*)data);
  433. selectSqlCount = argc;
  434. for(i = 0; i<argc; i++){
  435. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  436. }
  437. //printf("\n");
  438. return 0;
  439. }
  440. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  441. //int i;
  442. //printf("%s:\n", (const char*)data);
  443. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  444. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  445. return 0;
  446. }
  447. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  448. //printf("%s:\n", (const char*)data);
  449. //idTag
  450. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  451. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. //parentIdTag
  453. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  454. //expir_date
  455. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  456. //status
  457. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  458. //version
  459. if(columenCount > 5)
  460. idTagQuery.listVersionInt = atoi(columnValue[5]);
  461. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  462. return 0;
  463. }
  464. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  465. {
  466. // localversion = argv[5] ? atoi(argv[5]) : 0;
  467. // printf("localversion=%d\n", localversion);
  468. return 0;
  469. }
  470. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  471. {
  472. for (int i = 0; i < n_columns; i++)
  473. {
  474. DEBUG_INFO("%s\t", col_values[i]);
  475. }
  476. DEBUG_INFO("\n");
  477. return 0;
  478. }
  479. int OCPP_cleanLocalCache()
  480. {
  481. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  482. char *errMsg = 0;
  483. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  484. if (SQLITE_OK != rc)
  485. {
  486. DEBUG_INFO("SQL error: %s\n",errMsg);
  487. return FALSE;
  488. }
  489. return TRUE;
  490. }
  491. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  492. {
  493. int isSuccess = TRUE;
  494. int ret = 0;
  495. //const char* data = "Callback function called";
  496. char sql[300];
  497. char zErrMsg[200];
  498. memset(sql, 0, 300);
  499. memset(zErrMsg, 0, 200);
  500. 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);
  501. //* Execute SQL statement */
  502. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  503. if( ret != SQLITE_OK )
  504. {
  505. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  506. isSuccess = FALSE;
  507. }
  508. return isSuccess;
  509. }
  510. void OCPP_getIdTagFromLocalCache(char idTag[])
  511. {
  512. int rc = 0;
  513. char sql[100];
  514. char zErrMsg[100];
  515. memset(sql, 0, 100);
  516. memset(zErrMsg, 0, 100);
  517. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  518. memset(&idTagQuery, 0, sizeof(idTagQuery));
  519. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  520. /* Execute SQL statement */
  521. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  522. if( rc != SQLITE_OK )
  523. {
  524. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  525. }
  526. }
  527. void OCPP_getListVerion()
  528. {
  529. int rc = 0;
  530. // const char* data = "Callback function called";
  531. char sql[100];
  532. char zErrMsg[100];
  533. memset(sql, 0, 100);
  534. memset(zErrMsg, 0, 100);
  535. strcpy(sql, "select * from ocpp_auth_local order by idx");
  536. /* Execute SQL statement */
  537. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  538. if( rc != SQLITE_OK )
  539. {
  540. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  541. }
  542. }
  543. void OCPP_get_TableAuthlocalAllData(void)
  544. {
  545. int rc = 0;
  546. char sql[100];
  547. char zErrMsg[100];
  548. memset(sql, 0, 100);
  549. memset(zErrMsg, 0, 100);
  550. sprintf(sql,"select * from ocpp_auth_local ");
  551. /* Execute SQL statement */
  552. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  553. if( rc != SQLITE_OK )
  554. {
  555. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  556. }
  557. //return ver;
  558. }
  559. int OCPP_cleanLocalList()
  560. {
  561. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  562. char *errMsg = 0;
  563. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  564. if (SQLITE_OK != rc)
  565. {
  566. DEBUG_INFO("%s\n",errMsg);
  567. return FALSE;
  568. }
  569. return TRUE;
  570. }
  571. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  572. {
  573. int isSuccess = FALSE;
  574. int ret = 0;
  575. //const char* data = "Callback function called";
  576. char sql[300];
  577. char zErrMsg[200];
  578. memset(sql, 0, 300);
  579. memset(zErrMsg, 0, 200);
  580. 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);
  581. //* Execute SQL statement */
  582. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  583. if( ret != SQLITE_OK )
  584. {
  585. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  586. return isSuccess;
  587. }
  588. memset(sql, 0, 300);
  589. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  590. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. isSuccess = TRUE;
  597. return isSuccess;
  598. }
  599. void OCPP_getIdTagFromLocalList(char idTag[])
  600. {
  601. int rc = 0;
  602. // const char* data = "Callback function called";
  603. char sql[100];
  604. char zErrMsg[100];
  605. memset(sql, 0, 100);
  606. memset(zErrMsg, 0, 100);
  607. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  608. memset(&idTagQuery, 0, sizeof(idTagQuery));
  609. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  610. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  611. /* Execute SQL statement */
  612. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  613. if( rc != SQLITE_OK )
  614. {
  615. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  616. }
  617. //return ver;
  618. }
  619. void OCPP_deleteIdTagFromLocalList(char idTag[])
  620. {
  621. //int ver = 0;
  622. //int isSuccess = FALSE;
  623. int rc = 0;
  624. char sql[100];
  625. char zErrMsg[100];
  626. memset(sql, 0, 100);
  627. memset(zErrMsg, 0, 100);
  628. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  629. //* Execute SQL statement */
  630. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  631. if( rc != SQLITE_OK )
  632. {
  633. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  634. }
  635. }
  636. int getCurrentYear()
  637. {
  638. int result = 0;
  639. time_t CurrentTime;
  640. struct tm *tm;
  641. CurrentTime = time(NULL);
  642. tm=localtime(&CurrentTime);
  643. result = (tm->tm_year + 1900);
  644. return result;
  645. }
  646. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  647. {
  648. int result = PASS;
  649. char* errMsg = NULL;
  650. char sqlStr[8192];
  651. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  652. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  653. {
  654. result = FAIL;
  655. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  656. }
  657. 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));
  658. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  659. {
  660. result = FAIL;
  661. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  662. }
  663. return result;
  664. }
  665. //==========================================
  666. // Check time passed since today
  667. //==========================================
  668. long long DiffTimebWithNow(struct timeb ST)
  669. {
  670. //return milli-second
  671. struct timeb ET;
  672. long long StartTime,StopTime;
  673. ftime(&ET);
  674. StartTime=(long long)ST.time;
  675. StopTime=(long long)ET.time;
  676. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  677. }
  678. int getTimePassSinceToday(uint8_t gun_index)
  679. {
  680. int result = -1;
  681. static time_t lastTime[4];
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime[gun_index])>0)
  687. {
  688. tmStartToday=localtime(&t);
  689. tmStartToday->tm_hour = 0;
  690. tmStartToday->tm_min = 0;
  691. tmStartToday->tm_sec = 0;
  692. tbStartToday.time = mktime(tmStartToday);
  693. tbStartToday.millitm = 0;
  694. result = DiffTimebWithNow(tbStartToday)/1000;
  695. lastTime[gun_index] = t;
  696. }
  697. return result;
  698. }
  699. void getNowDatetime(uint8_t *data)
  700. {
  701. time_t t = time(NULL);
  702. struct tm tm = *localtime(&t);
  703. 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);
  704. }
  705. int syncDateTimeRTC(uint8_t *data)
  706. {
  707. struct ParsingResult
  708. {
  709. int result;
  710. int scanedElement;
  711. int year;
  712. int month;
  713. int mday;
  714. int hour;
  715. int min;
  716. int sec;
  717. int tz_hour;
  718. int tz_min;
  719. float minSec;
  720. }result;
  721. struct tm tmOrg;
  722. struct tm *tmTarget;
  723. struct timeb tbTarget;
  724. char buf[128];
  725. memset(&result, 0x00, sizeof(struct ParsingResult));
  726. result.result = PASS;
  727. if(strstr((char*)data, ".") != NULL)
  728. {
  729. // Original data with mini second
  730. if(strstr((char*)data, "Z") != NULL)
  731. {
  732. // Original data with Z
  733. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  734. &result.year,
  735. &result.month,
  736. &result.mday,
  737. &result.hour,
  738. &result.min,
  739. &result.sec,
  740. &result.minSec);
  741. }
  742. else
  743. {
  744. // Original data without Z
  745. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  746. &result.year,
  747. &result.month,
  748. &result.mday,
  749. &result.hour,
  750. &result.min,
  751. &result.sec,
  752. &result.minSec,
  753. &result.tz_hour,
  754. &result.tz_min);
  755. }
  756. }
  757. else
  758. {
  759. // Original data without mini second
  760. if(strstr((char*)data, "Z") != NULL)
  761. {
  762. // Original data with Z
  763. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  764. &result.year,
  765. &result.month,
  766. &result.mday,
  767. &result.hour,
  768. &result.min,
  769. &result.sec);
  770. }
  771. else
  772. {
  773. // Original data without Z
  774. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  775. &result.year,
  776. &result.month,
  777. &result.mday,
  778. &result.hour,
  779. &result.min,
  780. &result.sec,
  781. &result.tz_hour,
  782. &result.tz_min);
  783. }
  784. }
  785. tmOrg.tm_year = result.year - 1900;
  786. tmOrg.tm_mon = result.month - 1;
  787. tmOrg.tm_mday = result.mday;
  788. tmOrg.tm_hour = result.hour;
  789. tmOrg.tm_min = result.min;
  790. tmOrg.tm_sec = result.sec;
  791. tmOrg.tm_gmtoff = 0;
  792. tbTarget.time = mktime(&tmOrg);
  793. tbTarget.timezone = 0;
  794. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  795. tmTarget = gmtime(&tbTarget.time);
  796. 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);
  797. //DEBUG_INFO(" org date time: %s\n", data);
  798. //DEBUG_INFO("parse date time: %s\n", buf);
  799. system(buf);
  800. system("/sbin/hwclock -w --systohc");
  801. if(result.scanedElement < 6)
  802. result.result = FAIL;
  803. return result.result;
  804. }
  805. //==========================================
  806. // GetCompositeSchedule logic related function
  807. //==========================================
  808. int DiffTimebSec(struct timeb ST, struct timeb ET)
  809. {
  810. //return milli-second
  811. unsigned int StartTime,StopTime;
  812. StartTime=(unsigned int)ST.time;
  813. StopTime=(unsigned int)ET.time;
  814. return (StopTime-StartTime);
  815. }
  816. int DiffTimebWithNowSec(struct timeb ST)
  817. {
  818. //return milli-second
  819. struct timeb ET;
  820. unsigned int StartTime,StopTime;
  821. ftime(&ET);
  822. StartTime=(unsigned int)ST.time;
  823. StopTime=(unsigned int)ET.time;
  824. return (StopTime-StartTime);
  825. }
  826. int getStartStop(uint8_t *start, uint8_t *stop)
  827. {
  828. int result = -1;
  829. struct tm tmStart;
  830. struct timeb tbStart;
  831. struct tm tmStop;
  832. struct timeb tbStop;
  833. 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) &&
  834. (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))
  835. {
  836. //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);
  837. //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);
  838. tmStart.tm_year -= 1900;
  839. tmStart.tm_mon -= 1;
  840. tbStart.time = mktime(&tmStart);
  841. tbStart.millitm = 0;
  842. tmStop.tm_year -= 1900;
  843. tmStop.tm_mon -= 1;
  844. tbStop.time = mktime(&tmStop);
  845. tbStop.millitm = 0;
  846. result = DiffTimebSec(tbStart, tbStop);
  847. //DEBUG_INFO("getStartStop(): %d\n", result);
  848. }
  849. else
  850. {
  851. DEBUG_WARN("Start or stop date parsing error.\r\n");
  852. }
  853. return result;
  854. }
  855. int isOvertNow(uint8_t *start)
  856. {
  857. int result = NO;
  858. struct tm tmStart;
  859. struct timeb tbStart;
  860. 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))
  861. {
  862. //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);
  863. tmStart.tm_year -= 1900;
  864. tmStart.tm_mon -= 1;
  865. tbStart.time = mktime(&tmStart);
  866. tbStart.millitm = 0;
  867. if(DiffTimebWithNowSec(tbStart) <= 0)
  868. result = NO;
  869. else
  870. result = YES;
  871. }
  872. else
  873. {
  874. DEBUG_WARN("Start date parsing error.\n");
  875. }
  876. return result;
  877. }
  878. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  879. {
  880. int result = -1;
  881. struct tm tmStart;
  882. struct timeb tbStart;
  883. struct tm tmStop;
  884. struct timeb tbStop;
  885. 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) &&
  886. (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))
  887. {
  888. tmStart.tm_year -= 1900;
  889. tmStart.tm_mon -= 1;
  890. tbStart.time = mktime(&tmStart);
  891. tbStart.millitm = 0;
  892. tmStop.tm_year -= 1900;
  893. tmStop.tm_mon -= 1;
  894. tbStop.time = mktime(&tmStop);
  895. tbStop.millitm = 0;
  896. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  897. }
  898. return result;
  899. }
  900. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  901. {
  902. FILE *fp;
  903. char profileFileName[128];
  904. char *line = NULL;
  905. size_t len = 0;
  906. time_t CurrentTime;
  907. struct tm *tmComposite;
  908. struct StructChargingProfile maxProfile;
  909. struct StructChargingProfile defaultTxProfile;
  910. struct StructChargingProfile txProfile;
  911. struct StructChargingSchedulePeriod tmpPeriod;
  912. uint8_t limitMax=0;
  913. uint8_t limitDef=0;
  914. uint8_t limitTx=0;
  915. int compositePeriodIdx = 0;
  916. CurrentTime = time(NULL);
  917. tmComposite=localtime(&CurrentTime);
  918. 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);
  919. if(isUnitA)
  920. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  921. else
  922. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  923. compositeProfile->ChargingSchedule.Duration = durationReq;
  924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  925. {
  926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  929. }
  930. compositeProfile->ChargingProfileId = 0;
  931. compositeProfile->StackLevel = 99 ;
  932. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  933. maxProfile.ChargingProfileId = -1;
  934. defaultTxProfile.ChargingProfileId = -1;
  935. txProfile.ChargingProfileId = -1;
  936. maxProfile.ChargingSchedule.Duration = -1;
  937. defaultTxProfile.ChargingSchedule.Duration = -1;
  938. txProfile.ChargingSchedule.Duration = -1;
  939. system("rm -f /tmp/*.json");
  940. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  941. /*
  942. * Search valid charging profile
  943. */
  944. //DEBUG_INFO("====================================\n");
  945. // Search tx profile
  946. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  947. if((access(profileFileName, F_OK))!=-1)
  948. {
  949. fp = fopen(profileFileName, "r");
  950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  951. {
  952. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  955. }
  956. txProfile.ChargingProfileId = -1;
  957. txProfile.StackLevel = -1;
  958. while(getline(&line, &len, fp) != -1)
  959. {
  960. json_object *obj = NULL;
  961. obj = json_tokener_parse(line);
  962. if(is_error(obj))
  963. {
  964. DEBUG_ERROR("Parse txProfile from file error.\n");
  965. }
  966. else
  967. {
  968. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  969. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  970. )
  971. {
  972. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  973. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  974. )
  975. {
  976. struct tm tmFrom, tmTo;
  977. struct timeb tbFrom, tbTo;
  978. 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) &&
  979. (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))
  980. {
  981. tmFrom.tm_year -= 1900;
  982. tmFrom.tm_mon -= 1;
  983. tbFrom.time = mktime(&tmFrom);
  984. tmTo.tm_year -= 1900;
  985. tmTo.tm_mon -= 1;
  986. tbTo.time = mktime(&tmTo);
  987. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  988. {
  989. if(txProfile.ChargingProfileId == -1)
  990. DEBUG_INFO("TxProfile found.\n");
  991. else
  992. DEBUG_INFO("TxProfile updated.\n");
  993. // Required item
  994. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  995. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  996. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  997. if(isUnitA)
  998. {
  999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1000. 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++)
  1001. {
  1002. 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"));
  1003. 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?
  1004. 3:
  1005. 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")));
  1006. 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")));
  1007. }
  1008. }
  1009. else
  1010. {
  1011. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1012. 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++)
  1013. {
  1014. 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"));
  1015. 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?
  1016. 3:
  1017. 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")));
  1018. 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));
  1019. }
  1020. }
  1021. // Optional item
  1022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1023. {
  1024. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1025. }
  1026. else
  1027. {
  1028. sprintf((char*)txProfile.ValidFrom, " ");
  1029. }
  1030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1031. {
  1032. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1033. }
  1034. else
  1035. {
  1036. sprintf((char*)txProfile.ValidTo, " ");
  1037. }
  1038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1039. {
  1040. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1041. }
  1042. else
  1043. {
  1044. sprintf((char*)txProfile.RecurrencyKind, " ");
  1045. }
  1046. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1047. {
  1048. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1049. }
  1050. else
  1051. {
  1052. txProfile.TransactionId = -1;
  1053. }
  1054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1055. {
  1056. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1057. }
  1058. else
  1059. {
  1060. txProfile.ChargingSchedule.Duration = 86400;
  1061. }
  1062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1063. {
  1064. 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")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1069. }
  1070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1071. {
  1072. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1073. }
  1074. else
  1075. {
  1076. txProfile.ChargingSchedule.MinChargingRate = -1;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if(txProfile.ChargingProfileId == -1)
  1084. DEBUG_INFO("TxProfile found.\n");
  1085. else
  1086. DEBUG_INFO("TxProfile updated.\n");
  1087. // Required item
  1088. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1089. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1090. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1091. if(isUnitA)
  1092. {
  1093. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1094. 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++)
  1095. {
  1096. 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"));
  1097. 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?
  1098. 3:
  1099. 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")));
  1100. 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")));
  1101. }
  1102. }
  1103. else
  1104. {
  1105. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1106. 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++)
  1107. {
  1108. 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"));
  1109. 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?
  1110. 3:
  1111. 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")));
  1112. 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));
  1113. }
  1114. }
  1115. // Optional item
  1116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1117. {
  1118. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)txProfile.ValidFrom, " ");
  1123. }
  1124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1125. {
  1126. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1127. }
  1128. else
  1129. {
  1130. sprintf((char*)txProfile.ValidTo, " ");
  1131. }
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1133. {
  1134. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)txProfile.RecurrencyKind, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1141. {
  1142. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1143. }
  1144. else
  1145. {
  1146. txProfile.TransactionId = -1;
  1147. }
  1148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1149. {
  1150. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1151. }
  1152. else
  1153. {
  1154. txProfile.ChargingSchedule.Duration = 86400;
  1155. }
  1156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1157. {
  1158. 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")));
  1159. }
  1160. else
  1161. {
  1162. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1165. {
  1166. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1167. }
  1168. else
  1169. {
  1170. txProfile.ChargingSchedule.MinChargingRate = -1;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. json_object_put(obj);
  1176. }
  1177. fclose(fp);
  1178. /*
  1179. if(txProfile.ChargingProfileId != -1)
  1180. {
  1181. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1182. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1183. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1184. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1185. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1186. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1187. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1188. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1189. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1190. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1191. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1192. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1193. {
  1194. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1195. {
  1196. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1197. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1198. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1199. }
  1200. }
  1201. }
  1202. else
  1203. DEBUG_INFO("TxProfile not found.\n");*/
  1204. }
  1205. // Search default tx profile
  1206. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1207. if((access(profileFileName, F_OK))==-1)
  1208. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1209. if((access(profileFileName, F_OK))!=-1)
  1210. {
  1211. fp = fopen(profileFileName, "r");
  1212. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1213. {
  1214. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1217. }
  1218. defaultTxProfile.ChargingProfileId = -1;
  1219. defaultTxProfile.StackLevel = -1;
  1220. while(getline(&line, &len, fp) != -1)
  1221. {
  1222. json_object *obj = NULL;
  1223. obj = json_tokener_parse(line);
  1224. if(is_error(obj))
  1225. {
  1226. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1227. }
  1228. else
  1229. {
  1230. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1231. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1232. )
  1233. {
  1234. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1235. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. )
  1237. {
  1238. struct tm tmFrom, tmTo;
  1239. struct timeb tbFrom, tbTo;
  1240. 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) &&
  1241. (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))
  1242. {
  1243. tmFrom.tm_year -= 1900;
  1244. tmFrom.tm_mon -= 1;
  1245. tbFrom.time = mktime(&tmFrom);
  1246. tmTo.tm_year -= 1900;
  1247. tmTo.tm_mon -= 1;
  1248. tbTo.time = mktime(&tmTo);
  1249. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1250. {
  1251. if(defaultTxProfile.ChargingProfileId == -1)
  1252. DEBUG_INFO("TxDefaultProfile found.\n");
  1253. else
  1254. DEBUG_INFO("TxDefaultProfile updated.\n");
  1255. // Required item
  1256. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1257. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1258. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1259. if(isUnitA)
  1260. {
  1261. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1262. 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++)
  1263. {
  1264. 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"));
  1265. 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?
  1266. 3:
  1267. 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")));
  1268. 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")));
  1269. }
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1274. 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++)
  1275. {
  1276. 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"));
  1277. 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?
  1278. 3:
  1279. 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")));
  1280. 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));
  1281. }
  1282. }
  1283. // Optional item
  1284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1285. {
  1286. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1287. }
  1288. else
  1289. {
  1290. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1291. }
  1292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1293. {
  1294. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1295. }
  1296. else
  1297. {
  1298. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1299. }
  1300. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1301. {
  1302. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1303. }
  1304. else
  1305. {
  1306. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1307. }
  1308. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1309. {
  1310. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1311. }
  1312. else
  1313. {
  1314. defaultTxProfile.TransactionId = -1;
  1315. }
  1316. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1317. {
  1318. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1319. }
  1320. else
  1321. {
  1322. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1323. }
  1324. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1325. {
  1326. 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")));
  1327. }
  1328. else
  1329. {
  1330. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1331. }
  1332. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1333. {
  1334. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1335. }
  1336. else
  1337. {
  1338. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. if(defaultTxProfile.ChargingProfileId == -1)
  1346. DEBUG_INFO("TxDefaultProfile found.\n");
  1347. else
  1348. DEBUG_INFO("TxDefaultProfile updated.\n");
  1349. // Required item
  1350. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1351. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1352. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1353. if(isUnitA)
  1354. {
  1355. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1356. 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++)
  1357. {
  1358. 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"));
  1359. 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?
  1360. 3:
  1361. 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")));
  1362. 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")));
  1363. }
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1368. 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++)
  1369. {
  1370. 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"));
  1371. 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?
  1372. 3:
  1373. 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")));
  1374. 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));
  1375. }
  1376. }
  1377. // Optional item
  1378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1379. {
  1380. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1381. }
  1382. else
  1383. {
  1384. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1385. }
  1386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1387. {
  1388. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1393. }
  1394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1395. {
  1396. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1397. }
  1398. else
  1399. {
  1400. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1401. }
  1402. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1403. {
  1404. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1405. }
  1406. else
  1407. {
  1408. defaultTxProfile.TransactionId = -1;
  1409. }
  1410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1413. }
  1414. else
  1415. {
  1416. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1417. }
  1418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1419. {
  1420. 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")));
  1421. }
  1422. else
  1423. {
  1424. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1425. }
  1426. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1429. }
  1430. else
  1431. {
  1432. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. json_object_put(obj);
  1438. }
  1439. fclose(fp);
  1440. /*
  1441. if(defaultTxProfile.ChargingProfileId != -1)
  1442. {
  1443. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1444. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1445. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1446. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1447. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1448. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1449. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1450. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1451. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1452. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1453. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1457. {
  1458. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1459. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1460. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1461. }
  1462. }
  1463. }
  1464. else
  1465. DEBUG_INFO("TxDefaultProfile not found.\n");
  1466. DEBUG_INFO("------------------------------------\n");*/
  1467. }
  1468. // Search max profile
  1469. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1470. if((access(profileFileName, F_OK))!=-1)
  1471. {
  1472. fp = fopen(profileFileName, "r");
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1478. }
  1479. maxProfile.ChargingProfileId = -1;
  1480. maxProfile.StackLevel = -1;
  1481. while(getline(&line, &len, fp) != -1)
  1482. {
  1483. json_object *obj = NULL;
  1484. obj = json_tokener_parse(line);
  1485. if(is_error(obj))
  1486. {
  1487. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1488. }
  1489. else
  1490. {
  1491. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1492. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1493. )
  1494. {
  1495. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1496. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. )
  1498. {
  1499. struct tm tmFrom, tmTo;
  1500. struct timeb tbFrom, tbTo;
  1501. 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) &&
  1502. (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))
  1503. {
  1504. tmFrom.tm_year -= 1900;
  1505. tmFrom.tm_mon -= 1;
  1506. tbFrom.time = mktime(&tmFrom);
  1507. tmTo.tm_year -= 1900;
  1508. tmTo.tm_mon -= 1;
  1509. tbTo.time = mktime(&tmTo);
  1510. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1511. {
  1512. if(maxProfile.ChargingProfileId == -1)
  1513. DEBUG_INFO("MaxProfile found.\n");
  1514. else
  1515. DEBUG_INFO("MaxProfile updated.\n");
  1516. // Required item
  1517. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1518. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1519. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1520. if(isUnitA)
  1521. {
  1522. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1523. 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++)
  1524. {
  1525. 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"));
  1526. 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?
  1527. 3:
  1528. 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")));
  1529. 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")));
  1530. }
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1535. 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++)
  1536. {
  1537. 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"));
  1538. 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?
  1539. 3:
  1540. 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")));
  1541. 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));
  1542. }
  1543. }
  1544. // Optional item
  1545. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1546. {
  1547. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1548. }
  1549. else
  1550. {
  1551. sprintf((char*)maxProfile.ValidFrom, " ");
  1552. }
  1553. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1554. {
  1555. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1556. }
  1557. else
  1558. {
  1559. sprintf((char*)maxProfile.ValidTo, " ");
  1560. }
  1561. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1562. {
  1563. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1564. }
  1565. else
  1566. {
  1567. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1568. }
  1569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1570. {
  1571. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1572. }
  1573. else
  1574. {
  1575. maxProfile.TransactionId = -1;
  1576. }
  1577. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1578. {
  1579. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1580. }
  1581. else
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = 86400;
  1584. }
  1585. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1586. {
  1587. 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")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1592. }
  1593. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1594. {
  1595. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1596. }
  1597. else
  1598. {
  1599. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingProfileId == -1)
  1607. DEBUG_INFO("MaxProfile found.\n");
  1608. else
  1609. DEBUG_INFO("MaxProfile updated.\n");
  1610. // Required item
  1611. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1612. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1613. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1614. if(isUnitA)
  1615. {
  1616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1617. 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++)
  1618. {
  1619. 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"));
  1620. 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?
  1621. 3:
  1622. 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")));
  1623. 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")));
  1624. }
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1629. 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++)
  1630. {
  1631. 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"));
  1632. 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?
  1633. 3:
  1634. 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")));
  1635. 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));
  1636. }
  1637. }
  1638. // Optional item
  1639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1640. {
  1641. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1642. }
  1643. else
  1644. {
  1645. sprintf((char*)maxProfile.ValidFrom, " ");
  1646. }
  1647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1648. {
  1649. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1650. }
  1651. else
  1652. {
  1653. sprintf((char*)maxProfile.ValidTo, " ");
  1654. }
  1655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1656. {
  1657. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1662. }
  1663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1664. {
  1665. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1666. }
  1667. else
  1668. {
  1669. maxProfile.TransactionId = -1;
  1670. }
  1671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1672. {
  1673. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1674. }
  1675. else
  1676. {
  1677. maxProfile.ChargingSchedule.Duration = 86400;
  1678. }
  1679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1680. {
  1681. 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")));
  1682. }
  1683. else
  1684. {
  1685. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1686. }
  1687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1688. {
  1689. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1690. }
  1691. else
  1692. {
  1693. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. json_object_put(obj);
  1699. }
  1700. fclose(fp);
  1701. /*
  1702. if(maxProfile.ChargingProfileId !=-1)
  1703. {
  1704. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1705. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1706. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1707. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1708. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1709. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1710. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1711. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1712. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1713. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1714. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1716. {
  1717. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1718. {
  1719. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1720. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1721. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1722. }
  1723. }
  1724. }
  1725. else
  1726. DEBUG_INFO("MaxProfile not found.\n");
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Align found profile start schedule & periods
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. /*
  1734. // For local test usage, force modify found profile start schedule info
  1735. 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);
  1736. 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);
  1737. 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);
  1738. */
  1739. if(txProfile.ChargingProfileId != -1)
  1740. {
  1741. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1742. {
  1743. if(txProfile.ChargingSchedule.Duration != -1)
  1744. {
  1745. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1746. 0:
  1747. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1754. 0:
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1756. if(idxPeriod > 0)
  1757. {
  1758. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1759. {
  1760. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1767. {
  1768. if(txProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1771. 0:
  1772. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1779. 0:
  1780. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1794. {
  1795. if(txProfile.ChargingSchedule.Duration != -1)
  1796. {
  1797. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1798. 0:
  1799. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1800. }
  1801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1802. {
  1803. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1804. {
  1805. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1808. if(idxPeriod > 0)
  1809. {
  1810. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1811. {
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(txProfile.ChargingSchedule.Duration != -1)
  1821. {
  1822. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1823. 0:
  1824. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1825. }
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1829. {
  1830. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1831. 0:
  1832. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1833. if(idxPeriod > 0)
  1834. {
  1835. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1836. {
  1837. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. /*
  1845. DEBUG_INFO("txProfile after align.\n");
  1846. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1847. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1848. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1849. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1850. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1851. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1852. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1853. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1854. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1855. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1856. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1858. {
  1859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1860. {
  1861. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1862. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1863. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1864. }
  1865. }*/
  1866. }
  1867. if(defaultTxProfile.ChargingProfileId != -1)
  1868. {
  1869. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1870. {
  1871. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1874. 0:
  1875. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1876. }
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1880. {
  1881. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1882. 0:
  1883. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1884. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1885. {
  1886. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1887. }
  1888. if(idxPeriod > 0)
  1889. {
  1890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1891. {
  1892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1899. {
  1900. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1903. 0:
  1904. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1905. }
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1909. {
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1911. 0:
  1912. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1913. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1916. }
  1917. if(idxPeriod > 0)
  1918. {
  1919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1920. {
  1921. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1930. {
  1931. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1932. {
  1933. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1934. 0:
  1935. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1936. }
  1937. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1938. {
  1939. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1940. {
  1941. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1942. 0:
  1943. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1944. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1947. }
  1948. if(idxPeriod > 0)
  1949. {
  1950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1951. {
  1952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. else
  1959. {
  1960. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1963. 0:
  1964. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1965. }
  1966. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1967. {
  1968. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1969. {
  1970. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1971. 0:
  1972. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1976. }
  1977. if(idxPeriod > 0)
  1978. {
  1979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. /*
  1989. DEBUG_INFO("defaultTxProfile after align.\n");
  1990. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1991. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1992. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1993. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1994. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1995. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1996. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1997. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1998. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1999. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2000. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2004. {
  2005. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2006. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2007. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2008. }
  2009. }
  2010. DEBUG_INFO("------------------------------------\n");*/
  2011. }
  2012. if(maxProfile.ChargingProfileId != -1)
  2013. {
  2014. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2015. {
  2016. if(maxProfile.ChargingSchedule.Duration != -1)
  2017. {
  2018. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2019. 0:
  2020. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2021. }
  2022. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2023. {
  2024. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2025. {
  2026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2027. 0:
  2028. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2029. if(idxPeriod > 0)
  2030. {
  2031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2032. {
  2033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2040. {
  2041. if(maxProfile.ChargingSchedule.Duration != -1)
  2042. {
  2043. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2044. 0:
  2045. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2046. }
  2047. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2048. {
  2049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2050. {
  2051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2052. 0:
  2053. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2054. if(idxPeriod > 0)
  2055. {
  2056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2057. {
  2058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. else
  2065. {
  2066. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2067. {
  2068. if(maxProfile.ChargingSchedule.Duration != -1)
  2069. {
  2070. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2071. 0:
  2072. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2073. }
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2077. {
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2079. 0:
  2080. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2081. if(idxPeriod > 0)
  2082. {
  2083. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2084. {
  2085. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. else
  2092. {
  2093. if(maxProfile.ChargingSchedule.Duration != -1)
  2094. {
  2095. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2096. 0:
  2097. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2098. }
  2099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2100. {
  2101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2102. {
  2103. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2104. 0:
  2105. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2106. if(idxPeriod > 0)
  2107. {
  2108. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2109. {
  2110. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. /*
  2118. DEBUG_INFO("MaxProfile after align.\n");
  2119. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2120. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2121. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2122. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2123. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2124. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2125. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2126. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2127. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2128. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2129. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2133. {
  2134. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2135. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2136. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2137. }
  2138. }
  2139. DEBUG_INFO("------------------------------------\n");*/
  2140. }
  2141. /*
  2142. * Merge to conposite schedule
  2143. */
  2144. //DEBUG_INFO("====================================\n");
  2145. // Find each profile period quantity
  2146. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2147. {
  2148. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2149. limitMax = idx+1;
  2150. }
  2151. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2154. limitDef = idx+1;
  2155. }
  2156. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2157. {
  2158. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2159. limitTx = idx+1;
  2160. }
  2161. // TxProfile found, composite schedule based on it
  2162. if(txProfile.ChargingProfileId != -1)
  2163. {
  2164. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2165. {
  2166. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2167. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2168. (txProfile.ChargingSchedule.Duration > 0))
  2169. {
  2170. if(maxProfile.ChargingProfileId != -1)
  2171. {
  2172. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2173. {
  2174. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2175. {
  2176. if((maxProfile.ChargingSchedule.Duration > 0))
  2177. {
  2178. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2179. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2180. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2181. }
  2182. else
  2183. {
  2184. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2185. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2187. }
  2188. }
  2189. if(idxMaxPeriod == (limitMax-1))
  2190. {
  2191. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2192. {
  2193. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2194. {
  2195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2196. compositePeriodIdx++;
  2197. }
  2198. else
  2199. {
  2200. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. else
  2207. {
  2208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. compositePeriodIdx++;
  2212. }
  2213. else
  2214. {
  2215. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2216. }
  2217. }
  2218. }
  2219. if(idxTxPeriod == (limitTx-1))
  2220. {
  2221. if(defaultTxProfile.ChargingProfileId != -1)
  2222. {
  2223. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2224. {
  2225. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2226. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2227. (defaultTxProfile.ChargingSchedule.Duration>0))
  2228. {
  2229. if(maxProfile.ChargingProfileId != -1)
  2230. {
  2231. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2232. {
  2233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2234. {
  2235. if((maxProfile.ChargingSchedule.Duration > 0))
  2236. {
  2237. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2238. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2239. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2240. }
  2241. else
  2242. {
  2243. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2244. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2245. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2246. }
  2247. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2248. {
  2249. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2250. {
  2251. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2252. compositePeriodIdx++;
  2253. }
  2254. else
  2255. {
  2256. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2257. }
  2258. }
  2259. // Delete duplicate period
  2260. if(compositePeriodIdx > 1)
  2261. {
  2262. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2263. {
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2266. compositePeriodIdx -= 1;
  2267. }
  2268. }
  2269. }
  2270. else
  2271. break;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2277. {
  2278. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2279. compositePeriodIdx++;
  2280. }
  2281. else
  2282. {
  2283. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2293. else if(defaultTxProfile.ChargingProfileId != -1)
  2294. {
  2295. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2296. {
  2297. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2299. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2300. {
  2301. if(maxProfile.ChargingProfileId != -1)
  2302. {
  2303. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2304. {
  2305. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2306. {
  2307. if((maxProfile.ChargingSchedule.Duration > 0))
  2308. {
  2309. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2310. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2311. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2312. }
  2313. else
  2314. {
  2315. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2316. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2317. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2318. }
  2319. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2320. {
  2321. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2322. {
  2323. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2324. compositePeriodIdx++;
  2325. }
  2326. else
  2327. {
  2328. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2329. }
  2330. }
  2331. // Delete duplicate period
  2332. if(compositePeriodIdx > 1)
  2333. {
  2334. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2335. {
  2336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2338. compositePeriodIdx -= 1;
  2339. }
  2340. }
  2341. }
  2342. else
  2343. break;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2349. {
  2350. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2351. compositePeriodIdx++;
  2352. }
  2353. else
  2354. {
  2355. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. // Fill other period by MaxProfile
  2362. if(maxProfile.ChargingProfileId != -1)
  2363. {
  2364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2365. {
  2366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2368. (maxProfile.ChargingSchedule.Duration > 0))
  2369. {
  2370. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2371. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2372. {
  2373. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2374. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2376. }
  2377. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2378. {
  2379. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2380. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2381. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2382. }
  2383. if(tmpPeriod.Limit != -1)
  2384. {
  2385. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2386. {
  2387. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2388. {
  2389. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2390. compositePeriodIdx++;
  2391. }
  2392. else
  2393. {
  2394. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2395. }
  2396. }
  2397. // Delete duplicate period
  2398. if(compositePeriodIdx > 1)
  2399. {
  2400. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2401. {
  2402. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2404. compositePeriodIdx -= 1;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2412. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2414. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2416. {
  2417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2418. {
  2419. compositeProfile->ChargingProfileId = 1;
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2425. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2426. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2427. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2428. }
  2429. if(line)
  2430. free(line);
  2431. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2432. }
  2433. //==========================================
  2434. // Init all share memory
  2435. //==========================================
  2436. int InitShareMemory()
  2437. {
  2438. int result = PASS;
  2439. int MeterSMId;
  2440. //creat ShmSysConfigAndInfo
  2441. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2442. {
  2443. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2444. result = FAIL;
  2445. }
  2446. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2447. {
  2448. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2449. result = FAIL;
  2450. }
  2451. else
  2452. {}
  2453. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2454. {
  2455. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2456. result = FAIL;
  2457. }
  2458. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2459. {
  2460. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2461. result = FAIL;
  2462. }
  2463. else
  2464. {}
  2465. //creat ShmPsuData
  2466. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2467. {
  2468. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2469. result = FAIL;
  2470. }
  2471. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2472. {
  2473. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2474. result = FAIL;
  2475. }
  2476. else
  2477. {}
  2478. //creat ShmOCPP16Data
  2479. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2480. {
  2481. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2482. result = FAIL;
  2483. }
  2484. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2485. {
  2486. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2487. result = FAIL;
  2488. }
  2489. else
  2490. {}
  2491. /****************************** For Initial Settings************************************************/
  2492. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2493. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2494. // allocate Configuration memory address
  2495. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2496. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2497. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2499. //offline MeterValue Interval
  2500. TempMeterValueInterval = 0;
  2501. return result;
  2502. }
  2503. int ProcessShareMemory()
  2504. {
  2505. if(InitShareMemory() == FAIL)
  2506. {
  2507. DEBUG_ERROR("InitShareMemory NG\n");
  2508. if(ShmStatusCodeData!=NULL)
  2509. {
  2510. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2511. }
  2512. sleep(5);
  2513. return FAIL;
  2514. }
  2515. return PASS;
  2516. }
  2517. void CheckSystemValue(void)
  2518. {
  2519. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2520. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2521. char filenmae[100]={0};
  2522. char str[100]={0};
  2523. int tempIndex = 0;
  2524. //===============================
  2525. // send Heartbeat
  2526. //===============================
  2527. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2528. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2529. {
  2530. clientTime.Heartbeat=time((time_t*)NULL);
  2531. if(server_sign == TRUE)
  2532. {
  2533. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2534. }
  2535. else
  2536. {
  2537. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2538. }
  2539. }
  2540. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2541. {
  2542. //parameter for test
  2543. sendHeartbeatRequest(0);
  2544. //==============================================
  2545. // Reset Waiting Time
  2546. //==============================================
  2547. HeartBeatWithNOResponse += 1;
  2548. }
  2549. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2550. {
  2551. //==========================================
  2552. // csu trigger DataTransferReq
  2553. //==========================================
  2554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2555. {
  2556. sendDataTransferRequest(gun_index);
  2557. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2558. }
  2559. //===============================
  2560. // CSU Trigger Authorize Request
  2561. //===============================
  2562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2563. {
  2564. sendAuthorizeRequest(0);
  2565. authorizeRetryTimes = authorizeRetryTimes + 1;
  2566. if(authorizeRetryTimes < 3)
  2567. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2568. }
  2569. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2570. {
  2571. authorizeRetryTimes = 0;
  2572. SetOcppConnStatus(FALSE);
  2573. server_sign = FALSE;
  2574. }
  2575. 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))
  2576. {
  2577. sendAuthorizeRequest(0);
  2578. }
  2579. //==============================================
  2580. // CSU Trigger Smart Charging Profilw
  2581. //==============================================
  2582. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2583. {
  2584. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2585. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2586. }
  2587. //==============================================
  2588. // Charger start transaction
  2589. //==============================================
  2590. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2591. {
  2592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2593. sendStartTransactionRequest(gun_index);
  2594. clientTime.StartTransaction = time((time_t*)NULL);
  2595. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2596. storeTempStopTransaction(gun_index);
  2597. }
  2598. //==============================================
  2599. // Charger stop transaction
  2600. //==============================================
  2601. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2602. {
  2603. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2604. sendStopTransactionRequest(gun_index);
  2605. clientTime.StopTransaction = time((time_t*)NULL);
  2606. }
  2607. //==============================================
  2608. // Charger status report
  2609. //==============================================
  2610. //--- Check Mode Change ---//
  2611. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2613. {
  2614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2615. {
  2616. tempIndex = ((gun_index==2) ? 1: 0);
  2617. }
  2618. else
  2619. {
  2620. tempIndex = gun_index;
  2621. }
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2625. {
  2626. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2627. {
  2628. // Sent unplug message for California pricing logic
  2629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2630. {
  2631. uint8_t ts[20];
  2632. getNowDatetime(ts);
  2633. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2634. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2636. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2637. }
  2638. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2639. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2641. }
  2642. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2643. {
  2644. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2645. if((access(filenmae,F_OK))!=-1)
  2646. {
  2647. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2648. sprintf(str,"rm -f %s",filenmae);
  2649. system(str);
  2650. }
  2651. }
  2652. #if 1 // for TempStopTransaction
  2653. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2654. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2655. {
  2656. checkTempStopTransaction(gun_index);
  2657. }
  2658. #endif
  2659. }
  2660. }
  2661. }
  2662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2663. {
  2664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2665. {
  2666. tempIndex = ((gun_index==2) ? 1: 0);
  2667. }
  2668. else
  2669. {
  2670. tempIndex = gun_index;
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2675. {
  2676. 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]*/ )
  2677. {
  2678. // Sent unplug message for California pricing logic
  2679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2680. {
  2681. uint8_t ts[20];
  2682. getNowDatetime(ts);
  2683. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2686. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2687. }
  2688. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2689. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2690. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2691. }
  2692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2693. {
  2694. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2695. if((access(filenmae,F_OK))!=-1)
  2696. {
  2697. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2698. sprintf(str,"rm -f %s",filenmae);
  2699. system(str);
  2700. }
  2701. }
  2702. #if 1 // for TempStopTransaction
  2703. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2704. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2705. {
  2706. checkTempStopTransaction(gun_index);
  2707. }
  2708. #endif
  2709. }
  2710. }
  2711. }
  2712. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2713. {
  2714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2715. {
  2716. tempIndex = ((gun_index==2) ? 1: 0);
  2717. }
  2718. else
  2719. {
  2720. tempIndex = gun_index;
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2725. {
  2726. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2727. {
  2728. // Sent unplug message for California pricing logic
  2729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2730. {
  2731. uint8_t ts[20];
  2732. getNowDatetime(ts);
  2733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2734. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2736. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2737. }
  2738. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2739. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2740. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2741. }
  2742. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2743. {
  2744. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2745. if((access(filenmae,F_OK))!=-1)
  2746. {
  2747. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2748. sprintf(str,"rm -f %s",filenmae);
  2749. system(str);
  2750. }
  2751. }
  2752. #if 1 // for TempStopTransaction
  2753. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2754. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2755. {
  2756. checkTempStopTransaction(gun_index);
  2757. }
  2758. #endif
  2759. }
  2760. }
  2761. }
  2762. else if(gunType[gun_index] == GUN_TYPE_DO)
  2763. {
  2764. tempIndex = gun_index;
  2765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2766. {
  2767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2768. {
  2769. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2770. {
  2771. // Sent unplug message for California pricing logic
  2772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2773. {
  2774. uint8_t ts[20];
  2775. getNowDatetime(ts);
  2776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2777. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2779. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2780. }
  2781. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2782. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2784. }
  2785. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2786. {
  2787. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2788. if((access(filenmae,F_OK))!=-1)
  2789. {
  2790. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2791. sprintf(str,"rm -f %s",filenmae);
  2792. system(str);
  2793. }
  2794. }
  2795. #if 1 // for TempStopTransaction
  2796. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2797. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2798. {
  2799. checkTempStopTransaction(gun_index);
  2800. }
  2801. #endif
  2802. }
  2803. }
  2804. }
  2805. else
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2808. {
  2809. tempIndex = 2;
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < AC_QUANTITY; index++)
  2816. {
  2817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2818. {
  2819. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2820. {
  2821. // Sent unplug message for California pricing logic
  2822. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2823. {
  2824. uint8_t ts[20];
  2825. getNowDatetime(ts);
  2826. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2827. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2828. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2829. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2830. }
  2831. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2832. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2834. }
  2835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2836. {
  2837. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2838. if((access(filenmae,F_OK))!=-1)
  2839. {
  2840. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2841. sprintf(str,"rm -f %s",filenmae);
  2842. system(str);
  2843. }
  2844. }
  2845. #if 1 // for TempStopTransaction
  2846. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2847. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2848. {
  2849. checkTempStopTransaction(gun_index);
  2850. }
  2851. #endif
  2852. }
  2853. }// END
  2854. }
  2855. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2856. (
  2857. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2858. )
  2859. )
  2860. {
  2861. if(SystemInitial > 0)
  2862. SystemInitial -= 1;
  2863. sendStatusNotificationRequest(gun_index);
  2864. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2865. }
  2866. //==============================================
  2867. // Meter report
  2868. //==============================================
  2869. // Trigger MeterValue
  2870. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2871. {
  2872. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2873. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2874. }
  2875. // ClockAlign MeterValue
  2876. 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))
  2877. {
  2878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2879. {
  2880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2881. {
  2882. tempIndex = ((gun_index==2) ? 1: 0);
  2883. }
  2884. else
  2885. {
  2886. tempIndex = gun_index;
  2887. }
  2888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2889. {
  2890. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2891. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2892. {
  2893. reqClockAlignMeter[gun_index] = 1;
  2894. }
  2895. }// End for CHAdeMO
  2896. }
  2897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2898. {
  2899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2900. {
  2901. tempIndex = ((gun_index==2) ? 1: 0);
  2902. }
  2903. else
  2904. {
  2905. tempIndex = gun_index;
  2906. }
  2907. for (int index = 0; index < CCS_QUANTITY; index++)
  2908. {
  2909. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2910. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2911. {
  2912. reqClockAlignMeter[gun_index] = 1;
  2913. }
  2914. } // End for CCS
  2915. }
  2916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2917. {
  2918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2919. {
  2920. tempIndex = ((gun_index==2) ? 1: 0);
  2921. }
  2922. else
  2923. {
  2924. tempIndex = gun_index;
  2925. }
  2926. for (int index = 0; index < GB_QUANTITY; index++)
  2927. {
  2928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2930. {
  2931. reqClockAlignMeter[gun_index] = 1;
  2932. }
  2933. }// End for GB
  2934. }
  2935. else if(gunType[gun_index] == GUN_TYPE_DO)
  2936. {
  2937. tempIndex = gun_index;
  2938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2939. {
  2940. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2941. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2942. {
  2943. reqClockAlignMeter[gun_index] = 1;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2950. {
  2951. tempIndex = 2;
  2952. }
  2953. else
  2954. {
  2955. tempIndex = gun_index;
  2956. }
  2957. for (int index = 0; index < AC_QUANTITY; index++)
  2958. {
  2959. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2960. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2961. {
  2962. reqClockAlignMeter[gun_index] = 1;
  2963. }
  2964. }//End for AC
  2965. }
  2966. if(reqClockAlignMeter[gun_index] == 1)
  2967. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2968. }
  2969. // Sample period MeterValue
  2970. 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))))
  2971. {
  2972. //check Transaction active
  2973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2974. {
  2975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2976. {
  2977. tempIndex = ((gun_index==2) ? 1: 0);
  2978. }
  2979. else
  2980. {
  2981. tempIndex = gun_index;
  2982. }
  2983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2984. {
  2985. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2986. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2987. {
  2988. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2989. {
  2990. reqSampleMeter[gun_index] = 1;
  2991. }
  2992. }
  2993. }// End for CHAdeMO
  2994. }
  2995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2996. {
  2997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2998. {
  2999. tempIndex = ((gun_index==2) ? 1: 0);
  3000. }
  3001. else
  3002. {
  3003. tempIndex = gun_index;
  3004. }
  3005. for (int index = 0; index < CCS_QUANTITY; index++)
  3006. {
  3007. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3008. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3009. {
  3010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3011. {
  3012. reqSampleMeter[gun_index] = 1;
  3013. }
  3014. }
  3015. } // End for CCS
  3016. }
  3017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3018. {
  3019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3020. {
  3021. tempIndex = ((gun_index==2) ? 1: 0);
  3022. }
  3023. else
  3024. {
  3025. tempIndex = gun_index;
  3026. }
  3027. for (int index = 0; index < GB_QUANTITY; index++)
  3028. {
  3029. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3030. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3033. {
  3034. reqSampleMeter[gun_index] = 1;
  3035. }
  3036. }
  3037. }// End for GB
  3038. }
  3039. else if(gunType[gun_index] == GUN_TYPE_DO)
  3040. {
  3041. tempIndex = gun_index;
  3042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3043. {
  3044. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3045. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3046. {
  3047. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3048. {
  3049. reqSampleMeter[gun_index] = 1;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. else
  3055. {
  3056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3057. {
  3058. tempIndex = 2;
  3059. }
  3060. else
  3061. {
  3062. tempIndex = gun_index;
  3063. }
  3064. for (int index = 0; index < AC_QUANTITY; index++)
  3065. {
  3066. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3067. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3068. {
  3069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3070. {
  3071. reqSampleMeter[gun_index] = 1;
  3072. }
  3073. }
  3074. }//End for AC
  3075. }
  3076. if(reqSampleMeter[gun_index] == 1)
  3077. {
  3078. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3079. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3080. storeTempStopTransaction(gun_index);
  3081. }
  3082. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3083. }
  3084. //==============================================
  3085. // Check Connector reserved
  3086. //==============================================
  3087. //===============================
  3088. // Check if Reserve is expired
  3089. //===============================
  3090. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3091. {
  3092. double diff_t;
  3093. struct tm tp;
  3094. // current time
  3095. time_t t = time(NULL);
  3096. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3097. tp.tm_isdst = -1;
  3098. time_t utc = mktime(&tp);
  3099. diff_t = difftime(utc, t);
  3100. if(diff_t <= 0)
  3101. {
  3102. DEBUG_INFO("reserve expired.\n");
  3103. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3104. }
  3105. }//END OF Check if Reserve is expired
  3106. //==========================================
  3107. // csu trigger FirmwareStatusNotificationReq
  3108. //==========================================
  3109. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3110. {
  3111. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3112. }
  3113. //==========================================
  3114. // csu trigger DiagnosticsStatusNotificationReq
  3115. //==========================================
  3116. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3117. {
  3118. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3119. }
  3120. //==========================================
  3121. // csu trigger CancelReservationConf
  3122. //==========================================
  3123. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3124. {
  3125. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3126. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3127. }
  3128. //==========================================
  3129. // csu trigger ChangeAvailabilityConf
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3132. {
  3133. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3134. }
  3135. //==========================================
  3136. // csu trigger UnlockConnectorConf
  3137. //==========================================
  3138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3139. {
  3140. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3141. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3142. }
  3143. //==========================================
  3144. // csu trigger ReserveNowConf
  3145. //==========================================
  3146. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3147. {
  3148. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3149. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3150. }
  3151. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3152. {
  3153. sendSignCertificateRequest();
  3154. }
  3155. }
  3156. }
  3157. //==========================================
  3158. // send request routine
  3159. //==========================================
  3160. int sendAuthorizeRequest(int gun_index)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[100]={0};
  3165. char guid[37];
  3166. char tempdata[65]={0};
  3167. DEBUG_INFO("sendAuthorizeRequest...\n");
  3168. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3169. //Local Authorize
  3170. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3171. {
  3172. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3173. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3174. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3175. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3176. result = PASS;
  3177. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3178. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3179. authorizeRetryTimes = 0;
  3180. return result;
  3181. }
  3182. 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))||
  3183. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3184. {
  3185. // Query from cache
  3186. DEBUG_INFO("Authorize from cache.\n");
  3187. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3188. // Query from list
  3189. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3190. {
  3191. DEBUG_INFO("Authorize from list.\n");
  3192. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3193. }
  3194. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3195. {
  3196. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3197. {
  3198. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3199. }
  3200. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3201. {
  3202. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3203. }
  3204. if(!GetOcppConnStatus())
  3205. {
  3206. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3207. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3208. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3209. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3210. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3211. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3212. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3213. authorizeRetryTimes = 0;
  3214. return result;
  3215. }
  3216. }
  3217. else
  3218. {
  3219. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3220. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3221. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3222. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3223. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3224. else
  3225. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3226. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3227. result = PASS;
  3228. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3229. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3230. authorizeRetryTimes = 0;
  3231. return result;
  3232. }
  3233. }
  3234. //initialize struct Authorize
  3235. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3236. //get data from shared memory
  3237. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3238. random_uuid(guid);
  3239. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3240. LWS_Send(message);
  3241. sprintf(tempdata, "Authorize,%d", gun_index);
  3242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3243. {
  3244. result = PASS;
  3245. DEBUG_INFO("Authorize mapItem pass\n");
  3246. }
  3247. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3248. return result;
  3249. }
  3250. int sendBootNotificationRequest(void)
  3251. {
  3252. mtrace();
  3253. int result = FAIL;
  3254. char message[500]={0}, payload[700]={0};
  3255. char guid[37]={0};
  3256. char tempdata[65]={0};
  3257. // Fill BootNotification fields
  3258. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3259. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3260. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3261. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3262. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3263. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3264. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3265. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3266. ShmOCPP16Data->ChargeBoxId
  3267. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3268. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3269. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3270. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3271. ,ShmOCPP16Data->BootNotification.CpIccid
  3272. ,ShmOCPP16Data->BootNotification.CpImsi);
  3273. random_uuid(guid);
  3274. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3275. LWS_Send(message);
  3276. sprintf(tempdata, "BootNotification,0");
  3277. 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*/)
  3278. {
  3279. result = PASS;
  3280. }
  3281. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3282. strcpy(queuedata,message);
  3283. return result;
  3284. }
  3285. int sendDataTransferRequest(int gun_index)
  3286. {
  3287. mtrace();
  3288. char message[1000]={0};
  3289. char guid[37]={0};
  3290. char tempdata[65]={0};
  3291. int result = FAIL;
  3292. random_uuid(guid);
  3293. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3294. MESSAGE_TYPE_CALL,
  3295. guid,
  3296. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3297. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3298. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3299. LWS_Send(message);
  3300. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3301. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3302. {
  3303. result = PASS;
  3304. DEBUG_INFO("DataTransfer mapItem pass\n");
  3305. }
  3306. return result;
  3307. }
  3308. int sendDiagnosticsStatusNotificationRequest(char *status)
  3309. {
  3310. mtrace();
  3311. int result = FAIL;
  3312. char message[110]={0};
  3313. char guid[37]={0};
  3314. char tempdata[65]={0};
  3315. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3316. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3317. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3318. random_uuid(guid);
  3319. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3320. LWS_SendNow(message);
  3321. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3322. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3323. {
  3324. result = PASS;
  3325. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3326. }
  3327. //#ifdef SystemLogMessage
  3328. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3329. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3330. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3331. //#endif
  3332. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3333. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3334. //record status
  3335. if(strcmp(status,"Idle")==0)
  3336. {
  3337. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3338. }
  3339. else if(strcmp(status,"Uploaded")==0)
  3340. {
  3341. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3342. }
  3343. else if(strcmp(status,"UploadFailed")==0)
  3344. {
  3345. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3346. }
  3347. else if(strcmp(status,"Uploading")==0)
  3348. {
  3349. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3350. }
  3351. return result;
  3352. }
  3353. int sendFirmwareStatusNotificationRequest(char *status)
  3354. {
  3355. mtrace();
  3356. int result = FAIL;
  3357. char message[110]={0};
  3358. char guid[37]={0};
  3359. char tempdata[65]={0};
  3360. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3361. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3362. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3363. random_uuid(guid);
  3364. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3365. LWS_SendNow(message);
  3366. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3367. 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*/)
  3368. {
  3369. result = PASS;
  3370. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3371. }
  3372. //#ifdef SystemLogMessage
  3373. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3374. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3375. //#endif
  3376. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3377. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3378. //record status
  3379. if(strcmp(status,"Downloaded")==0)
  3380. {
  3381. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3382. }
  3383. else if(strcmp(status,"DownloadFailed")==0)
  3384. {
  3385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3386. }
  3387. else if(strcmp(status,"Downloading")==0)
  3388. {
  3389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3390. }
  3391. else if(strcmp(status,"Idle")==0)
  3392. {
  3393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3394. }
  3395. else if(strcmp(status,"InstallationFailed")==0)
  3396. {
  3397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3398. }
  3399. else if(strcmp(status,"Installing")==0)
  3400. {
  3401. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3402. }
  3403. else if(strcmp(status,"Installed")==0)
  3404. {
  3405. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3406. }
  3407. return result;
  3408. }
  3409. int sendHeartbeatRequest(int gun_index)
  3410. {
  3411. mtrace();
  3412. int result = FAIL;
  3413. char message[80]={0};
  3414. char guid[37]={0};
  3415. char tempdata[65]={0};
  3416. random_uuid(guid);
  3417. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3418. , MESSAGE_TYPE_CALL
  3419. , guid );
  3420. LWS_Send(message);
  3421. sprintf(tempdata, "Heartbeat,%d", 0);
  3422. 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*/)
  3423. {
  3424. result = PASS;
  3425. }
  3426. return result;
  3427. }
  3428. int sendStartTransactionRequest(int gun_index)
  3429. {
  3430. mtrace();
  3431. int result = FAIL;
  3432. char message[250]={0};
  3433. char guid[37]={0};
  3434. struct timeval tmnow;
  3435. struct tm *tm;
  3436. char buf[28];//, usec_buf[6];
  3437. char tempdata[65]={0};
  3438. int tempIndex = 0;
  3439. DEBUG_INFO("sendStartTransactionRequest...\n");
  3440. gettimeofday(&tmnow, NULL);
  3441. time_t t;
  3442. t = time(NULL);
  3443. /*UTC time and date*/
  3444. tm = gmtime(&t);
  3445. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3446. #if 0 // remove temporally
  3447. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3448. strcat(buf,".");
  3449. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3450. strcat(buf,usec_buf);
  3451. #endif
  3452. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3453. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3454. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3455. // clear StartTransaction Response
  3456. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3457. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3458. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3459. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3460. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3475. {
  3476. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3477. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3478. }
  3479. }
  3480. }
  3481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < CCS_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3494. {
  3495. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3496. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3497. }
  3498. }
  3499. }
  3500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3503. {
  3504. tempIndex = ((gun_index==2) ? 1: 0);
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < GB_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3513. {
  3514. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3515. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3516. }
  3517. }
  3518. }
  3519. else if(gunType[gun_index] == GUN_TYPE_DO)
  3520. {
  3521. tempIndex = gun_index;
  3522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3523. {
  3524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3525. {
  3526. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3527. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3528. }
  3529. }
  3530. }
  3531. else
  3532. {
  3533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3534. {
  3535. tempIndex = 2;
  3536. }
  3537. else
  3538. {
  3539. tempIndex = gun_index;
  3540. }
  3541. for (int index = 0; index < AC_QUANTITY; index++)
  3542. {
  3543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3544. {
  3545. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3546. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3547. }
  3548. }
  3549. }
  3550. random_uuid(guid);
  3551. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3552. {
  3553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3554. , gun_index +1
  3555. , MESSAGE_TYPE_CALL
  3556. , guid
  3557. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3558. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3559. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3560. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3561. }
  3562. else
  3563. {
  3564. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3565. , gun_index +1
  3566. , MESSAGE_TYPE_CALL
  3567. , guid
  3568. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3569. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3570. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3571. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3572. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3573. }
  3574. #if 1
  3575. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3576. 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*/)
  3577. {
  3578. result = PASS;
  3579. }
  3580. #endif
  3581. strcpy(queuedata, message);
  3582. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3583. OCPP_insert_transaction_msg(YES, queuedata);
  3584. return result;
  3585. }
  3586. int sendStatusNotificationRequest(int gun_index)
  3587. {
  3588. mtrace();
  3589. int result = FAIL;
  3590. char message[600]={0};
  3591. char guid[37];
  3592. int currentStatus = 0;
  3593. struct timeval tmnow;
  3594. struct tm *tm;
  3595. char buf[28];//, usec_buf[6];
  3596. char tempdata[65]={0};
  3597. int tempIndex = 0;
  3598. uint8_t isStateChanged = TRUE;
  3599. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3600. gettimeofday(&tmnow, NULL);
  3601. time_t t;
  3602. t = time(NULL);
  3603. /*UTC time and date*/
  3604. tm = gmtime(&t);
  3605. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3606. #if 0 // remove temporally
  3607. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3608. strcat(buf,".");
  3609. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3610. strcat(buf,usec_buf);
  3611. #endif
  3612. printf("%s",buf);
  3613. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3614. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3615. // it's option
  3616. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3617. /*
  3618. enum _SYSTEM_STATUS
  3619. {
  3620. S_BOOTING = 0,
  3621. S_IDLE, = 1
  3622. S_AUTHORIZING, =2
  3623. S_REASSIGN_CHECK, =3
  3624. S_REASSIGN, =4
  3625. S_PRECHARGE, =5
  3626. S_PREPARING_FOR_EV, =6
  3627. S_PREPARING_FOR_EVSE, =7
  3628. S_CHARGING, =8
  3629. S_TERMINATING, =9
  3630. S_COMPLETE, =10
  3631. S_ALARM, =11
  3632. S_FAULT =12
  3633. }
  3634. */
  3635. //check Transaction active
  3636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3638. {
  3639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3640. {
  3641. tempIndex = ((gun_index==2) ? 1: 0);
  3642. }
  3643. else
  3644. {
  3645. tempIndex = gun_index;
  3646. }
  3647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3648. {
  3649. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3650. {
  3651. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3652. {
  3653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3654. {
  3655. currentStatus = Preparing; //OCPP Status: Preparing
  3656. }
  3657. else
  3658. {
  3659. currentStatus = Available; //OCPP Status: Available
  3660. }
  3661. }
  3662. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3663. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3664. ) //S_PRECHARGE
  3665. {
  3666. currentStatus = Preparing; //OCPP Status: Preparing
  3667. }
  3668. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3669. {
  3670. currentStatus = Charging; //OCPP Status: Charging
  3671. }
  3672. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3673. {
  3674. currentStatus = Finishing; //OCPP Status: Finishing
  3675. }
  3676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3677. {
  3678. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3679. }
  3680. 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
  3681. {
  3682. currentStatus = Unavailable; //OCPP Status: Unavailable
  3683. }
  3684. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3685. {
  3686. currentStatus = Faulted; //OCPP Status: Faulted
  3687. }
  3688. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3689. {
  3690. currentStatus = Reserved; //OCPP Status: Reserved
  3691. }
  3692. } //end of the same index
  3693. }//end of for CHAdeMO_QUANTITY
  3694. }
  3695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. for (int index = 0; index < CCS_QUANTITY; index++)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3710. {
  3711. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3712. {
  3713. currentStatus = Preparing; //OCPP Status: Preparing
  3714. }
  3715. else
  3716. {
  3717. currentStatus = Available; //OCPP Status: Available
  3718. }
  3719. }
  3720. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3721. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3722. ) //S_PRECHARGE
  3723. {
  3724. currentStatus = Preparing; //OCPP Status: Preparing
  3725. }
  3726. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3727. {
  3728. currentStatus = Charging; //OCPP Status: Charging
  3729. }
  3730. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3731. {
  3732. currentStatus = Finishing; //OCPP Status: Finishing
  3733. }
  3734. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3735. {
  3736. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3737. }
  3738. 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
  3739. {
  3740. currentStatus = Unavailable; //OCPP Status : Unavailable
  3741. }
  3742. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3743. {
  3744. currentStatus = Faulted; //OCPP Status: Faulted
  3745. }
  3746. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3747. {
  3748. currentStatus = Reserved; //OCPP Status: Reserved
  3749. }
  3750. } //end of the same index
  3751. } // end of for CCS_QUANTITY
  3752. }
  3753. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3756. {
  3757. tempIndex = ((gun_index==2) ? 1: 0);
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < GB_QUANTITY; index++)
  3764. {
  3765. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3766. {
  3767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3768. {
  3769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3770. {
  3771. currentStatus = Preparing; //OCPP Status: Preparing
  3772. }
  3773. else
  3774. {
  3775. currentStatus = Available; //OCPP Status: Available
  3776. }
  3777. }
  3778. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3779. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3780. ) //S_PRECHARGE
  3781. {
  3782. currentStatus = Preparing; //OCPP Status: Preparing
  3783. }
  3784. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3785. {
  3786. currentStatus = Charging; //OCPP Status: Charging
  3787. }
  3788. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3789. {
  3790. currentStatus = Finishing; //OCPP Status: Finishing
  3791. }
  3792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3793. {
  3794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3795. }
  3796. 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
  3797. {
  3798. currentStatus = Unavailable; //OCPP Status: Unavailable
  3799. }
  3800. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3801. {
  3802. currentStatus = Faulted; //OCPP Status: Faulted
  3803. }
  3804. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3805. {
  3806. currentStatus = Reserved; //OCPP Status: Reserved
  3807. }
  3808. } //end of the same index
  3809. } // end of for GB_QUANTITY
  3810. }
  3811. else if(gunType[gun_index] == GUN_TYPE_DO)
  3812. {
  3813. tempIndex = gun_index;
  3814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3815. {
  3816. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3817. {
  3818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3819. {
  3820. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3821. {
  3822. currentStatus = Preparing; //OCPP Status: Preparing
  3823. }
  3824. else
  3825. {
  3826. currentStatus = Available; //OCPP Status: Available
  3827. }
  3828. }
  3829. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3830. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3831. ) //S_PRECHARGE
  3832. {
  3833. currentStatus = Preparing; //OCPP Status: Preparing
  3834. }
  3835. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3836. {
  3837. currentStatus = Charging; //OCPP Status: Charging
  3838. }
  3839. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3840. {
  3841. currentStatus = Finishing; //OCPP Status: Finishing
  3842. }
  3843. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3844. {
  3845. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3846. }
  3847. 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
  3848. {
  3849. currentStatus = Unavailable; //OCPP Status: Unavailable
  3850. }
  3851. 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
  3852. {
  3853. currentStatus = Faulted; //OCPP Status: Faulted
  3854. }
  3855. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3856. {
  3857. currentStatus = Reserved; //OCPP Status: Reserved
  3858. }
  3859. } //end of the same index
  3860. }
  3861. }
  3862. else
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3865. {
  3866. tempIndex = 2;
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < AC_QUANTITY; index++)
  3873. {
  3874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3875. {
  3876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3877. {
  3878. 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))
  3879. {
  3880. currentStatus = Preparing; //OCPP Status: Preparing
  3881. }
  3882. else
  3883. {
  3884. currentStatus = Available; //OCPP Status: Available
  3885. }
  3886. }
  3887. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3888. {
  3889. currentStatus = Preparing; //OCPP Status: Preparing
  3890. }
  3891. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3892. {
  3893. currentStatus = Charging; //OCPP Status: Charging
  3894. }
  3895. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3896. {
  3897. currentStatus = Finishing; //OCPP Status: Finishing
  3898. }
  3899. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3900. {
  3901. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3902. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3903. else
  3904. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3905. }
  3906. 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
  3907. {
  3908. currentStatus = Unavailable; //OCPP Status: Unavailable
  3909. }
  3910. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3911. {
  3912. currentStatus = Faulted; //OCPP Status: Faulted
  3913. }
  3914. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3915. {
  3916. currentStatus = Reserved; //OCPP Status: Reserved
  3917. }
  3918. }//end of the same index
  3919. }//end of for AC_QUANTITY
  3920. }
  3921. //it's option
  3922. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3923. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3924. {
  3925. isStateChanged = FALSE;
  3926. }
  3927. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3928. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3929. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3930. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3931. random_uuid(guid);
  3932. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3933. , MESSAGE_TYPE_CALL
  3934. , guid
  3935. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3936. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3937. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3938. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3939. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3940. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3941. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3942. if((server_sign == TRUE) && isStateChanged)
  3943. {
  3944. LWS_Send(message);
  3945. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3946. 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*/)
  3947. {
  3948. //DEBUG_ERROR("statusNotification mapitem pass");
  3949. result = PASS;
  3950. }
  3951. }
  3952. else
  3953. {
  3954. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3955. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3956. result = PASS;
  3957. }
  3958. return result;
  3959. }
  3960. int sendStopTransactionRequest(int gun_index)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. //char message[1500]={0};
  3965. char guid[37]={0};
  3966. char tempdata[65]={0};
  3967. int tempIndex = 0;
  3968. char TempStopTransaction[256];
  3969. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3970. //int idx_sample=0;
  3971. DEBUG_INFO("sendStopTransactionRequest \n");
  3972. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3973. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3974. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3975. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3976. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3987. {
  3988. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3989. {
  3990. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3991. }
  3992. }// END OF CHAdeMO_QUANTITY
  3993. }
  3994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CCS_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4007. {
  4008. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4009. }
  4010. }// END OF CCS_QUANTITY
  4011. }
  4012. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < GB_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4025. {
  4026. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4027. }
  4028. }// END OF GB_QUANTITY
  4029. }
  4030. else if(gunType[gun_index] == GUN_TYPE_DO)
  4031. {
  4032. tempIndex = gun_index;
  4033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4036. {
  4037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4038. }
  4039. }// END OF GB_QUANTITY
  4040. }
  4041. else
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4044. {
  4045. tempIndex = 2;
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < AC_QUANTITY; index++)
  4052. {
  4053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4054. {
  4055. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4056. }
  4057. }// END OF AC_QUANTITY
  4058. }
  4059. //====================================== Stop Transaction Time =====================================================
  4060. struct timeval tmnow;
  4061. struct tm *tm;
  4062. char buf[28];//, usec_buf[6];
  4063. gettimeofday(&tmnow, NULL);
  4064. time_t t;
  4065. t = time(NULL);
  4066. /*UTC time and date*/
  4067. tm = gmtime(&t);
  4068. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4070. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4071. random_uuid(guid);
  4072. /***********************************transactionData******************************************************/
  4073. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4075. //=================================
  4076. // Transaction_Begin
  4077. //=================================
  4078. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4079. {
  4080. //============================================ Energy.Active.Import.Interval ================================
  4081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4084. 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*/]);
  4085. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4086. 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))
  4087. {
  4088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4089. }
  4090. else
  4091. {
  4092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4093. }
  4094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4096. }
  4097. //=================================
  4098. // Transaction_End
  4099. //=================================
  4100. // ================================= Current.Import L1 ===============================================
  4101. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4102. {
  4103. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4104. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4119. }
  4120. }// End of for CHAdeMO_QUANTITY
  4121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CCS_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4138. }
  4139. }// End of for CCS_QUANTITY
  4140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < GB_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4157. }
  4158. }// End of for GB_QUANTITY
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_DO)
  4162. {
  4163. tempIndex = gun_index;
  4164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4165. {
  4166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4167. {
  4168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4169. }
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4172. }
  4173. else
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4176. {
  4177. tempIndex = 2;
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < AC_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4186. {
  4187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4188. }
  4189. }// End of for AC_QUANTITY
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4191. }
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4197. }
  4198. // ================================= Energy.Active.Import.Interval ==============================================
  4199. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4200. {
  4201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4205. {
  4206. tempIndex = ((gun_index==2) ? 1: 0);
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4217. }
  4218. }// END OF CHAdeMO_QUANTITY
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4220. }
  4221. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CCS_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4236. }
  4237. }// END OF CCS_QUANTITY
  4238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4239. }
  4240. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < GB_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4255. }
  4256. }// END OF GB_QUANTITY
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_DO)
  4260. {
  4261. tempIndex = gun_index;
  4262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4263. {
  4264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4265. {
  4266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4267. }
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4270. }
  4271. else
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4274. {
  4275. tempIndex = 2;
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < AC_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4284. {
  4285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4286. }
  4287. }// END OF AC_QUANTITY
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4289. }
  4290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4295. }
  4296. //=================================== Power.Active.Import ==================================================
  4297. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4298. {
  4299. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4300. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4315. }
  4316. } // End for CHAdeMO_QUANTITY
  4317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CCS_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4334. }
  4335. } // END for CCS_QUANTITY
  4336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < GB_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4353. }
  4354. }// END for GB_QUANTITY
  4355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_DO)
  4358. {
  4359. tempIndex = gun_index;
  4360. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4365. }
  4366. }
  4367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4368. }
  4369. else
  4370. {
  4371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4372. {
  4373. tempIndex = 2;
  4374. }
  4375. else
  4376. {
  4377. tempIndex = gun_index;
  4378. }
  4379. for (int index = 0; index < AC_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4384. }
  4385. } // END for AC_QUANTITY
  4386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4393. }
  4394. //============================ Voltage L1 ====================================
  4395. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4396. {
  4397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4398. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4399. {
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4401. {
  4402. tempIndex = ((gun_index==2) ? 1: 0);
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4409. {
  4410. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4411. {
  4412. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4413. }
  4414. } // END OF FOR CHAdeMO_QUANTITY
  4415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4416. }
  4417. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CCS_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4432. }
  4433. } // END OF FOR CCS_QUANTITY
  4434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < GB_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4451. }
  4452. } // END OF FOR GB_QUANTITY
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_DO)
  4456. {
  4457. tempIndex = gun_index;
  4458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4461. {
  4462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4463. }
  4464. }
  4465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4466. }
  4467. else
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4470. {
  4471. tempIndex = 2;
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < AC_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4480. {
  4481. 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
  4482. }
  4483. } // END OF FOR AC_QUANTITY
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4491. }
  4492. //====================== End SoC ================================
  4493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4494. {
  4495. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4496. 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))
  4497. {
  4498. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4499. {
  4500. tempIndex = ((gun_index==2) ? 1: 0);
  4501. }
  4502. else
  4503. {
  4504. tempIndex = gun_index;
  4505. }
  4506. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4507. {
  4508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4513. }
  4514. }
  4515. }
  4516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4517. {
  4518. for (int index = 0; index < CCS_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4521. {
  4522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4523. }
  4524. }
  4525. }
  4526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4527. {
  4528. for (int index = 0; index < GB_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4531. {
  4532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4533. }
  4534. }
  4535. }
  4536. else if(gunType[gun_index] == GUN_TYPE_DO)
  4537. {
  4538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4543. }
  4544. }
  4545. }
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4552. } // END FOR DC CASE
  4553. }
  4554. // ================================= Current.Import L2 ===============================================
  4555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4556. {
  4557. // AC 3 phse L2 current
  4558. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4573. }
  4574. }// End of for AC_QUANTITY
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4582. }
  4583. // ================================= Current.Import L3 ===============================================
  4584. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4585. {
  4586. // AC 3 phse L3 current
  4587. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4590. {
  4591. tempIndex = 2;
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < AC_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4600. {
  4601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4602. }
  4603. }// End of for AC_QUANTITY
  4604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4605. }
  4606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4611. }
  4612. //============================ Voltage L2 ====================================
  4613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4614. {
  4615. // AC 3 phse L2 voltage
  4616. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4617. {
  4618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4619. {
  4620. tempIndex = 2;
  4621. }
  4622. else
  4623. {
  4624. tempIndex = gun_index;
  4625. }
  4626. for (int index = 0; index < AC_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4629. {
  4630. 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
  4631. }
  4632. } // END OF FOR AC_QUANTITY
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4634. }
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4640. }
  4641. //============================ Voltage L3 ====================================
  4642. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4643. {
  4644. // AC 3 phse L3 voltage
  4645. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. 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
  4660. }
  4661. } // END OF FOR AC_QUANTITY
  4662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4669. }
  4670. //====================== Start SoC ================================
  4671. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4672. {
  4673. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4674. 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))
  4675. {
  4676. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4677. {
  4678. tempIndex = ((gun_index==2) ? 1: 0);
  4679. }
  4680. else
  4681. {
  4682. tempIndex = gun_index;
  4683. }
  4684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4685. {
  4686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4687. {
  4688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4689. {
  4690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4691. }
  4692. }
  4693. }
  4694. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4695. {
  4696. for (int index = 0; index < CCS_QUANTITY; index++)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4699. {
  4700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4701. }
  4702. }
  4703. }
  4704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4705. {
  4706. for (int index = 0; index < GB_QUANTITY; index++)
  4707. {
  4708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4709. {
  4710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4711. }
  4712. }
  4713. }
  4714. else if(gunType[gun_index] == GUN_TYPE_DO)
  4715. {
  4716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4717. {
  4718. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4719. {
  4720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4721. }
  4722. }
  4723. }
  4724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4730. } // END FOR DC CASE
  4731. }
  4732. //================================================ Message create ====================================================
  4733. json_object *StopTransaction = json_object_new_object();
  4734. json_object *transactionDatas = json_object_new_array();
  4735. json_object *sampledValues = json_object_new_array();
  4736. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4737. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4738. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4739. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4740. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4742. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4743. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4744. {
  4745. json_object *transactionData = json_object_new_object();
  4746. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4747. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4748. {
  4749. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4750. {
  4751. json_object *sampledValue = json_object_new_object();
  4752. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4753. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4754. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4755. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4756. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4758. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4759. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4760. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4761. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4762. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4763. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4764. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4765. json_object_array_add(sampledValues, sampledValue);
  4766. }
  4767. }
  4768. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4769. json_object_array_add(transactionDatas, transactionData);
  4770. }
  4771. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4772. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4773. ,MESSAGE_TYPE_CALL
  4774. ,guid
  4775. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4776. json_object_put(StopTransaction);
  4777. #if 1 // for TempStopTransaction
  4778. //Delete TempStopTransaction
  4779. if((access(TempStopTransaction,F_OK))!=-1)
  4780. {
  4781. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4782. }
  4783. #endif
  4784. #if 1
  4785. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4787. {
  4788. result = PASS;
  4789. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4790. }
  4791. #endif
  4792. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4793. OCPP_insert_transaction_msg(NO, queuedata);
  4794. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4795. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4796. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4797. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4798. {
  4799. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4800. }
  4801. //for test
  4802. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4803. return result;
  4804. }
  4805. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4806. {
  4807. mtrace();
  4808. int result = FAIL;
  4809. char guid[37]={0};
  4810. char tempdata[65]={0};
  4811. int tempIndex = 0;
  4812. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4813. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4814. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4815. //set value
  4816. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4817. 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) )?
  4818. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4819. -1);
  4820. random_uuid(guid);
  4821. //UTC Date time
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. gettimeofday(&tmnow, NULL);
  4826. time_t t;
  4827. t = time(NULL);
  4828. /*UTC time and date*/
  4829. tm = gmtime(&t);
  4830. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4832. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4833. //********************************(1)Current.Import L1************************************************/
  4834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4836. (dataType == ReadingContext_Trigger))
  4837. {
  4838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4842. {
  4843. tempIndex = ((gun_index==2) ? 1: 0);
  4844. }
  4845. else
  4846. {
  4847. tempIndex = gun_index;
  4848. }
  4849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4850. {
  4851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4852. {
  4853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4854. }
  4855. }
  4856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4857. }
  4858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < CCS_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4890. {
  4891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4892. }
  4893. }
  4894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_DO)
  4897. {
  4898. tempIndex = gun_index;
  4899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4904. }
  4905. }
  4906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4907. }
  4908. else
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4911. {
  4912. tempIndex = 2;
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < AC_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4923. }
  4924. }
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4926. }
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4932. }
  4933. //********************************(2)Energy.Active.Import.Register ************************************************/
  4934. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4935. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4936. (dataType == ReadingContext_Trigger))
  4937. {
  4938. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4940. {
  4941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4942. {
  4943. tempIndex = ((gun_index==2) ? 1: 0);
  4944. }
  4945. else
  4946. {
  4947. tempIndex = gun_index;
  4948. }
  4949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4954. }
  4955. }
  4956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4957. }
  4958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4961. {
  4962. tempIndex = ((gun_index==2) ? 1: 0);
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < CCS_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4980. {
  4981. tempIndex = ((gun_index==2) ? 1: 0);
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < GB_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4995. }
  4996. else if(gunType[gun_index] == GUN_TYPE_DO)
  4997. {
  4998. tempIndex = gun_index;
  4999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5007. }
  5008. else
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5011. {
  5012. tempIndex = 2;
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < AC_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5023. }
  5024. }
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5026. }
  5027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5032. }
  5033. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5034. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5035. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5036. (dataType == ReadingContext_Trigger))
  5037. {
  5038. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5040. {
  5041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5042. {
  5043. tempIndex = ((gun_index==2) ? 1: 0);
  5044. }
  5045. else
  5046. {
  5047. tempIndex = gun_index;
  5048. }
  5049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5050. {
  5051. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5052. {
  5053. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5054. }
  5055. } // END OF FOR CHAdeMO_QUANTITY
  5056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5057. }
  5058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CCS_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5073. }
  5074. } // END OF CCS_QUANTITY
  5075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < GB_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5092. }
  5093. } // END OF GB_QUANTITY
  5094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_DO)
  5097. {
  5098. tempIndex = gun_index;
  5099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5100. {
  5101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5102. {
  5103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5104. }
  5105. }
  5106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5107. }
  5108. else
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5111. {
  5112. tempIndex = 2;
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < AC_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5123. }
  5124. }
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5132. }
  5133. //********************************(4)Power.Active.Import************************************************/
  5134. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5135. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5136. (dataType == ReadingContext_Trigger))
  5137. {
  5138. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5139. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5140. {
  5141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5142. {
  5143. tempIndex = ((gun_index==2) ? 1: 0);
  5144. }
  5145. else
  5146. {
  5147. tempIndex = gun_index;
  5148. }
  5149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5152. {
  5153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5154. }
  5155. } // END OF FOR
  5156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5157. }
  5158. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CCS_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5173. }
  5174. }
  5175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < GB_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5190. {
  5191. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5192. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5193. }
  5194. }
  5195. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5196. }
  5197. else if(gunType[gun_index] == GUN_TYPE_DO)
  5198. {
  5199. tempIndex = gun_index;
  5200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5201. {
  5202. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5203. {
  5204. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5206. }
  5207. }
  5208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5209. }
  5210. else
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5213. {
  5214. tempIndex = 2;
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < AC_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5223. {
  5224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5225. }
  5226. }
  5227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5228. }
  5229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5234. }
  5235. //***********************************************(5)VOLTAGE L1******************************************************/
  5236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5238. (dataType == ReadingContext_Trigger))
  5239. {
  5240. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5241. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5242. {
  5243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5244. {
  5245. tempIndex = ((gun_index==2) ? 1: 0);
  5246. }
  5247. else
  5248. {
  5249. tempIndex = gun_index;
  5250. }
  5251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5254. {
  5255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5256. }
  5257. }
  5258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5259. }
  5260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5275. }
  5276. }
  5277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5282. {
  5283. tempIndex = ((gun_index==2) ? 1: 0);
  5284. }
  5285. else
  5286. {
  5287. tempIndex = gun_index;
  5288. }
  5289. for (int index = 0; index < GB_QUANTITY; index++)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5292. {
  5293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5294. }
  5295. }
  5296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5297. }
  5298. else if(gunType[gun_index] == GUN_TYPE_DO)
  5299. {
  5300. tempIndex = gun_index;
  5301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5306. }
  5307. }
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5309. }
  5310. else
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. tempIndex = 2;
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < AC_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5325. }
  5326. }
  5327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5328. }
  5329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5334. }
  5335. //***********************************************(6)SOC******************************************************/
  5336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5338. (dataType == ReadingContext_Trigger))
  5339. {
  5340. 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))
  5341. {
  5342. //idx_sample=5;
  5343. //sampledValue = NULL;
  5344. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5345. {
  5346. tempIndex = ((gun_index==2) ? 1: 0);
  5347. }
  5348. else
  5349. {
  5350. tempIndex = gun_index;
  5351. }
  5352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5353. {
  5354. //tempIndex = ((gun_index==2) ? 1: 0);
  5355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5358. {
  5359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5360. }
  5361. }
  5362. }
  5363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5364. {
  5365. //tempIndex = ((gun_index==2) ? 1: 0);
  5366. for (int index = 0; index < CCS_QUANTITY; index++)
  5367. {
  5368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5369. {
  5370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5371. }
  5372. }
  5373. }
  5374. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5375. {
  5376. //tempIndex = ((gun_index==2) ? 1: 0);
  5377. for (int index = 0; index < GB_QUANTITY; index++)
  5378. {
  5379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5380. {
  5381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5382. }
  5383. }
  5384. }
  5385. else if(gunType[gun_index] == GUN_TYPE_DO)
  5386. {
  5387. //tempIndex = ((gun_index==2) ? 1: 0);
  5388. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5389. {
  5390. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5391. {
  5392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5393. }
  5394. }
  5395. }
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5402. }
  5403. }
  5404. //********************************(7)Current.Import L2************************************************/
  5405. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5406. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5407. (dataType == ReadingContext_Trigger))
  5408. {
  5409. // Only for AC 3 phase
  5410. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5413. {
  5414. tempIndex = 2;
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < AC_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5425. }
  5426. }
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5428. }
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5434. }
  5435. //********************************(8)Current.Import L3************************************************/
  5436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5438. (dataType == ReadingContext_Trigger))
  5439. {
  5440. // Only for AC 3 phase
  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->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5456. }
  5457. }
  5458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5465. }
  5466. //***********************************************(9)VOLTAGE L2******************************************************/
  5467. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5468. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5469. (dataType == ReadingContext_Trigger))
  5470. {
  5471. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5474. {
  5475. tempIndex = 2;
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < AC_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5486. }
  5487. }
  5488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5489. }
  5490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5495. }
  5496. //***********************************************(10)VOLTAGE L3******************************************************/
  5497. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5498. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5499. (dataType == ReadingContext_Trigger))
  5500. {
  5501. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5502. {
  5503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5504. {
  5505. tempIndex = 2;
  5506. }
  5507. else
  5508. {
  5509. tempIndex = gun_index;
  5510. }
  5511. for (int index = 0; index < AC_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5514. {
  5515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5516. }
  5517. }
  5518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5519. }
  5520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5525. }
  5526. // Message create ====================================================================================================
  5527. if(TRUE)
  5528. {
  5529. json_object *MeterValueReq = json_object_new_object();
  5530. json_object *MeterValues = json_object_new_array();
  5531. json_object *sampledValues = json_object_new_array();
  5532. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5533. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5534. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5535. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5536. {
  5537. json_object *MeterValue = json_object_new_object();
  5538. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5539. {
  5540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5541. {
  5542. json_object *sampledValue = json_object_new_object();
  5543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5544. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5546. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5548. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5550. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5552. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5554. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5556. json_object_array_add(sampledValues, sampledValue);
  5557. }
  5558. }
  5559. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5560. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5561. json_object_array_add(MeterValues, MeterValue);
  5562. }
  5563. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5564. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5565. ,gun_index + 1
  5566. ,MESSAGE_TYPE_CALL
  5567. ,guid
  5568. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5569. json_object_put(MeterValueReq);
  5570. }
  5571. // Put request guid to hash map
  5572. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5573. 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*/)
  5574. {
  5575. result = PASS;
  5576. //DEBUG_INFO("MeterValues mapitem pass\n");
  5577. }
  5578. if((dataType != ReadingContext_Trigger) &&
  5579. (dataType != ReadingContext_Sample_Clock) &&
  5580. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5581. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5582. else
  5583. {
  5584. if(FirstHeartBeat)
  5585. LWS_Send(queuedata +2);
  5586. }
  5587. return result;
  5588. }
  5589. int sendLogStatusNotificationRequest(char *status)
  5590. {
  5591. mtrace();
  5592. int result = PASS;
  5593. char message[4096]={0};
  5594. char guid[37]={0};
  5595. char tempdata[128]={0};
  5596. json_object *LogStatusNotification = json_object_new_object();
  5597. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5598. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5599. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5600. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5601. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5602. random_uuid(guid);
  5603. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5604. json_object_put(LogStatusNotification);
  5605. LWS_Send(message);
  5606. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5607. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5608. {
  5609. result = PASS;
  5610. }
  5611. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5612. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5613. return result;
  5614. }
  5615. int sendSecurityEventNotificationRequest()
  5616. {
  5617. mtrace();
  5618. int result = PASS;
  5619. char message[4096]={0};
  5620. char guid[37]={0};
  5621. char tempdata[128]={0};
  5622. json_object *SecurityEventNotification = json_object_new_object();
  5623. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5624. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5625. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5626. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5627. random_uuid(guid);
  5628. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5629. json_object_put(SecurityEventNotification);
  5630. LWS_Send(message);
  5631. sprintf(tempdata, "SecurityEventNotification,0");
  5632. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5633. {
  5634. result = PASS;
  5635. }
  5636. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5637. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5638. return result;
  5639. }
  5640. int sendSignCertificateRequest()
  5641. {
  5642. mtrace();
  5643. int result = PASS;
  5644. char message[4096]={0};
  5645. char guid[37]={0};
  5646. char tempdata[128]={0};
  5647. json_object *SignCertificate = json_object_new_object();
  5648. DEBUG_INFO("sendSignCertificateRequest...\n");
  5649. // Read csr file content
  5650. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5651. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5652. char *line = NULL;
  5653. size_t len = 0;
  5654. while(getline(&line, &len, fp) != -1)
  5655. {
  5656. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5657. {
  5658. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5659. }
  5660. }
  5661. fclose(fp);
  5662. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5663. random_uuid(guid);
  5664. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5665. json_object_put(SignCertificate);
  5666. LWS_Send(message);
  5667. sprintf(tempdata, "SignCertificate,0");
  5668. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5669. {
  5670. result = PASS;
  5671. }
  5672. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5673. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5674. return result;
  5675. }
  5676. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5677. {
  5678. mtrace();
  5679. int result = PASS;
  5680. char message[110]={0};
  5681. char guid[37]={0};
  5682. char tempdata[65]={0};
  5683. json_object *FirmwareStatusNotification = json_object_new_object();
  5684. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5685. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5686. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5687. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5688. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5689. random_uuid(guid);
  5690. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5691. json_object_put(FirmwareStatusNotification);
  5692. LWS_Send(message);
  5693. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5694. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5695. {
  5696. result = PASS;
  5697. }
  5698. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5699. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5700. return result;
  5701. }
  5702. //==========================================
  5703. // send confirm routine
  5704. //==========================================
  5705. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5706. {
  5707. mtrace();
  5708. int result = FAIL;
  5709. char message[100]={0};
  5710. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5712. LWS_Send(message);
  5713. result = TRUE;
  5714. return result;
  5715. }
  5716. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5717. {
  5718. mtrace();
  5719. int result = FAIL;
  5720. char message[100]={0};
  5721. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5723. LWS_Send(message);
  5724. result = TRUE;
  5725. return result;
  5726. }
  5727. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. char message[100]={0};
  5732. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5734. LWS_Send(message);
  5735. result = TRUE;
  5736. return result;
  5737. }
  5738. int sendClearCacheConfirmation(char *uuid,char *payload)
  5739. {
  5740. mtrace();
  5741. int result = FAIL;
  5742. char message[500]={0};
  5743. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5744. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5745. LWS_Send(message);
  5746. return result;
  5747. }
  5748. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5749. {
  5750. mtrace();
  5751. int result = FAIL;
  5752. char message[500]={0};
  5753. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5754. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5755. LWS_Send(message);
  5756. return result;
  5757. }
  5758. int sendDataTransferConfirmation(char *uuid,char *payload)
  5759. {
  5760. mtrace();
  5761. char statusStr[20]={0};
  5762. char dataStr[10]={0};
  5763. char sstr[20]={0};
  5764. int c = 0;
  5765. char *loc;
  5766. int result = FAIL;
  5767. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5768. /**********************status**************************/
  5769. loc = strstr(payload, "status");
  5770. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5771. c = 0;
  5772. while (loc[3+strlen("status")+c] != '\"')
  5773. {
  5774. sstr[c] = loc[3+strlen("status")+c];
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. strcpy(statusStr, sstr);
  5779. /**********************data**************************/
  5780. loc = strstr(payload, "data");
  5781. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5782. c = 0;
  5783. while (loc[3+strlen("data")+c] != '\"')
  5784. {
  5785. sstr[c] = loc[3+strlen("data")+c];
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. strcpy(dataStr, sstr);
  5790. return result;
  5791. }
  5792. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5793. {
  5794. mtrace();
  5795. int result = FAIL;
  5796. char message[1000]={0};
  5797. int CompositeScheduleIndex = 0;
  5798. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5799. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5800. if(nPeriod == 0)
  5801. {
  5802. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5803. {
  5804. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5805. ,MESSAGE_TYPE_CALLRESULT
  5806. ,uuid
  5807. ,payload
  5808. ,connectorIdInt);
  5809. }
  5810. else
  5811. {
  5812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5813. ,MESSAGE_TYPE_CALLRESULT
  5814. ,uuid
  5815. ,payload
  5816. ,connectorIdInt
  5817. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5818. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5821. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5822. }
  5823. }
  5824. else
  5825. {
  5826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5827. ,MESSAGE_TYPE_CALLRESULT
  5828. ,uuid
  5829. ,payload
  5830. ,connectorIdInt
  5831. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5832. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5833. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5834. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5835. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5836. {
  5837. if (idx_sample == 0)
  5838. {
  5839. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5840. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5841. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5842. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5843. }
  5844. else
  5845. {
  5846. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5847. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5848. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5849. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5850. }
  5851. }
  5852. sprintf(message + strlen(message), "]}}]");
  5853. }
  5854. LWS_Send(message);
  5855. result = TRUE;
  5856. return result;
  5857. }
  5858. int sendGetConfigurationConfirmation(char *uuid)
  5859. {
  5860. mtrace();
  5861. int result = FAIL;
  5862. int MaxKeySupported = 0;
  5863. int sentConfigurationNumber= 0;
  5864. int sentunConfigurationNumber= 0;
  5865. char message[4000]={0};
  5866. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5867. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5868. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5869. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5870. ,MESSAGE_TYPE_CALLRESULT
  5871. ,uuid );
  5872. //configuration key
  5873. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5874. {
  5875. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5876. {
  5877. if (sentConfigurationNumber == 0)
  5878. {
  5879. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5880. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5881. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5882. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5883. }
  5884. else
  5885. {
  5886. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5887. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5888. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5889. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5890. }
  5891. sentConfigurationNumber = sentConfigurationNumber + 1;
  5892. }
  5893. }
  5894. sprintf(message + strlen(message), "]");
  5895. if(UnknownKeynum != 0)
  5896. {
  5897. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5898. //unkown key
  5899. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5900. {
  5901. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5902. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5903. if(sentunConfigurationNumber == 0)
  5904. {
  5905. sprintf(message + strlen(message), "\"%s\""
  5906. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5907. }
  5908. else
  5909. {
  5910. sprintf(message + strlen(message), ",\"%s\""
  5911. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5912. }
  5913. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5914. }
  5915. sprintf(message + strlen(message), "]");
  5916. }
  5917. sprintf(message + strlen(message), "}]");
  5918. LWS_Send(message);
  5919. return result;
  5920. }
  5921. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5922. {
  5923. mtrace();
  5924. int result = FAIL;
  5925. char message[400]={0};
  5926. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5927. if(strcmp(payload,"")==0)
  5928. {
  5929. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5930. }
  5931. else
  5932. {
  5933. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5934. }
  5935. LWS_Send(message);
  5936. result = TRUE;
  5937. return result;
  5938. }
  5939. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5940. {
  5941. mtrace();
  5942. int result = FAIL;
  5943. char message[80]={0};
  5944. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5945. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5946. LWS_Send(message);
  5947. result = TRUE;
  5948. return result;
  5949. }
  5950. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5951. {
  5952. mtrace();
  5953. int result = FAIL;
  5954. char message[80]={0};
  5955. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5957. LWS_Send(message);
  5958. result = TRUE;
  5959. return result;
  5960. }
  5961. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5962. {
  5963. mtrace();
  5964. int result = FAIL;
  5965. char message[80]={0};
  5966. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5968. LWS_Send(message);
  5969. result = TRUE;
  5970. return result;
  5971. }
  5972. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5973. {
  5974. mtrace();
  5975. int result = FAIL;
  5976. char message[80]={0};
  5977. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5978. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5980. LWS_Send(message);
  5981. result = TRUE;
  5982. return result;
  5983. }
  5984. int sendResetConfirmation(char *uuid,char *payload)
  5985. {
  5986. mtrace();
  5987. int result = FAIL;
  5988. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5989. char message[80]={0};
  5990. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5992. LWS_Send(message);
  5993. result = TRUE;
  5994. return result;
  5995. }
  5996. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char message[500]={0};
  6001. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6002. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6003. LWS_Send(message);
  6004. result = TRUE;
  6005. return result;
  6006. }
  6007. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6008. {
  6009. mtrace();
  6010. int result = FAIL;
  6011. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6012. char message[80]={0};
  6013. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6015. LWS_Send(message);
  6016. result = TRUE;
  6017. return result;
  6018. }
  6019. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6020. {
  6021. mtrace();
  6022. int result = FAIL;
  6023. char message[80]={0};
  6024. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6026. LWS_Send(message);
  6027. result = TRUE;
  6028. return result;
  6029. }
  6030. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. char message[80]={0};
  6035. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6036. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6037. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6038. LWS_Send(message);
  6039. result = TRUE;
  6040. return result;
  6041. }
  6042. int sendUpdateFirmwareConfirmation(char *uuid)
  6043. {
  6044. mtrace();
  6045. int result = FAIL;
  6046. char message[60]={0};
  6047. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6048. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6049. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6050. LWS_Send(message);
  6051. result = TRUE;
  6052. return result;
  6053. }
  6054. int sendCertificateSignedConfirmation(char *uuid)
  6055. {
  6056. mtrace();
  6057. int result = PASS;
  6058. char message[4096]={0};
  6059. json_object *CertificateSigned = json_object_new_object();
  6060. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6061. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6062. sprintf(message,"[%d,\"%s\",%s]"
  6063. ,MESSAGE_TYPE_CALLRESULT
  6064. ,uuid
  6065. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6066. json_object_put(CertificateSigned);
  6067. LWS_Send(message);
  6068. return result;
  6069. }
  6070. int sendDeleteCertificateConfirmation(char *uuid)
  6071. {
  6072. mtrace();
  6073. int result = PASS;
  6074. char message[4096]={0};
  6075. json_object *DeleteCertificate = json_object_new_object();
  6076. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6077. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6078. sprintf(message,"[%d,\"%s\",%s]"
  6079. ,MESSAGE_TYPE_CALLRESULT
  6080. ,uuid
  6081. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6082. json_object_put(DeleteCertificate);
  6083. LWS_Send(message);
  6084. return result;
  6085. }
  6086. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6087. {
  6088. mtrace();
  6089. int result = PASS;
  6090. char message[4096]={0};
  6091. json_object *ExtendedTriggerMessage = json_object_new_object();
  6092. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6093. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6094. sprintf(message,"[%d,\"%s\",%s]"
  6095. ,MESSAGE_TYPE_CALLRESULT
  6096. ,uuid
  6097. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6098. json_object_put(ExtendedTriggerMessage);
  6099. LWS_Send(message);
  6100. return result;
  6101. }
  6102. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6103. {
  6104. mtrace();
  6105. int result = PASS;
  6106. char message[4096]={0};
  6107. json_object *GetInstalledCertificateIds = json_object_new_object();
  6108. json_object *certificateHashDataDatas = json_object_new_array();
  6109. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6110. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6111. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6112. {
  6113. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6114. {
  6115. json_object *certificateHashData = json_object_new_object();
  6116. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6117. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6118. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6119. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6120. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6121. }
  6122. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6123. }
  6124. else
  6125. {
  6126. json_object_put(certificateHashDataDatas);
  6127. }
  6128. sprintf(message,"[%d,\"%s\",%s]"
  6129. ,MESSAGE_TYPE_CALLRESULT
  6130. ,uuid
  6131. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6132. json_object_put(GetInstalledCertificateIds);
  6133. LWS_Send(message);
  6134. return result;
  6135. }
  6136. int sendGetLogConfirmation(char *uuid)
  6137. {
  6138. mtrace();
  6139. int result = PASS;
  6140. char message[4096]={0};
  6141. json_object *GetLog = json_object_new_object();
  6142. DEBUG_INFO("sendGetLogConfirmation...\n");
  6143. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6144. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6145. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6146. sprintf(message,"[%d,\"%s\",%s]"
  6147. ,MESSAGE_TYPE_CALLRESULT
  6148. ,uuid
  6149. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6150. json_object_put(GetLog);
  6151. LWS_Send(message);
  6152. return result;
  6153. }
  6154. int sendInstallCertificateConfirmation(char *uuid)
  6155. {
  6156. mtrace();
  6157. int result = PASS;
  6158. char message[4096]={0};
  6159. json_object *InstallCertificate = json_object_new_object();
  6160. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6161. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6162. sprintf(message,"[%d,\"%s\",%s]"
  6163. ,MESSAGE_TYPE_CALLRESULT
  6164. ,uuid
  6165. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6166. json_object_put(InstallCertificate);
  6167. LWS_Send(message);
  6168. return result;
  6169. }
  6170. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6171. {
  6172. mtrace();
  6173. int result = PASS;
  6174. char message[4096]={0};
  6175. json_object *SignedUpdateFirmware = json_object_new_object();
  6176. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6177. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6178. sprintf(message,"[%d,\"%s\",%s]"
  6179. ,MESSAGE_TYPE_CALLRESULT
  6180. ,uuid
  6181. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6182. json_object_put(SignedUpdateFirmware);
  6183. LWS_Send(message);
  6184. return result;
  6185. }
  6186. int sendUnknownConfirmation(char *uuid)
  6187. {
  6188. mtrace();
  6189. int result = PASS;
  6190. char message[256]={0};
  6191. DEBUG_INFO("sendUnknownConfirmation...\n");
  6192. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6193. LWS_Send(message);
  6194. return result;
  6195. }
  6196. //==========================================
  6197. // Handle server request routine Start
  6198. //==========================================
  6199. int handleCancelReservationRequest(char *uuid, char *payload)
  6200. {
  6201. mtrace();
  6202. int result = FAIL;
  6203. int gunNO = 0;
  6204. int reservationIdInt = -1;
  6205. char comfirmstr[20];
  6206. DEBUG_INFO("handleCancelReservationRequest...\n");
  6207. json_object *CancelReservation;
  6208. CancelReservation = json_tokener_parse(payload);
  6209. if(!is_error(CancelReservation))
  6210. {
  6211. // Required data
  6212. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6213. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6214. }
  6215. json_object_put(CancelReservation);
  6216. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6217. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6218. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6219. if(reservationIdInt != -1)
  6220. {
  6221. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6222. //check Transaction active
  6223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6227. {
  6228. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6229. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6230. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6231. {
  6232. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6233. }
  6234. else
  6235. {
  6236. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6237. }
  6238. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6239. goto end;
  6240. }
  6241. }
  6242. for (int index = 0; index < CCS_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6245. {
  6246. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6247. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6248. if(gunType[2] == GUN_TYPE_CCS)
  6249. {
  6250. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6251. }
  6252. else
  6253. {
  6254. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6255. }
  6256. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6257. goto end;
  6258. }
  6259. }
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6263. {
  6264. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6265. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6266. if(gunType[2] == GUN_TYPE_GBT)
  6267. {
  6268. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6269. }
  6270. else
  6271. {
  6272. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6273. }
  6274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6275. goto end;
  6276. }
  6277. }
  6278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6281. {
  6282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6284. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6285. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6286. goto end;
  6287. }
  6288. }
  6289. for (int index = 0; index < AC_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6292. {
  6293. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6294. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6296. {
  6297. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6298. }
  6299. else
  6300. {
  6301. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6302. }
  6303. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6304. goto end;
  6305. }
  6306. }
  6307. }
  6308. //The reservationId does NOT match the reservationId
  6309. sendCancelReservationConfirmation(uuid, comfirmstr);
  6310. end:
  6311. // Fill in ocpp packet uuid
  6312. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6313. return result;
  6314. }
  6315. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6316. {
  6317. mtrace();
  6318. int result = FAIL;
  6319. int gunIndex = 0;
  6320. char typeStr[16]={0};
  6321. char comfirmstr[20];
  6322. int specificId = FALSE;
  6323. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6324. json_object *ChangeAvailability;
  6325. ChangeAvailability = json_tokener_parse(payload);
  6326. if(!is_error(ChangeAvailability))
  6327. {
  6328. // Required data
  6329. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6330. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6331. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6332. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6333. }
  6334. json_object_put(ChangeAvailability);
  6335. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6336. {
  6337. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6338. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6339. }
  6340. else if(gunIndex == 0)
  6341. {
  6342. for(int i=0; i < gunTotalNumber; i++)
  6343. {
  6344. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6345. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6346. }
  6347. }
  6348. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6350. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6351. {
  6352. specificId = TRUE;
  6353. }
  6354. if(specificId == FALSE)
  6355. goto end;
  6356. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6357. {
  6358. //----------------------gunIndex is 0 ------------------------------------------------//
  6359. if(gunIndex == 0)
  6360. {
  6361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6362. {
  6363. for(int i=0; i < gunTotalNumber; i++)
  6364. {
  6365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6366. {
  6367. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6370. {
  6371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6372. goto end;
  6373. }
  6374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6379. {
  6380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6381. goto end;
  6382. }
  6383. }
  6384. }//END FOR CHAdeMO_QUANTITY
  6385. for (int index = 0; index < CCS_QUANTITY; index++)
  6386. {
  6387. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6388. {
  6389. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6390. {
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6392. goto end;
  6393. }
  6394. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6398. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6399. {
  6400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6401. goto end;
  6402. }
  6403. }
  6404. }//END FOR CCS_QUANTITY
  6405. for (int index = 0; index < GB_QUANTITY; index++)
  6406. {
  6407. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6408. {
  6409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6410. {
  6411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6412. goto end;
  6413. }
  6414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6419. {
  6420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6421. goto end;
  6422. }
  6423. }
  6424. }// END FOR GB_QUANTITY
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6430. {
  6431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6432. goto end;
  6433. }
  6434. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6439. {
  6440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6441. goto end;
  6442. }
  6443. }
  6444. }// END FOR GENERAL_GUN_QUANTITY
  6445. for (int index = 0; index < AC_QUANTITY; index++)
  6446. {
  6447. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6448. {
  6449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6450. {
  6451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6452. goto end;
  6453. }
  6454. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6459. {
  6460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6461. goto end;
  6462. }
  6463. }
  6464. }//END FOR AC_QUANTITY
  6465. }// END FOR gunTotalNumber
  6466. }
  6467. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6468. {
  6469. for(int i=0; i < gunTotalNumber; i++)
  6470. {
  6471. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6472. {
  6473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6474. goto end;
  6475. }
  6476. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6478. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6481. {
  6482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6483. goto end;
  6484. }
  6485. }
  6486. }
  6487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6488. goto end;
  6489. }
  6490. //----------------------gunIndex is not 0 ------------------------------------------------//
  6491. //check Transaction active
  6492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6493. {
  6494. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6495. {
  6496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6497. {
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6499. goto end;
  6500. }
  6501. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6502. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6505. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6506. {
  6507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6508. goto end;
  6509. }
  6510. else
  6511. {
  6512. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6514. goto end;
  6515. }
  6516. }
  6517. }//END FOR CHAdeMO_QUANTITY
  6518. for (int index = 0; index < CCS_QUANTITY; index++)
  6519. {
  6520. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6523. {
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6525. goto end;
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6530. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6532. {
  6533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6534. goto end;
  6535. }
  6536. else
  6537. {
  6538. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6540. goto end;
  6541. }
  6542. }
  6543. }//END FOR CCS_QUANTITY
  6544. for (int index = 0; index < GB_QUANTITY; index++)
  6545. {
  6546. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6547. {
  6548. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6549. {
  6550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6551. goto end;
  6552. }
  6553. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6556. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6557. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6558. {
  6559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6560. goto end;
  6561. }
  6562. else
  6563. {
  6564. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6566. goto end;
  6567. }
  6568. }
  6569. }// END FOR GB_QUANTITY
  6570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6571. {
  6572. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6575. {
  6576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6577. goto end;
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6583. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6584. {
  6585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6586. goto end;
  6587. }
  6588. else
  6589. {
  6590. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6592. goto end;
  6593. }
  6594. }
  6595. }// END FOR GENERAL_GUN_QUANTITY
  6596. for (int index = 0; index < AC_QUANTITY; index++)
  6597. {
  6598. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6599. {
  6600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6601. {
  6602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6603. goto end;
  6604. }
  6605. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6608. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6609. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6610. {
  6611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6612. goto end;
  6613. }
  6614. else
  6615. {
  6616. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6618. goto end;
  6619. }
  6620. }
  6621. }//END FOR AC_QUANTITY
  6622. }//END FOR AvailabilityTypeStr[Inoperative]
  6623. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6624. {
  6625. //----------------------gunIndex is 0 ------------------------------------------------//
  6626. if(gunIndex == 0)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6629. {
  6630. for(int i=0; i < gunTotalNumber; i++)
  6631. {
  6632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6633. {
  6634. 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
  6635. {
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6637. goto end;
  6638. }
  6639. }//END FOR CHAdeMO_QUANTITY
  6640. for (int index = 0; index < CCS_QUANTITY; index++)
  6641. {
  6642. 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
  6643. {
  6644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6645. goto end;
  6646. }
  6647. }//END FOR CCS_QUANTITY
  6648. for (int index = 0; index < GB_QUANTITY; index++)
  6649. {
  6650. 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
  6651. {
  6652. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6654. goto end;
  6655. }
  6656. }// END FOR GB_QUANTITY
  6657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6658. {
  6659. 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
  6660. {
  6661. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6663. goto end;
  6664. }
  6665. }// END FOR GENERAL_GUN_QUANTITY
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. 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
  6669. {
  6670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6671. goto end;
  6672. }
  6673. }//END FOR CHAdeMO_QUANTITY
  6674. }// END FOR gunTotalNumber
  6675. }
  6676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6677. {
  6678. for(int i=0; i < gunTotalNumber; i++)
  6679. {
  6680. for (int index = 0; index < AC_QUANTITY; index++)
  6681. {
  6682. 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
  6683. {
  6684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6685. goto end;
  6686. }
  6687. }//END FOR CHAdeMO_QUANTITY
  6688. } // END FOR gunTotalNumber
  6689. }
  6690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6691. goto end;
  6692. }
  6693. //----------------------gunIndex is not 0 ------------------------------------------------//
  6694. //check Transaction active
  6695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6696. {
  6697. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6698. {
  6699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6700. goto end;
  6701. }
  6702. }//END FOR CHAdeMO_QUANTITY
  6703. for (int index = 0; index < CCS_QUANTITY; index++)
  6704. {
  6705. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6706. {
  6707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6708. goto end;
  6709. }
  6710. }//END FOR CCS_QUANTITY
  6711. for (int index = 0; index < GB_QUANTITY; index++)
  6712. {
  6713. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6714. {
  6715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6716. goto end;
  6717. }
  6718. }// END FOR GB_QUANTITY
  6719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6720. {
  6721. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6722. {
  6723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6724. goto end;
  6725. }
  6726. }// END FOR GENERAL_GUN_QUANTITY
  6727. for (int index = 0; index < AC_QUANTITY; index++)
  6728. {
  6729. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6730. {
  6731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6732. goto end;
  6733. }
  6734. }//END FOR AC_QUANTITY
  6735. }//END FOR AvailabilityTypeStr[Operative]
  6736. end:
  6737. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6740. }
  6741. else
  6742. {
  6743. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6744. }
  6745. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6746. {
  6747. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6748. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6749. }
  6750. else if(gunIndex == 0)
  6751. {
  6752. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6753. {
  6754. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6755. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6756. }
  6757. }
  6758. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6760. return result;
  6761. }
  6762. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. char keystr[40]={0};
  6767. char valuestr[256]={0};
  6768. char comfirmstr[20]={0};
  6769. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6770. json_object *ChangeConfiguration;
  6771. ChangeConfiguration = json_tokener_parse(payload);
  6772. if(!is_error(ChangeConfiguration))
  6773. {
  6774. // Required data
  6775. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6776. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6777. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6778. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6779. }
  6780. json_object_put(ChangeConfiguration);
  6781. if((uuid==NULL) || (payload ==NULL) )
  6782. {
  6783. DEBUG_ERROR("Payload is null\n");
  6784. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6785. }
  6786. else
  6787. {
  6788. int status = setKeyValue(keystr, valuestr);
  6789. switch(status)
  6790. {
  6791. case ConfigurationStatus_Accepted:
  6792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6793. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6794. StoreConfigurationTable();
  6795. break;
  6796. case RebootRequired:
  6797. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6798. StoreConfigurationTable();
  6799. break;
  6800. case NotSupported:
  6801. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6802. break;
  6803. case ConfigurationStatus_Rejected:
  6804. default:
  6805. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6806. break;
  6807. }
  6808. }
  6809. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6810. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6811. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6812. {
  6813. ChageWebSocketPingInterval(atoi(valuestr));
  6814. }
  6815. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6816. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6817. {
  6818. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6819. SetOcppConnStatus(FALSE);
  6820. }
  6821. return result;
  6822. }
  6823. int handleClearCacheRequest(char *uuid, char *payload)
  6824. {
  6825. mtrace();
  6826. int result = FAIL;
  6827. char comfirmstr[20];
  6828. char rmFileCmd[100]={0};
  6829. struct stat stats;
  6830. DEBUG_INFO("handleClearCacheRequest...\n");
  6831. stat("/Storage/OCPP", &stats);
  6832. // Check for directory existence
  6833. if (S_ISDIR(stats.st_mode) == 1)
  6834. {}
  6835. else
  6836. {
  6837. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6838. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6839. system(rmFileCmd);
  6840. }
  6841. if(OCPP_cleanLocalCache())
  6842. {
  6843. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6844. }
  6845. else
  6846. {
  6847. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6848. }
  6849. sendClearCacheConfirmation(uuid, comfirmstr);
  6850. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6851. return result;
  6852. }
  6853. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6854. {
  6855. mtrace();
  6856. int result = FAIL;
  6857. int resultRename;
  6858. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6859. char chargingProfilePurposeStr[26]={0};
  6860. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6861. char tempchargingProfilePurposeStr[26]={0};
  6862. char str[100]={0};
  6863. char fname[200]={0};
  6864. char comfirmstr[20]={0};
  6865. char word[1600]={0};
  6866. int clearflag = FALSE;
  6867. int chargingProfileIdIsNULL = FALSE;
  6868. int connectorIsNULL = FALSE;
  6869. int chargingProfilePurposeIsNULL = FALSE;
  6870. int stackLevelIsNULL = FALSE;
  6871. //int GotoEnd = FALSE;
  6872. FILE *fptr1, *fptr2;
  6873. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6874. int n_chargingProfile=0;
  6875. int isEmptyFile = FALSE;
  6876. char sLineWord[1600]={0};
  6877. char chargingProfiles[10][100]={0};
  6878. int ChargeProfileCount = 0;
  6879. int ch;
  6880. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6881. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6882. json_object *ClearChargingProfile;
  6883. ClearChargingProfile = json_tokener_parse(payload);
  6884. if(!is_error(ClearChargingProfile))
  6885. {
  6886. // Optional data
  6887. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6888. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6889. else
  6890. chargingProfileIdIsNULL = TRUE;
  6891. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6892. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6893. else
  6894. connectorIsNULL = TRUE;
  6895. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6896. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6897. else
  6898. chargingProfilePurposeIsNULL = TRUE;
  6899. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6900. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6901. else
  6902. stackLevelIsNULL = TRUE;
  6903. }
  6904. json_object_put(ClearChargingProfile);
  6905. if(connectorIsNULL == FALSE)
  6906. {
  6907. switch(connectorIdInt)
  6908. {
  6909. case 0:
  6910. if(chargingProfilePurposeIsNULL == TRUE)
  6911. {
  6912. int l = 0;
  6913. strcpy(fname, ChargePointMaxProfile_JSON);
  6914. if((access(fname,F_OK))!=-1)
  6915. {
  6916. strcpy(chargingProfiles[l], fname);
  6917. l = l + 1;
  6918. }
  6919. strcpy(fname, TxDefaultProfile_0_JSON);
  6920. if((access(fname,F_OK))!=-1)
  6921. {
  6922. strcpy(chargingProfiles[l], fname);
  6923. l = l + 1;
  6924. }
  6925. ChargeProfileCount = l;
  6926. }
  6927. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6928. {
  6929. strcpy(fname, ChargePointMaxProfile_JSON);
  6930. if((access(fname,F_OK))!=-1)
  6931. {
  6932. strcpy(chargingProfiles[0], fname);
  6933. ChargeProfileCount = 1;
  6934. }
  6935. }
  6936. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6937. {
  6938. strcpy(fname, TxDefaultProfile_0_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[0], fname);
  6942. ChargeProfileCount = 1;
  6943. }
  6944. }
  6945. break;
  6946. default:
  6947. if(chargingProfilePurposeIsNULL == TRUE)
  6948. {
  6949. int m = 0;
  6950. memset(fname, 0, ARRAY_SIZE(fname));
  6951. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6952. if((access(fname,F_OK))!=-1)
  6953. {
  6954. strcpy(chargingProfiles[m], fname);
  6955. m = m + 1;
  6956. }
  6957. memset(fname, 0, ARRAY_SIZE(fname));
  6958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6959. if((access(fname,F_OK))!=-1)
  6960. {
  6961. strcpy(chargingProfiles[m], fname);
  6962. m = m + 1;
  6963. }
  6964. ChargeProfileCount = m;
  6965. }
  6966. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6967. {
  6968. //strcpy(fname, TxDefaultProfile_1_JSON);
  6969. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6970. if((access(fname,F_OK))!=-1)
  6971. {
  6972. strcpy(chargingProfiles[0], fname);
  6973. ChargeProfileCount = 1;
  6974. }
  6975. }
  6976. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6977. {
  6978. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6979. if((access(fname,F_OK))!=-1)
  6980. {
  6981. strcpy(chargingProfiles[0], fname);
  6982. ChargeProfileCount = 1;
  6983. }
  6984. //strcpy(fname, TxProfile_1_JSON);
  6985. }
  6986. //strcpy(fname, ChargePointMaxProfile_JSON );
  6987. break;
  6988. }
  6989. }
  6990. else // Check all Charging Profiles
  6991. {
  6992. int i = 0;
  6993. char fnametemp[200]={0};
  6994. ChargeProfileCount = 0;
  6995. //Check ChargePointMaxProfile.json exit
  6996. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6997. {
  6998. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6999. i = i + 1;
  7000. }
  7001. //Check TxDefaultProfile_0.json exit
  7002. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7003. {
  7004. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7005. i = i + 1;
  7006. }
  7007. //Check TxDefaultProfile_%d.json
  7008. for(int j=1; j <= gunTotalNumber; j++)
  7009. {
  7010. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7011. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7012. if((access(fnametemp,F_OK))!=-1)
  7013. {
  7014. strcpy(chargingProfiles[i], fnametemp);
  7015. i = i + 1;
  7016. }
  7017. }
  7018. //Check TxProfile_%d.json
  7019. for(int j=1; j <= gunTotalNumber; j++)
  7020. {
  7021. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7022. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7023. if((access(fnametemp,F_OK))!=-1)
  7024. {
  7025. strcpy(chargingProfiles[i], fnametemp);
  7026. i = i + 1;
  7027. }
  7028. }
  7029. ChargeProfileCount = i;
  7030. }// End connectorIsNULL is TRUE
  7031. if(ChargeProfileCount == 0)
  7032. {
  7033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7034. goto end;
  7035. }
  7036. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7037. {
  7038. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7039. goto end;
  7040. }
  7041. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7042. {
  7043. memset(str, 0, ARRAY_SIZE(str));
  7044. // clear temp file
  7045. sprintf(str,"rm -f %s",temp);
  7046. system(str);
  7047. for(int k=0; k < ChargeProfileCount; k++)
  7048. {
  7049. memset(str, 0, ARRAY_SIZE(str));
  7050. //clear file in C
  7051. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7052. system(str);
  7053. }
  7054. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7055. goto end;
  7056. }
  7057. else if(connectorIsNULL == TRUE)
  7058. {
  7059. for(int k=0; k < ChargeProfileCount; k++)
  7060. {
  7061. fptr1 = fopen(chargingProfiles[k], "r");
  7062. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7063. //Check Charging Profile Count
  7064. while(fscanf(fptr1, "%s", word) != EOF)
  7065. {
  7066. //DEBUG_INFO("word=%s\n",word);
  7067. if(strstr(word, "chargingProfileId")!= NULL)
  7068. {
  7069. //DEBUG_INFO("test chargingProfileId \n");
  7070. n_chargingProfile = n_chargingProfile + 1;
  7071. //DEBUG_INFO("chargingProfileId Found\n");
  7072. }
  7073. }
  7074. rewind(fptr1);
  7075. //search Charging Profile Element
  7076. //int i= 0;
  7077. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7078. {
  7079. json_object *tmpProfilee;
  7080. tmpProfilee = json_tokener_parse(sLineWord);
  7081. if(!is_error(tmpProfilee))
  7082. {
  7083. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7084. {
  7085. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7086. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7087. }
  7088. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7089. {
  7090. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7091. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7092. }
  7093. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7094. {
  7095. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7096. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7097. }
  7098. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7099. {
  7100. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7101. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7102. }
  7103. }
  7104. json_object_put(tmpProfilee);
  7105. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7106. {
  7107. //------- not write to fptr2-------//
  7108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7109. //clearflag = TRUE;
  7110. }
  7111. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7112. {
  7113. //------- not write to fptr2-------//
  7114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7115. }
  7116. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7117. {
  7118. //------- not write to fptr2-------//
  7119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7120. }
  7121. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7122. {
  7123. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7124. }
  7125. else
  7126. {
  7127. fprintf(fptr2, sLineWord);//writing data into file
  7128. }
  7129. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7130. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7131. if(clearflag == TRUE)
  7132. {
  7133. fclose(fptr1);
  7134. fclose(fptr2);
  7135. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7136. system(str);
  7137. // clear temp file
  7138. sprintf(str,"rm -f %s",temp);
  7139. system(str);
  7140. }
  7141. else
  7142. {
  7143. fclose(fptr1);
  7144. fclose(fptr2);
  7145. memset(str, 0, ARRAY_SIZE(str));
  7146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7147. system(str);
  7148. resultRename = rename(temp, chargingProfiles[k]);
  7149. if(resultRename == 0)
  7150. {
  7151. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7152. }
  7153. else
  7154. {
  7155. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7156. }
  7157. if(comfirmstr[0]== 0)
  7158. {
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7160. }
  7161. //Check chargingProfile is empty file
  7162. /*------ Read the file ----------------*/
  7163. fptr1=fopen(chargingProfiles[k],"r");
  7164. ch=fgetc(fptr1);
  7165. rewind(fptr1);
  7166. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7167. if(ch!=EOF)
  7168. {
  7169. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7170. {
  7171. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7172. if(sLineWord[0]=='\0')
  7173. {
  7174. isEmptyFile = TRUE;
  7175. break;
  7176. }
  7177. else
  7178. {
  7179. isEmptyFile = FALSE;
  7180. break;
  7181. }
  7182. }
  7183. }
  7184. else
  7185. isEmptyFile = TRUE;
  7186. fclose(fptr1);
  7187. if(isEmptyFile == TRUE)
  7188. {
  7189. memset(str, 0, ARRAY_SIZE(str));
  7190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7191. system(str);
  7192. }
  7193. }
  7194. }// End of while(int k=0; k < ChargePointCount; k++)
  7195. }
  7196. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7197. {
  7198. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7199. for(int k=0; k < ChargeProfileCount; k++)
  7200. {
  7201. fptr1 = fopen(chargingProfiles[k], "r");
  7202. fptr2 = fopen(temp, "w+");
  7203. //Check Charging Profile Count
  7204. while(fscanf(fptr1, "%s", word) != EOF)
  7205. {
  7206. //DEBUG_INFO("word=%s\n",word);
  7207. if(strstr(word, "chargingProfileId")!= NULL)
  7208. {
  7209. n_chargingProfile = n_chargingProfile + 1;
  7210. }
  7211. }
  7212. rewind(fptr1);
  7213. //search Charging Profile Element
  7214. //int i= 0;
  7215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7216. {
  7217. json_object *tmpProfilee;
  7218. tmpProfilee = json_tokener_parse(sLineWord);
  7219. if(!is_error(tmpProfilee))
  7220. {
  7221. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7222. {
  7223. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7224. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7225. }
  7226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7227. {
  7228. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7229. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7230. }
  7231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7232. {
  7233. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7234. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7235. }
  7236. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7237. {
  7238. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7239. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7240. }
  7241. }
  7242. json_object_put(tmpProfilee);
  7243. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7244. {
  7245. //------- not write to fptr2-------//
  7246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7247. //clearflag = TRUE;
  7248. }
  7249. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7250. {
  7251. //------- not write to fptr2-------//
  7252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7253. }
  7254. else if(stackLevelIsNULL == TRUE)
  7255. {
  7256. //Clear Whole File
  7257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7258. clearflag = TRUE;
  7259. break;
  7260. }
  7261. else
  7262. {
  7263. fprintf(fptr2, sLineWord);//writing data into file
  7264. }
  7265. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7266. }
  7267. if(clearflag == TRUE)
  7268. {
  7269. fclose(fptr1);
  7270. fclose(fptr2);
  7271. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7272. system(str);
  7273. // clear temp file
  7274. sprintf(str,"rm -f %s",temp);
  7275. system(str);
  7276. }
  7277. else
  7278. {
  7279. fclose(fptr1);
  7280. fclose(fptr2);
  7281. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7282. system(str);
  7283. resultRename = rename(temp, chargingProfiles[k]);
  7284. if(resultRename == 0)
  7285. {
  7286. DEBUG_INFO("File ChargingProfile renamed successfully");
  7287. }
  7288. else
  7289. {
  7290. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7291. }
  7292. if(comfirmstr[0]== 0)
  7293. {
  7294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7295. }
  7296. //Check chargingProfile is empty file
  7297. /*------ Read the file ----------------*/
  7298. fptr1=fopen(chargingProfiles[k],"r");
  7299. ch=fgetc(fptr1);
  7300. rewind(fptr1);
  7301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7302. if(ch!=EOF)
  7303. {
  7304. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7305. {
  7306. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7307. if(sLineWord[0]=='\0')
  7308. {
  7309. isEmptyFile = TRUE;
  7310. break;
  7311. }
  7312. else
  7313. {
  7314. isEmptyFile = FALSE;
  7315. break;
  7316. }
  7317. }
  7318. }
  7319. else
  7320. isEmptyFile = TRUE;
  7321. fclose(fptr1);
  7322. if(isEmptyFile == TRUE)
  7323. {
  7324. memset(str, 0, ARRAY_SIZE(str));
  7325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7326. system(str);
  7327. }
  7328. /*------- End of reading ---------------*/
  7329. }
  7330. } // while(int k=0; k < ChargeProfileCount; k++)
  7331. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7332. end:
  7333. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7334. {
  7335. if(connectorIdInt == 0)
  7336. {
  7337. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7338. {
  7339. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7340. }
  7341. }
  7342. else
  7343. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7344. }
  7345. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7346. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7347. return result;
  7348. }
  7349. void createFirmwareVersionByDataTransfer(void)
  7350. {
  7351. json_object *FirmwareDataTransfer = json_object_new_object();
  7352. // AC & DC model
  7353. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7354. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7355. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7356. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7357. // DC model
  7358. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7359. {
  7360. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7361. {
  7362. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7363. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7364. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7365. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7366. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7367. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7368. }
  7369. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7370. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7371. {
  7372. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7373. }
  7374. }
  7375. else
  7376. {
  7377. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7381. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7390. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7391. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7392. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7393. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7394. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7395. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7396. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7397. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7398. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7399. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7400. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7401. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7402. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7403. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7404. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7405. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7406. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7407. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7408. }
  7409. // 4G model
  7410. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7411. {
  7412. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7413. }
  7414. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7415. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7416. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7417. json_object_put(FirmwareDataTransfer);
  7418. }
  7419. int handleDataTransferRequest(char *uuid, char *payload)
  7420. {
  7421. mtrace();
  7422. json_object *response = json_object_new_object();
  7423. int result = FAIL;
  7424. char tempvendorId[255]={0};
  7425. char tempmessageId[50]={0};
  7426. char tempdata[512]={0};
  7427. char message[2048]={0};
  7428. DEBUG_INFO("handleDataTransferRequest...\n");
  7429. if((uuid != NULL) && (payload != NULL))
  7430. {
  7431. json_object *DataTransfer;
  7432. DataTransfer = json_tokener_parse(payload);
  7433. if(!is_error(DataTransfer))
  7434. {
  7435. // Required data
  7436. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7437. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7438. // Optional data
  7439. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7440. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7441. if(json_object_object_get(DataTransfer, "data") != NULL)
  7442. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7443. result = PASS;
  7444. }
  7445. json_object_put(DataTransfer);
  7446. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7447. {
  7448. // Send all moudle firmware version on EVSE
  7449. createFirmwareVersionByDataTransfer();
  7450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7451. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7452. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7453. json_object_put(response);
  7454. }
  7455. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7456. {
  7457. system("/usr/bin/run_tmate_restart.sh &");
  7458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7459. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(response);
  7461. }
  7462. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7463. {
  7464. json_object *data;
  7465. data = json_tokener_parse(tempdata);
  7466. if(!is_error(data))
  7467. {
  7468. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7469. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7470. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7471. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7472. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7473. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7474. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7475. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7479. }
  7480. else
  7481. {
  7482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7484. }
  7485. json_object_put(data);
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7490. {
  7491. json_object *data;
  7492. data = json_tokener_parse(tempdata);
  7493. if(!is_error(data))
  7494. {
  7495. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7496. if(json_object_object_get(data, "idToken") != NULL)
  7497. {
  7498. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7499. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7500. }
  7501. if(json_object_object_get(data, "price") != NULL)
  7502. {
  7503. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7504. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7505. }
  7506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7507. }
  7508. else
  7509. {
  7510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7512. }
  7513. json_object_put(data);
  7514. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7515. json_object_put(response);
  7516. }
  7517. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7518. {
  7519. json_object *data;
  7520. data = json_tokener_parse(tempdata);
  7521. if(!is_error(data))
  7522. {
  7523. if(json_object_object_get(data, "txId") != NULL)
  7524. {
  7525. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7526. for(int idx = 0;idx<gunTotalNumber;idx++)
  7527. {
  7528. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7529. {
  7530. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7531. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7532. if(json_object_object_get(data, "description") != NULL)
  7533. {
  7534. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7535. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7536. }
  7537. }
  7538. }
  7539. }
  7540. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7541. }
  7542. else
  7543. {
  7544. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7545. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7546. }
  7547. json_object_put(data);
  7548. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7549. json_object_put(response);
  7550. }
  7551. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7552. {
  7553. json_object *data;
  7554. data = json_tokener_parse(tempdata);
  7555. if(!is_error(data))
  7556. {
  7557. if(json_object_object_get(data, "txId") != NULL)
  7558. {
  7559. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7560. for(int idx = 0;idx<gunTotalNumber;idx++)
  7561. {
  7562. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7563. {
  7564. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7565. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7566. if(json_object_object_get(data, "description") != NULL)
  7567. {
  7568. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7569. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7570. }
  7571. }
  7572. }
  7573. }
  7574. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7575. }
  7576. else
  7577. {
  7578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7579. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7580. }
  7581. json_object_put(data);
  7582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7583. json_object_put(response);
  7584. }
  7585. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7586. {
  7587. json_object *data;
  7588. data = json_tokener_parse(tempdata);
  7589. if(!is_error(data))
  7590. {
  7591. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7592. if(json_object_object_get(data, "Content_Type") != NULL)
  7593. {
  7594. 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))
  7595. {
  7596. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7597. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7598. {
  7599. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7600. }
  7601. }
  7602. else
  7603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7604. }
  7605. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7606. }
  7607. else
  7608. {
  7609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7610. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7611. }
  7612. json_object_put(data);
  7613. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7614. json_object_put(response);
  7615. }
  7616. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7617. {
  7618. json_object *data;
  7619. data = json_tokener_parse(tempdata);
  7620. if(!is_error(data))
  7621. {
  7622. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7623. if(json_object_object_get(data, "Page_Index") != NULL)
  7624. {
  7625. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7626. }
  7627. if(json_object_object_get(data, "Duration") != NULL)
  7628. {
  7629. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7630. }
  7631. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7632. }
  7633. else
  7634. {
  7635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7637. }
  7638. json_object_put(data);
  7639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7640. json_object_put(response);
  7641. }
  7642. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7643. {
  7644. json_object *data;
  7645. data = json_tokener_parse(tempdata);
  7646. if(!is_error(data))
  7647. {
  7648. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7649. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7650. {
  7651. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7652. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7653. else
  7654. {
  7655. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7656. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7657. }
  7658. }
  7659. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7660. {
  7661. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7662. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7663. else
  7664. {
  7665. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7666. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7667. }
  7668. }
  7669. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7670. {
  7671. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7672. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7673. else
  7674. {
  7675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7677. }
  7678. }
  7679. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7680. {
  7681. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7682. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7683. else
  7684. {
  7685. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7686. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7687. }
  7688. }
  7689. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7690. {
  7691. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7692. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7693. else
  7694. {
  7695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7696. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7697. }
  7698. }
  7699. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7700. {
  7701. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7702. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7703. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7704. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7705. else
  7706. {
  7707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7708. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7709. }
  7710. }
  7711. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7712. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7713. }
  7714. else
  7715. {
  7716. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7717. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7718. }
  7719. json_object_put(data);
  7720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7721. json_object_put(response);
  7722. }
  7723. else
  7724. {
  7725. // Can not find valid message id
  7726. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7727. }
  7728. }
  7729. else
  7730. {
  7731. // Payload is null
  7732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7733. }
  7734. LWS_Send(message);
  7735. return result;
  7736. }
  7737. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7738. {
  7739. mtrace();
  7740. int result = FAIL;
  7741. int connectorIdInt, durationInt;
  7742. char chargingRateUnitStr[4]={0};
  7743. char comfirmstr[20];
  7744. int confirmPeriods = 0;
  7745. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7746. json_object *GetCompositeSchedule;
  7747. GetCompositeSchedule = json_tokener_parse(payload);
  7748. if(!is_error(GetCompositeSchedule))
  7749. {
  7750. // Required data
  7751. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7752. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7753. else
  7754. connectorIdInt = -1;
  7755. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7756. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7757. else
  7758. durationInt = 86400;
  7759. // Optional data
  7760. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7761. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7762. }
  7763. json_object_put(GetCompositeSchedule);
  7764. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7765. if((connectorIdInt == 0) ||
  7766. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7767. {
  7768. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7769. struct StructChargingProfile tmpProfile[1];
  7770. if(strstr(chargingRateUnitStr, "W") != NULL)
  7771. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7772. else
  7773. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7774. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7775. {
  7776. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7777. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7778. }
  7779. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7780. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7781. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7782. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7783. {
  7784. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7785. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7786. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7787. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7788. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7789. {
  7790. confirmPeriods = idx;
  7791. break;
  7792. }
  7793. }
  7794. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7795. {
  7796. confirmPeriods += 1;
  7797. }
  7798. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7799. }
  7800. else
  7801. {
  7802. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7803. }
  7804. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7805. return result;
  7806. }
  7807. int handleGetConfigurationRequest(char *uuid, char *payload)
  7808. {
  7809. mtrace();
  7810. int result = FAIL;
  7811. int MaxKeySupported = 0;
  7812. int n_keys = 0;
  7813. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7814. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7815. json_object *GetConfiguration;
  7816. GetConfiguration = json_tokener_parse(payload);
  7817. if(!is_error(GetConfiguration))
  7818. {
  7819. // Optional data
  7820. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7821. {
  7822. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7823. {
  7824. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7825. n_keys = idx + 1;
  7826. }
  7827. }
  7828. }
  7829. json_object_put(GetConfiguration);
  7830. UnknownKeynum = 0;
  7831. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7832. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7833. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7834. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7835. if(n_keys != 0)
  7836. {
  7837. for(int i=0;i<n_keys;i++)
  7838. {
  7839. getKeyValue(requestKey[i]);
  7840. }
  7841. }
  7842. else
  7843. {
  7844. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7845. getKeyValue("");
  7846. }
  7847. processUnkownKey();
  7848. sendGetConfigurationConfirmation(uuid);
  7849. return result;
  7850. }
  7851. static char fnamePlusPath[100]={0};
  7852. static char fnamePWithNoPath[60]={0};
  7853. void checkUploadLog(void)
  7854. {
  7855. FILE *fp;
  7856. /* Open the command for reading. */
  7857. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7858. if (fp == NULL) {
  7859. printf("Failed to run command\n" );
  7860. exit(1);
  7861. }
  7862. int ftppathlen = 0;
  7863. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7864. int i = 0;
  7865. /* Read the output a line at a time - output it. */
  7866. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7867. if(i==0)
  7868. {
  7869. ftppathlen = strlen(fnamePlusPath);
  7870. printf("%s\n", fnamePlusPath);
  7871. fnamePlusPath[ftppathlen]='\0';
  7872. break;
  7873. }
  7874. i= i+1;
  7875. }
  7876. /* close */
  7877. pclose(fp);
  7878. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7879. {
  7880. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7881. {
  7882. fnamePlusPath[k]='\0';
  7883. }
  7884. }
  7885. i=1;
  7886. //char fname[60]={0};
  7887. while(i < ftppathlen)
  7888. {
  7889. int len=ftppathlen-i;
  7890. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7891. {
  7892. printf("compare '/' all right\n");
  7893. break;
  7894. }
  7895. i=i+1;
  7896. }
  7897. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7898. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7899. fnamePWithNoPath[i+1] = '\0';
  7900. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7901. {
  7902. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7903. {
  7904. fnamePWithNoPath[j]='\0';
  7905. }
  7906. }
  7907. FILE* fp1 = fopen(fnamePlusPath, "r");
  7908. if (fp1)
  7909. {
  7910. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7911. // file exists
  7912. fclose(fp1);
  7913. }
  7914. else
  7915. {
  7916. // file doesn't exist
  7917. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7918. }
  7919. }
  7920. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. time_t CurrentTime;
  7925. struct tm *tm;
  7926. pthread_t th_Status;
  7927. CurrentTime = time(NULL);
  7928. tm = localtime(&CurrentTime);
  7929. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7930. 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);
  7931. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7932. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7933. return result;
  7934. }
  7935. void* GetDiagnosticsProcess(void* data)
  7936. {
  7937. pthread_detach(pthread_self());
  7938. mtrace();
  7939. int retriesInt=0, retryIntervalInt=0;
  7940. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7941. 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};
  7942. int port=0;
  7943. int isSuccess = FALSE;
  7944. char cmdBuf[2048];
  7945. struct tm *tmNow;
  7946. time_t CurrentTime;
  7947. struct tm tmStart;
  7948. struct tm tmStop;
  7949. CurrentTime = time(NULL);
  7950. tmNow=localtime(&CurrentTime);
  7951. uint16_t targetYear, targetMonth;
  7952. json_object *GetDiagnostics;
  7953. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7954. GetDiagnostics = json_tokener_parse(data);
  7955. if(!is_error(GetDiagnostics))
  7956. {
  7957. // Required data
  7958. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7959. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7960. // Optional data
  7961. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7962. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7963. else
  7964. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7965. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7966. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7967. else
  7968. retryIntervalInt = 30;
  7969. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7970. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7971. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7972. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7973. }
  7974. json_object_put(GetDiagnostics);
  7975. // Pack log to compress file
  7976. 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) &&
  7977. (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))
  7978. {
  7979. // Pack system log
  7980. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7981. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7982. targetYear = tmStart.tm_year;
  7983. targetMonth = tmStart.tm_mon;
  7984. do
  7985. {
  7986. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7987. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  7988. if(targetMonth+1>=13)
  7989. {
  7990. targetYear += 1;
  7991. targetMonth = 1;
  7992. }
  7993. else
  7994. {
  7995. targetMonth += 1;
  7996. }
  7997. }while((targetYear < (tmNow->tm_year+1900)) ||
  7998. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7999. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8000. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8001. system(cmdBuf);
  8002. // Pack charging & event log
  8003. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8004. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8005. targetYear = tmStart.tm_year;
  8006. targetMonth = tmStart.tm_mon;
  8007. do
  8008. {
  8009. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8010. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8011. if(targetMonth+1>=13)
  8012. {
  8013. targetYear += 1;
  8014. targetMonth = 1;
  8015. }
  8016. else
  8017. {
  8018. targetMonth += 1;
  8019. }
  8020. }while((targetYear < (tmNow->tm_year+1900)) ||
  8021. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8022. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8023. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8024. system(cmdBuf);
  8025. // Combine log file
  8026. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8027. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8028. }
  8029. else
  8030. {
  8031. system("exec /root/logPackTools 'log' 6");
  8032. }
  8033. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8034. system(cmdBuf);
  8035. checkUploadLog();
  8036. //****************location*******************/
  8037. if(strcmp(locationstr,"")==0)
  8038. {
  8039. DEBUG_INFO("location is <Empty>!\n");
  8040. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8041. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8042. goto end;
  8043. }
  8044. memset(protocol, 0, ARRAY_SIZE(protocol));
  8045. memset(user, 0, ARRAY_SIZE(user) );
  8046. memset(password, 0, ARRAY_SIZE(password));
  8047. memset(host, 0, ARRAY_SIZE(host));
  8048. memset(path, 0, ARRAY_SIZE(path));
  8049. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8050. memset(host1, 0, ARRAY_SIZE(host1));
  8051. memset(path1, 0, ARRAY_SIZE(path1));
  8052. /*location: ftp://user:password@host:port/path*/
  8053. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8054. if((access(fnamePlusPath,F_OK))!=-1)
  8055. {
  8056. DEBUG_INFO("fnamePlusPath exist.\n");
  8057. }
  8058. else
  8059. {
  8060. DEBUG_INFO("fnamePlusPath not exist!\n");
  8061. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8062. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8063. goto end;
  8064. }
  8065. if(strchr(locationstr,'@')==NULL)
  8066. {
  8067. sscanf(locationstr,
  8068. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8069. protocol, host, &port, path);
  8070. strcpy(user,"anonymous");
  8071. strcpy(password,"");
  8072. }
  8073. else
  8074. {
  8075. //DEBUG_INFO("pch=%s\n", pch);
  8076. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8077. protocol, user, password, host, &port, path);
  8078. }
  8079. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8080. {
  8081. DEBUG_INFO("protocol is not ftp/http ! \n");
  8082. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8083. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8084. goto end;
  8085. }
  8086. if(strncmp(locationstr,"http", 4) == 0)
  8087. {
  8088. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8089. sprintf(ftppath,"/%s", path);
  8090. do
  8091. {
  8092. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8093. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8094. sleep(3);
  8095. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8096. if(!isSuccess)
  8097. {
  8098. DEBUG_INFO("Diagnostics fail.\n");
  8099. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8100. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8101. sleep(retryIntervalInt);
  8102. }
  8103. else
  8104. {
  8105. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8106. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8107. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8108. }
  8109. retriesInt--;
  8110. }while((isSuccess == 0)&&(retriesInt >= 0));
  8111. }
  8112. else
  8113. {
  8114. sscanf(host,"%[^/]%s",host1, path1);
  8115. if(strlen(path) > 0)
  8116. sprintf(ftppath,"/%s", path);
  8117. else
  8118. sprintf(ftppath,"/%s", path1);
  8119. int ftppathlen=strlen(ftppath);
  8120. int i=1;
  8121. char filenametemp[50];
  8122. while(i < ftppathlen)
  8123. {
  8124. int len=ftppathlen-i;
  8125. if(ftppath[len]== 47) // '/' ascll code: 47
  8126. {
  8127. DEBUG_INFO("find '/' all right\n");
  8128. break;
  8129. }
  8130. i=i+1;
  8131. }
  8132. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8133. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8134. filenametemp[i+1] = 0;
  8135. if(port == 0)
  8136. port = 21;
  8137. do
  8138. {
  8139. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8140. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8141. sleep(3);
  8142. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8143. if(!isSuccess)
  8144. {
  8145. DEBUG_INFO("Diagnostics fail.\n");
  8146. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8147. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8148. sleep(retryIntervalInt);
  8149. }
  8150. else
  8151. {
  8152. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8153. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8154. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8155. }
  8156. retriesInt--;
  8157. }while((!isSuccess)&&(retriesInt >= 0));
  8158. }
  8159. end:
  8160. system("rm -f /mnt/*");
  8161. sleep(5);
  8162. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8163. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8164. pthread_exit(NULL);
  8165. }
  8166. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8167. {
  8168. mtrace();
  8169. int result = FAIL;
  8170. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8171. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8172. {
  8173. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8174. locallistVersion = -1;
  8175. }
  8176. else
  8177. {
  8178. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8179. OCPP_getListVerion();
  8180. }
  8181. //from db.OCPP_getListVerion
  8182. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8183. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8184. sendGetLocalListVersionConfirmation(uuid,"");
  8185. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8186. return result;
  8187. }
  8188. int handleRemoteStartRequest(char *uuid, char *payload)
  8189. {
  8190. mtrace();
  8191. int result = FAIL;
  8192. int connectorIdInt=0;
  8193. int tempIndex = 0;
  8194. int connectorIdIsNULL, chargingProfileIsNULL;
  8195. char comfirmstr[20]={0};
  8196. char cmdBuf[512];
  8197. json_object *RemoteStartTransaction;
  8198. FILE *fp;
  8199. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8200. if(server_pending == TRUE)
  8201. {
  8202. return 0;
  8203. }
  8204. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8205. RemoteStartTransaction = json_tokener_parse(payload);
  8206. if(!is_error(RemoteStartTransaction))
  8207. {
  8208. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8209. {
  8210. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8211. if(connectorIdInt <= gunTotalNumber)
  8212. {
  8213. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8214. // Required data
  8215. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8216. // Optional data
  8217. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8218. {
  8219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8220. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8221. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8222. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8223. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8224. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8225. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8226. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8227. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8228. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8229. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8230. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8231. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8232. {
  8233. 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")));
  8234. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8235. 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"));
  8236. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8237. 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"));
  8238. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8239. 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")));
  8240. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8241. {
  8242. 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++)
  8243. {
  8244. 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"));
  8245. 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"));
  8246. 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)
  8247. 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"));
  8248. }
  8249. }
  8250. }
  8251. }
  8252. else
  8253. chargingProfileIsNULL = TRUE;
  8254. }
  8255. }
  8256. else
  8257. connectorIdIsNULL = TRUE;
  8258. }
  8259. else
  8260. connectorIdIsNULL = TRUE;
  8261. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8262. {
  8263. DEBUG_WARN("Connector id is NULL\n.");
  8264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8265. goto end;
  8266. }
  8267. /*
  8268. enum _SYSTEM_STATUS
  8269. {
  8270. S_BOOTING = 0,
  8271. S_IDLE, = 1
  8272. S_AUTHORIZING, = 2
  8273. S_REASSIGN_CHECK, = 3
  8274. S_REASSIGN, = 4
  8275. S_PRECHARGE, = 5
  8276. S_PREPARING_FOR_EV, = 6
  8277. S_PREPARING_FOR_EVSE, = 7
  8278. S_CHARGING, = 8
  8279. S_TERMINATING, = 9
  8280. S_COMPLETE, = 10
  8281. S_ALARM, = 11
  8282. S_FAULT = 12
  8283. }
  8284. */
  8285. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8286. {
  8287. //check Transaction active
  8288. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8289. {
  8290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8291. {
  8292. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8293. }
  8294. else
  8295. {
  8296. tempIndex = connectorIdInt -1;
  8297. }
  8298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8299. {
  8300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8301. {
  8302. 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))
  8303. {
  8304. //Reserved
  8305. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8306. }
  8307. 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))
  8308. {
  8309. //Reserved
  8310. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8312. goto end;
  8313. }
  8314. else
  8315. {
  8316. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8317. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8318. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8319. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8320. {
  8321. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8323. goto end;
  8324. }
  8325. }//END FOR ELSE
  8326. }
  8327. }// END FOR CHAdeMO_QUANTITY
  8328. }
  8329. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8330. {
  8331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8332. {
  8333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8334. }
  8335. else
  8336. {
  8337. tempIndex = connectorIdInt -1;
  8338. }
  8339. for (int index = 0; index < CCS_QUANTITY; index++)
  8340. {
  8341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8342. {
  8343. 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))
  8344. {
  8345. //Reserved
  8346. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8347. }
  8348. 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))
  8349. {
  8350. //Reserved
  8351. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8353. goto end;
  8354. }
  8355. else
  8356. {
  8357. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8358. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8359. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8360. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8361. {
  8362. DEBUG_WARN("CCS connector not allow start\n.");
  8363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8364. goto end;
  8365. }
  8366. }// END FOR ELSE
  8367. }
  8368. }// END FOR CCS_QUANTITY
  8369. }
  8370. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8371. {
  8372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8373. {
  8374. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8375. }
  8376. else
  8377. {
  8378. tempIndex = connectorIdInt -1;
  8379. }
  8380. for (int index = 0; index < GB_QUANTITY; index++)
  8381. {
  8382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8383. {
  8384. 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))
  8385. {
  8386. //Reserved
  8387. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8388. }
  8389. 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))
  8390. {
  8391. //Reserved
  8392. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8394. goto end;
  8395. }
  8396. else
  8397. {
  8398. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8399. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8400. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8401. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8402. {
  8403. DEBUG_WARN("GB connector not allow start\n.");
  8404. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8405. goto end;
  8406. }
  8407. }// END FOR ELSE
  8408. }
  8409. } // END FOR GB_QUANTITY
  8410. }
  8411. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8412. {
  8413. tempIndex = connectorIdInt -1;
  8414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8415. {
  8416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8417. {
  8418. 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))
  8419. {
  8420. //Reserved
  8421. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8422. }
  8423. 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))
  8424. {
  8425. //Reserved
  8426. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8427. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8428. goto end;
  8429. }
  8430. else
  8431. {
  8432. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8433. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8434. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8435. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8436. {
  8437. DEBUG_WARN("GB connector not allow start\n.");
  8438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8439. goto end;
  8440. }
  8441. }// END FOR ELSE
  8442. }
  8443. } // END FOR GB_QUANTITY
  8444. }
  8445. else
  8446. {
  8447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8448. {
  8449. tempIndex = 2;
  8450. }
  8451. else
  8452. {
  8453. tempIndex = connectorIdInt -1;
  8454. }
  8455. for (int index = 0; index < AC_QUANTITY; index++)
  8456. {
  8457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8458. {
  8459. 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))
  8460. {
  8461. //Reserved
  8462. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8463. }
  8464. 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))
  8465. {
  8466. //Reserved
  8467. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8468. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8469. goto end;
  8470. }
  8471. else
  8472. {
  8473. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8474. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8475. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8476. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8477. {
  8478. DEBUG_WARN("AC connector not allow start\n.");
  8479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8480. goto end;
  8481. }
  8482. }//END FOR ELSE
  8483. }
  8484. }// END FOR AC_QUANTITY
  8485. }
  8486. if(chargingProfileIsNULL == FALSE)
  8487. {
  8488. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8489. {
  8490. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8492. //memset idTag
  8493. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8494. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8495. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8496. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8497. // Save profile to file
  8498. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8499. system(cmdBuf);
  8500. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8501. fp = fopen(cmdBuf, "w");
  8502. 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));
  8503. fclose(fp);
  8504. }
  8505. else
  8506. {
  8507. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8509. }
  8510. }
  8511. else
  8512. {
  8513. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8515. //memset idTag
  8516. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8517. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8518. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8519. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8520. }
  8521. }
  8522. else
  8523. {
  8524. DEBUG_WARN("Connector id over\n.");
  8525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8526. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8527. }
  8528. end:
  8529. json_object_put(RemoteStartTransaction);
  8530. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8531. {
  8532. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8533. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8534. }
  8535. //OCPP send RemoteStartConfirmation by first.
  8536. sendRemoteStartConfirmation(uuid, comfirmstr);
  8537. return result;
  8538. }
  8539. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8540. {
  8541. mtrace();
  8542. int result = FAIL;
  8543. int match = FALSE;
  8544. int GunNO = 0;
  8545. int tempIndex = 0;
  8546. int transactionIdInt=0;
  8547. int transactionIdIsNULL= TRUE;
  8548. char comfirmstr[20];
  8549. json_object *RemoteStopTransaction;
  8550. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8551. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8552. if(server_pending == TRUE)
  8553. {
  8554. return 0;
  8555. }
  8556. RemoteStopTransaction = json_tokener_parse(payload);
  8557. if(!is_error(RemoteStopTransaction))
  8558. {
  8559. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8560. {
  8561. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8562. transactionIdIsNULL = FALSE;
  8563. }
  8564. }
  8565. json_object_put(RemoteStopTransaction);
  8566. if(transactionIdIsNULL == FALSE)
  8567. {
  8568. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8569. {
  8570. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8571. {
  8572. //check Transaction active
  8573. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8574. {
  8575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8576. {
  8577. tempIndex = ((gun_index==2) ? 1: 0);
  8578. }
  8579. else
  8580. {
  8581. tempIndex = gun_index;
  8582. }
  8583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8584. {
  8585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8586. {
  8587. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8588. {
  8589. match = TRUE;
  8590. GunNO = gun_index;
  8591. }
  8592. }
  8593. }// END FOR CHAdeMO_QUANTITY
  8594. }
  8595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8596. {
  8597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8598. {
  8599. tempIndex = ((gun_index==2) ? 1: 0);
  8600. }
  8601. else
  8602. {
  8603. tempIndex = gun_index;
  8604. }
  8605. for (int index = 0; index < CCS_QUANTITY; index++)
  8606. {
  8607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8608. {
  8609. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8610. {
  8611. match = TRUE;
  8612. GunNO = gun_index;
  8613. }
  8614. }
  8615. }// END FOR CCS_QUANTITY
  8616. }
  8617. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8618. {
  8619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8620. {
  8621. tempIndex = ((gun_index==2) ? 1: 0);
  8622. }
  8623. else
  8624. {
  8625. tempIndex = gun_index;
  8626. }
  8627. for (int index = 0; index < GB_QUANTITY; index++)
  8628. {
  8629. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8630. {
  8631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8632. {
  8633. match = TRUE;
  8634. GunNO = gun_index;
  8635. }
  8636. }
  8637. }// END FOR GB_QUANTITY
  8638. }
  8639. else if(gunType[gun_index] == GUN_TYPE_DO)
  8640. {
  8641. tempIndex = gun_index;
  8642. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8643. {
  8644. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8645. {
  8646. 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
  8647. {
  8648. match = TRUE;
  8649. GunNO = gun_index;
  8650. }
  8651. }
  8652. }// END FOR GB_QUANTITY
  8653. }
  8654. else
  8655. {
  8656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8657. {
  8658. tempIndex = 2;
  8659. }
  8660. else
  8661. {
  8662. tempIndex = gun_index;
  8663. }
  8664. for (int index = 0; index < AC_QUANTITY; index++)
  8665. {
  8666. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8667. {
  8668. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8669. {
  8670. match = TRUE;
  8671. GunNO = gun_index;
  8672. }
  8673. }
  8674. }// END FOR CHAdeMO_QUANTITY
  8675. } // END FOR AC ELSE
  8676. }// CHECK IF ResponseTransactionId == transactionIdInt
  8677. }//END FOR
  8678. if( match == TRUE)
  8679. {
  8680. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8681. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8682. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8683. }
  8684. else
  8685. {
  8686. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8687. }
  8688. }
  8689. else
  8690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8691. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8692. return result;
  8693. }
  8694. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8695. {
  8696. mtrace();
  8697. int result = FAIL;
  8698. int connectorIdInt=0, reservationIdInt=0;
  8699. int tempIndex = 0;
  8700. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8701. char comfirmstr[20]={0};
  8702. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8703. int c = 0;
  8704. char *loc;
  8705. //char *ptr;
  8706. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8707. strcpy(sstrtemp, stringtrimspace(payload));
  8708. //***(1)connectorId ****/
  8709. c=0;
  8710. loc = strstr(sstrtemp, "connectorId");
  8711. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8712. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8713. {
  8714. sstr[c] = loc[strlen("connectorId")+2+c];
  8715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8716. c++;
  8717. }
  8718. sstr[c] = '\0';
  8719. connectorIdInt = atoi(sstr);
  8720. //***(2)expiryDate ****/
  8721. loc = strstr(sstrtemp, "expiryDate");
  8722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8723. c = 0;
  8724. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8725. {
  8726. sstr[c] = loc[3+strlen("expiryDate")+c];
  8727. c++;
  8728. }
  8729. sstr[c] = '\0';
  8730. strcpy(expiryDatestr, sstr);
  8731. //***(3)idTag ****/
  8732. loc = strstr(sstrtemp, "idTag");
  8733. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8734. c = 0;
  8735. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8736. {
  8737. sstr[c] = loc[3+strlen("idTag")+c];
  8738. c++;
  8739. }
  8740. sstr[c] = '\0';
  8741. strcpy(idTagstr, sstr);
  8742. //***(4)parentIdTag ****/
  8743. loc = strstr(sstrtemp, "parentIdTag");
  8744. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8745. c = 0;
  8746. if(loc == NULL)
  8747. {
  8748. strcpy(parentIdTagstr, "");
  8749. }
  8750. else
  8751. {
  8752. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8753. {
  8754. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8755. c++;
  8756. }
  8757. sstr[c] = '\0';
  8758. strcpy(parentIdTagstr, sstr);
  8759. }
  8760. //***(5)reservationId ****/
  8761. c=0;
  8762. loc = strstr(sstrtemp, "reservationId");
  8763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8764. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8765. {
  8766. sstr[c] = loc[strlen("reservationId")+2+c];
  8767. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8768. c++;
  8769. }
  8770. sstr[c] = '\0';
  8771. reservationIdInt = atoi(sstr);
  8772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8773. /*
  8774. enum SYSTEM_STATUS
  8775. {
  8776. SYS_MODE_BOOTING = 0,
  8777. SYS_MODE_IDLE = 1,
  8778. SYS_MODE_AUTHORIZING = 2,
  8779. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8780. SYS_MODE_REASSIGN = 4,
  8781. SYS_MODE_PREPARING = 5,
  8782. SYS_MODE_PREPARE_FOR_EV = 6,
  8783. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8784. SYS_MODE_CHARGING = 8,
  8785. SYS_MODE_TERMINATING = 9,
  8786. SYS_MODE_COMPLETE = 10,
  8787. SYS_MODE_ALARM = 11,
  8788. SYS_MODE_FAULT = 12,
  8789. SYS_MODE_RESERVATION = 13,
  8790. SYS_MODE_BOOKING = 14,
  8791. SYS_MODE_MAINTAIN = 15,
  8792. SYS_MODE_DEBUG = 16,
  8793. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8794. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8795. SYS_MODE_UPDATE = 19
  8796. };
  8797. */
  8798. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8799. {
  8800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8801. goto end;
  8802. }
  8803. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8804. {
  8805. //check Transaction active
  8806. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8807. {
  8808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8809. {
  8810. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8811. }
  8812. else
  8813. {
  8814. tempIndex = connectorIdInt -1;
  8815. }
  8816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8817. {
  8818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8819. {
  8820. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8821. {
  8822. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8823. {
  8824. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8825. {
  8826. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8828. }
  8829. 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'))
  8830. {
  8831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8832. }
  8833. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8834. {
  8835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8836. }
  8837. else
  8838. {
  8839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8840. }
  8841. }
  8842. 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
  8843. {
  8844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8845. }
  8846. }
  8847. else
  8848. {
  8849. //replace reservation
  8850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8852. }
  8853. }
  8854. } // END FOR CHAdeMO_QUANTITY
  8855. }
  8856. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8857. {
  8858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8859. {
  8860. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8861. }
  8862. else
  8863. {
  8864. tempIndex = connectorIdInt -1;
  8865. }
  8866. for (int index = 0; index < CCS_QUANTITY; index++)
  8867. {
  8868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8869. {
  8870. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8871. {
  8872. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8873. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8874. {
  8875. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8876. {
  8877. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8879. }
  8880. 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'))
  8881. {
  8882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8883. }
  8884. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8885. {
  8886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8887. }
  8888. else
  8889. {
  8890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8891. }
  8892. }
  8893. 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
  8894. {
  8895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8896. }
  8897. }
  8898. else
  8899. {
  8900. //replace reservation
  8901. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8903. }
  8904. }
  8905. } // END FOR CCS_QUANTITY
  8906. }
  8907. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8908. {
  8909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8910. {
  8911. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8912. }
  8913. else
  8914. {
  8915. tempIndex = connectorIdInt -1;
  8916. }
  8917. for (int index = 0; index < GB_QUANTITY; index++)
  8918. {
  8919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8920. {
  8921. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8922. {
  8923. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8924. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8925. {
  8926. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8927. {
  8928. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8930. }
  8931. 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'))
  8932. {
  8933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8934. }
  8935. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8936. {
  8937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8938. }
  8939. else
  8940. {
  8941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8942. }
  8943. }
  8944. 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
  8945. {
  8946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8947. }
  8948. }
  8949. else
  8950. {
  8951. //replace reservation
  8952. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8954. }
  8955. }
  8956. }// END FOR GB_QUANTITY
  8957. }
  8958. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8959. {
  8960. tempIndex = connectorIdInt -1;
  8961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8962. {
  8963. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8964. {
  8965. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8966. {
  8967. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8968. 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
  8969. {
  8970. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8971. {
  8972. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8974. }
  8975. 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'))
  8976. {
  8977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8978. }
  8979. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8980. {
  8981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8982. }
  8983. else
  8984. {
  8985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8986. }
  8987. }
  8988. 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
  8989. {
  8990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8991. }
  8992. }
  8993. else
  8994. {
  8995. //replace reservation
  8996. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8998. }
  8999. }
  9000. }// END FOR GB_QUANTITY
  9001. }
  9002. else
  9003. {
  9004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9005. {
  9006. tempIndex = 2;
  9007. }
  9008. else
  9009. {
  9010. tempIndex = (connectorIdInt -1);
  9011. }
  9012. for (int index = 0; index < AC_QUANTITY; index++)
  9013. {
  9014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9015. {
  9016. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9017. {
  9018. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9019. {
  9020. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9021. {
  9022. 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))
  9023. {
  9024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9025. }
  9026. else
  9027. {
  9028. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9030. }
  9031. }
  9032. 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'))
  9033. {
  9034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9035. }
  9036. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9037. {
  9038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9039. }
  9040. else
  9041. {
  9042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9043. }
  9044. }
  9045. 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
  9046. {
  9047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9048. }
  9049. }
  9050. else
  9051. {
  9052. //replace reservation
  9053. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9055. }
  9056. }
  9057. } // END FOR AC_QUANTITY
  9058. }
  9059. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9060. }
  9061. else if(connectorIdInt == 0)
  9062. {
  9063. //check Transaction active
  9064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9065. {
  9066. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9067. {
  9068. 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'))
  9069. {
  9070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9071. goto end;
  9072. }
  9073. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9074. {
  9075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9076. goto end;
  9077. }
  9078. 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
  9079. {
  9080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9081. goto end;
  9082. }
  9083. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9084. {
  9085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9086. goto end;
  9087. }
  9088. }
  9089. }// END FOR CHAdeMO_QUANTITY
  9090. for (int index = 0; index < CCS_QUANTITY; index++)
  9091. {
  9092. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9093. {
  9094. 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'))
  9095. {
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9097. goto end;
  9098. }
  9099. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9100. {
  9101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9102. goto end;
  9103. }
  9104. 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
  9105. {
  9106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9107. goto end;
  9108. }
  9109. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9110. {
  9111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9112. goto end;
  9113. }
  9114. }
  9115. } // END FOR CCS_QUANTITY
  9116. for (int index = 0; index < GB_QUANTITY; index++)
  9117. {
  9118. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9119. {
  9120. 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'))
  9121. {
  9122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9123. goto end;
  9124. }
  9125. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9126. {
  9127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9128. goto end;
  9129. }
  9130. 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
  9131. {
  9132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9133. goto end;
  9134. }
  9135. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9136. {
  9137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9138. goto end;
  9139. }
  9140. }
  9141. } // END FOR GB_QUANTITY
  9142. for (int index = 0; index < AC_QUANTITY; index++)
  9143. {
  9144. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9145. {
  9146. 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'))
  9147. {
  9148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9149. goto end;
  9150. }
  9151. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9152. {
  9153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9154. goto end;
  9155. }
  9156. 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
  9157. {
  9158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9159. goto end;
  9160. }
  9161. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9162. {
  9163. 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))
  9164. {
  9165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9166. goto end;
  9167. }
  9168. }
  9169. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9170. {
  9171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9172. goto end;
  9173. }
  9174. }
  9175. }// END FOR AC_QUANTITY
  9176. //The connectorId is 0
  9177. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9179. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9180. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9181. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9182. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9183. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9184. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9185. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9186. result = TRUE;
  9187. return result;
  9188. }
  9189. else
  9190. {
  9191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9192. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9193. }
  9194. if(strcmp(comfirmstr,"Accepted") == 0)
  9195. {
  9196. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9197. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9198. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9199. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9200. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9201. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9202. result = TRUE;
  9203. return result;
  9204. }
  9205. end:
  9206. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9207. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9208. return result;
  9209. }
  9210. int handleResetRequest(char *uuid, char *payload)
  9211. {
  9212. mtrace();
  9213. int result = FAIL;
  9214. char sstr[10]={0},sstrtemp[30]={ 0 };
  9215. char typestr[10]={0};
  9216. char comfirmstr[20]={0};
  9217. int c = 0;
  9218. char *loc;
  9219. DEBUG_INFO("handleResetRequest...\n");
  9220. strcpy(sstrtemp, stringtrimspace(payload));
  9221. loc = strstr(sstrtemp, "type");
  9222. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9223. c = 0;
  9224. while (loc[3+strlen("type")+c] != '\"')
  9225. {
  9226. sstr[c] = loc[3+strlen("type")+c];
  9227. c++;
  9228. }
  9229. sstr[c] = '\0';
  9230. strcpy(typestr,sstr);
  9231. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9232. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9233. {
  9234. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9235. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9236. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9237. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9238. }
  9239. else
  9240. {
  9241. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9242. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9243. result = PASS;
  9244. }
  9245. sendResetConfirmation(uuid, comfirmstr);
  9246. return result;
  9247. }
  9248. int handleSendLocalListRequest(char *uuid, char *payload)
  9249. {
  9250. mtrace();
  9251. int result = FAIL;
  9252. char comfirmstr[20];
  9253. int checkState_Faulted = FALSE;
  9254. json_object *SendLocalList;
  9255. DEBUG_INFO("handleSendLocalListRequest...\n");
  9256. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9257. {
  9258. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9259. goto end;
  9260. }
  9261. //check Charge Point state
  9262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9263. {
  9264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9265. {
  9266. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9267. }
  9268. }
  9269. for (int index = 0; index < CCS_QUANTITY; index++)
  9270. {
  9271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9272. {
  9273. checkState_Faulted = TRUE; //OCPP Status
  9274. }
  9275. }
  9276. for (int index = 0; index < GB_QUANTITY; index++)
  9277. {
  9278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9279. {
  9280. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9281. }
  9282. }
  9283. //check Charge Point state
  9284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9285. {
  9286. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9287. {
  9288. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9289. }
  9290. }
  9291. //check Charge Point state
  9292. for (int index = 0; index < AC_QUANTITY; index++)
  9293. {
  9294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9295. {
  9296. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9297. }
  9298. }
  9299. if(checkState_Faulted == TRUE)
  9300. {
  9301. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9302. goto end;
  9303. }
  9304. // Parsing payload
  9305. SendLocalList = json_tokener_parse(payload);
  9306. if(!is_error(SendLocalList))
  9307. {
  9308. // Required data
  9309. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9310. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9311. // Optional data
  9312. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9313. {
  9314. //Check UpdateType
  9315. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9316. {
  9317. //Local list full update
  9318. DEBUG_INFO("Local list full update.\n");
  9319. OCPP_getListVerion();
  9320. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9321. {
  9322. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9323. goto end;
  9324. }
  9325. OCPP_cleanLocalList();
  9326. }
  9327. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9328. {
  9329. //Local list different update
  9330. DEBUG_INFO("Local list different update.\n");
  9331. OCPP_getListVerion();
  9332. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9333. {
  9334. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9335. goto end;
  9336. }
  9337. }
  9338. else
  9339. {
  9340. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9341. goto end;
  9342. }
  9343. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9344. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9345. {
  9346. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9347. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9348. {
  9349. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9350. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9351. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9352. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9353. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9354. }
  9355. // Add to db
  9356. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9357. {
  9358. //Local list full update
  9359. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9360. idx,
  9361. ShmOCPP16Data->SendLocalList.ListVersion,
  9362. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9363. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9364. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9365. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9366. // update list
  9367. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9368. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9369. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9370. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9371. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9372. }
  9373. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9374. {
  9375. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9376. idx,
  9377. ShmOCPP16Data->SendLocalList.ListVersion,
  9378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9380. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9381. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9382. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9383. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9384. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9385. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9386. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9387. }
  9388. }
  9389. }
  9390. else
  9391. {
  9392. //Check UpdateType
  9393. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9394. {
  9395. //Local list full update
  9396. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9397. OCPP_cleanLocalList();
  9398. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9399. goto end;
  9400. }
  9401. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9402. {
  9403. //Local list different update
  9404. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9405. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9406. goto end;
  9407. }
  9408. }
  9409. result = PASS;
  9410. }
  9411. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9412. end:
  9413. json_object_put(SendLocalList);
  9414. sendSendLocalListConfirmation(uuid, comfirmstr);
  9415. return result;
  9416. }
  9417. #define MAX 200
  9418. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9419. {
  9420. mtrace();
  9421. int result = FAIL;
  9422. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9423. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9424. char chargingProfilePurposeStr[30]={0};
  9425. char chargingProfileKindStr[16]={0};
  9426. char recurrencyKindStr[10]={0};
  9427. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9428. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9429. int chargingSchedulePeriodCount = 0;
  9430. char comfirmstr[20]={0};
  9431. int meet= FALSE;
  9432. FILE *fptr1;
  9433. char filename[MAX]={0};
  9434. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9435. char rmFileCmd[50]={0};
  9436. char tempchargingProfilePurposeStr[30]={0};
  9437. char word[1600]={0};
  9438. int n_chargingProfile = 0;
  9439. json_object *SetChargingProfile;
  9440. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9441. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9442. SetChargingProfile = json_tokener_parse(payload);
  9443. if(!is_error(SetChargingProfile))
  9444. {
  9445. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9446. {
  9447. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9448. if(connectorIdInt == 0)
  9449. {
  9450. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9451. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9452. }
  9453. else
  9454. {
  9455. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9456. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9457. }
  9458. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9459. }
  9460. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9461. {
  9462. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9463. {
  9464. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9466. {
  9467. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9468. }
  9469. else
  9470. {
  9471. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9472. }
  9473. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9474. }
  9475. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9476. {
  9477. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9478. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9479. {
  9480. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9481. }
  9482. else
  9483. {
  9484. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9485. }
  9486. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9487. }
  9488. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9489. {
  9490. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9491. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9492. {
  9493. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9494. }
  9495. else
  9496. {
  9497. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9498. }
  9499. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9500. }
  9501. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9502. {
  9503. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9504. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9505. {
  9506. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9507. }
  9508. else
  9509. {
  9510. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9511. }
  9512. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9513. }
  9514. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9515. {
  9516. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9518. {
  9519. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9520. }
  9521. else
  9522. {
  9523. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9524. }
  9525. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9526. }
  9527. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9528. {
  9529. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9530. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9531. {
  9532. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9533. }
  9534. else
  9535. {
  9536. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9537. }
  9538. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9539. }
  9540. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9541. {
  9542. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9543. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9544. {
  9545. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9546. }
  9547. else
  9548. {
  9549. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9550. }
  9551. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9552. }
  9553. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9554. {
  9555. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9556. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9557. {
  9558. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9559. }
  9560. else
  9561. {
  9562. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9563. }
  9564. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9565. }
  9566. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9567. {
  9568. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9569. {
  9570. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9571. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9572. {
  9573. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9574. }
  9575. else
  9576. {
  9577. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9578. }
  9579. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9580. }
  9581. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9582. {
  9583. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9585. {
  9586. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9587. }
  9588. else
  9589. {
  9590. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9591. }
  9592. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9593. }
  9594. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9595. {
  9596. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9597. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9598. {
  9599. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9600. }
  9601. else
  9602. {
  9603. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9604. }
  9605. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9606. }
  9607. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9608. {
  9609. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9610. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9613. }
  9614. else
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9617. }
  9618. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9619. }
  9620. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9621. {
  9622. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9623. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9624. if(chargingSchedulePeriodCount <= 10)
  9625. {
  9626. 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++)
  9627. {
  9628. 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)
  9629. {
  9630. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9631. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9632. {
  9633. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9634. }
  9635. else
  9636. {
  9637. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9638. }
  9639. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9640. }
  9641. 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)
  9642. {
  9643. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9644. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9645. {
  9646. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9647. }
  9648. else
  9649. {
  9650. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9651. }
  9652. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9653. }
  9654. 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)
  9655. {
  9656. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9657. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9658. {
  9659. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9660. }
  9661. else
  9662. {
  9663. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9664. }
  9665. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9666. }
  9667. }
  9668. }
  9669. }
  9670. }
  9671. }
  9672. }
  9673. json_object_put(SetChargingProfile);
  9674. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9675. {
  9676. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9677. goto end;
  9678. }
  9679. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9680. {
  9681. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9682. if(connectorIdInt != 0)
  9683. {
  9684. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9685. goto end;
  9686. }
  9687. strcpy(filename, ChargePointMaxProfile_JSON );
  9688. fptr1 = fopen(filename, "r");
  9689. if (!fptr1)
  9690. {
  9691. //file not exist
  9692. DEBUG_INFO("Unable to open the input file!!\n");
  9693. fptr1 = fopen(filename, "w+");
  9694. }
  9695. else
  9696. {
  9697. //Check Charging Profile Count
  9698. while(fscanf(fptr1, "%s", word) != EOF)
  9699. {
  9700. //DEBUG_INFO("word=%s\n",word);
  9701. if(strstr(word, "chargingProfileId")!= NULL)
  9702. {
  9703. //DEBUG_INFO("test chargingProfileId \n");
  9704. n_chargingProfile = n_chargingProfile + 1;
  9705. //DEBUG_INFO("chargingProfileId Found\n");
  9706. }
  9707. }
  9708. }
  9709. fclose(fptr1);
  9710. }
  9711. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9712. {
  9713. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9714. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9715. {
  9716. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9717. goto end;
  9718. }
  9719. memset(filename, 0, ARRAY_SIZE(filename));
  9720. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9721. fptr1 = fopen(filename, "r");
  9722. if (!fptr1)
  9723. {
  9724. //file not exist
  9725. //DEBUG_INFO("Unable to open the input file!!\n");
  9726. fptr1 = fopen(filename, "w+");
  9727. }
  9728. else
  9729. {
  9730. //Check Charging Profile Count
  9731. while(fscanf(fptr1, "%s", word) != EOF)
  9732. {
  9733. //DEBUG_INFO("word=%s\n",word);
  9734. if(strstr(word, "chargingProfileId")!= NULL)
  9735. {
  9736. //DEBUG_INFO("test chargingProfileId \n");
  9737. n_chargingProfile = n_chargingProfile + 1;
  9738. //DEBUG_INFO("chargingProfileId Found\n");
  9739. }
  9740. }
  9741. }
  9742. fclose(fptr1);
  9743. }
  9744. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9745. {
  9746. //printf("set chargingProfile 1-4\n");
  9747. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9748. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9749. if(connectorIdInt == 0)
  9750. {
  9751. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9752. goto end;
  9753. }
  9754. int tempIndex = 0;
  9755. //check Transaction active
  9756. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9757. {
  9758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9759. {
  9760. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9761. }
  9762. else
  9763. {
  9764. tempIndex = connectorIdInt -1;
  9765. }
  9766. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9767. {
  9768. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9769. {
  9770. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9771. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9772. {
  9773. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9774. {
  9775. meet = TRUE;
  9776. break;
  9777. }
  9778. }
  9779. }
  9780. }
  9781. }
  9782. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9783. {
  9784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9785. {
  9786. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9787. }
  9788. else
  9789. {
  9790. tempIndex = connectorIdInt -1;
  9791. }
  9792. for (int index = 0; index < CCS_QUANTITY; index++)
  9793. {
  9794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9795. {
  9796. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9798. {
  9799. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9800. {
  9801. meet = TRUE;
  9802. break;
  9803. }
  9804. }
  9805. }
  9806. }
  9807. }
  9808. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9809. {
  9810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9811. {
  9812. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9813. }
  9814. else
  9815. {
  9816. tempIndex = connectorIdInt -1;
  9817. }
  9818. for (int index = 0; index < GB_QUANTITY; index++)
  9819. {
  9820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9821. {
  9822. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9823. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9824. {
  9825. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9826. {
  9827. meet = TRUE;
  9828. break;
  9829. }
  9830. }
  9831. }
  9832. }
  9833. }
  9834. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9835. {
  9836. tempIndex = connectorIdInt -1;
  9837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9838. {
  9839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9840. {
  9841. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9842. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9843. {
  9844. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9845. {
  9846. meet = TRUE;
  9847. break;
  9848. }
  9849. }
  9850. }
  9851. }
  9852. }
  9853. else
  9854. {
  9855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9856. {
  9857. tempIndex = 2;
  9858. }
  9859. else
  9860. {
  9861. tempIndex = (connectorIdInt -1);
  9862. }
  9863. for (int index = 0; index < AC_QUANTITY; index++)
  9864. {
  9865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9866. {
  9867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9868. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9869. {
  9870. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9871. {
  9872. meet = TRUE;
  9873. break;
  9874. }
  9875. }
  9876. }
  9877. }
  9878. }
  9879. //check Transaction active
  9880. if(meet == FALSE)
  9881. {
  9882. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9883. goto end;
  9884. }
  9885. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9886. {
  9887. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9888. goto end;
  9889. }
  9890. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9891. fptr1 = fopen(filename, "r");
  9892. if (!fptr1)
  9893. {
  9894. //file not exist
  9895. DEBUG_INFO("Unable to open the input file!!\n");
  9896. fptr1 = fopen(filename, "w+");
  9897. }
  9898. else
  9899. {
  9900. //Check Charging Profile Count
  9901. while(fscanf(fptr1, "%s", word) != EOF)
  9902. {
  9903. //DEBUG_INFO("word=%s\n",word);
  9904. if(strstr(word, "chargingProfileId")!= NULL)
  9905. {
  9906. //DEBUG_INFO("test chargingProfileId \n");
  9907. n_chargingProfile = n_chargingProfile + 1;
  9908. //DEBUG_INFO("chargingProfileId Found\n");
  9909. }
  9910. }
  9911. }
  9912. fclose(fptr1);
  9913. }
  9914. // Check ChargeProfileMaxStackLevel
  9915. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9916. {
  9917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9918. goto end;
  9919. }
  9920. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9921. {
  9922. int i = 0;
  9923. char fnametemp[200]={0};
  9924. n_chargingProfile = 0;
  9925. //Check ChargePointMaxProfile.json exit
  9926. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9927. {
  9928. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9929. //Check Charging Profile Count
  9930. while(fscanf(fptr1, "%s", word) != EOF)
  9931. {
  9932. //DEBUG_INFO("word=%s\n",word);
  9933. if(strstr(word, "chargingProfileId")!= NULL)
  9934. {
  9935. //DEBUG_INFO("test chargingProfileId \n");
  9936. n_chargingProfile = n_chargingProfile + 1;
  9937. i = i + 1;
  9938. //DEBUG_INFO("chargingProfileId Found\n");
  9939. }
  9940. memset(word, 0, ARRAY_SIZE(word));
  9941. }
  9942. fclose(fptr1);
  9943. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9944. }
  9945. //Check TxDefaultProfile_0.json exit
  9946. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9947. {
  9948. i = 0;
  9949. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9950. //Check Charging Profile Count
  9951. while(fscanf(fptr1, "%s", word) != EOF)
  9952. {
  9953. //DEBUG_INFO("word=%s\n",word);
  9954. if(strstr(word, "chargingProfileId")!= NULL)
  9955. {
  9956. //DEBUG_INFO("test chargingProfileId \n");
  9957. n_chargingProfile = n_chargingProfile + 1;
  9958. i = i + 1;
  9959. //DEBUG_INFO("chargingProfileId Found\n");
  9960. }
  9961. memset(word, 0, ARRAY_SIZE(word));
  9962. }
  9963. fclose(fptr1);
  9964. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9965. }
  9966. //Check TxDefaultProfile_%d.json
  9967. for(int j=1; j <= gunTotalNumber; j++)
  9968. {
  9969. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9970. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9971. if((access(fnametemp,F_OK))!=-1)
  9972. {
  9973. i = 0;
  9974. fptr1 = fopen(fnametemp, "r");
  9975. //Check Charging Profile Count
  9976. while(fscanf(fptr1, "%s", word) != EOF)
  9977. {
  9978. //DEBUG_INFO("word=%s\n",word);
  9979. if(strstr(word, "chargingProfileId")!= NULL)
  9980. {
  9981. //DEBUG_INFO("test chargingProfileId \n");
  9982. n_chargingProfile = n_chargingProfile + 1;
  9983. i = i + 1;
  9984. //DEBUG_INFO("chargingProfileId Found\n");
  9985. }
  9986. memset(word, 0, ARRAY_SIZE(word));
  9987. }
  9988. fclose(fptr1);
  9989. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9990. }
  9991. }
  9992. //Check TxProfile_%d.json
  9993. for(int j=1; j <= gunTotalNumber; j++)
  9994. {
  9995. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9996. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9997. if((access(fnametemp,F_OK))!=-1)
  9998. {
  9999. i = 0;
  10000. fptr1 = fopen(fnametemp, "r");
  10001. //Check Charging Profile Count
  10002. while(fscanf(fptr1, "%s", word) != EOF)
  10003. {
  10004. //DEBUG_INFO("word=%s\n",word);
  10005. if(strstr(word, "chargingProfileId")!= NULL)
  10006. {
  10007. //DEBUG_INFO("test chargingProfileId \n");
  10008. n_chargingProfile = n_chargingProfile + 1;
  10009. i = i + 1;
  10010. //DEBUG_INFO("chargingProfileId Found\n");
  10011. }
  10012. memset(word, 0, ARRAY_SIZE(word));
  10013. }
  10014. fclose(fptr1);
  10015. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10016. }
  10017. }
  10018. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10019. {
  10020. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10021. goto end;
  10022. }
  10023. }
  10024. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10025. //**********************************Write to File********************************************************/
  10026. FILE *infile;
  10027. FILE *outfile;
  10028. infile = fopen (filename, "r");
  10029. outfile = fopen (tempfile, "w");
  10030. int d =0;
  10031. d = fgetc(infile);
  10032. rewind(infile);
  10033. if(d == EOF)
  10034. {
  10035. // Profile is empty
  10036. fprintf(outfile,"%s\n",payload);
  10037. fclose(infile);
  10038. fclose(outfile);
  10039. sprintf(rmFileCmd,"rm -f %s",filename);
  10040. system(rmFileCmd);
  10041. rename(tempfile, filename);
  10042. }
  10043. else
  10044. {
  10045. // Profile is not empty
  10046. char buf[2048]={0};
  10047. int ChargingProfileAdded = FALSE;
  10048. while (fgets(buf, sizeof(buf), infile) != NULL)
  10049. {
  10050. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10051. json_object *tmpChargingProfile;
  10052. tmpChargingProfile = json_tokener_parse(buf);
  10053. if(!is_error(SetChargingProfile))
  10054. {
  10055. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10056. {
  10057. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10058. }
  10059. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10060. {
  10061. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10062. {
  10063. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10064. }
  10065. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10066. {
  10067. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10068. }
  10069. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10070. {
  10071. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10072. }
  10073. }
  10074. }
  10075. json_object_put(tmpChargingProfile);
  10076. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10077. {
  10078. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10079. {
  10080. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10081. if(ChargingProfileAdded == FALSE)
  10082. {
  10083. fprintf(outfile,"%s\n",payload);
  10084. ChargingProfileAdded = TRUE;
  10085. }
  10086. }
  10087. else
  10088. {
  10089. if(tempstackLevelInt < stackLevelInt)
  10090. {
  10091. if(ChargingProfileAdded == FALSE)
  10092. {
  10093. fprintf(outfile,"%s\n",buf);
  10094. fprintf(outfile,"%s\n",payload);
  10095. ChargingProfileAdded = TRUE;
  10096. }
  10097. else
  10098. {
  10099. fprintf(outfile,"%s\n",buf);
  10100. }
  10101. }
  10102. else
  10103. {
  10104. if(ChargingProfileAdded == FALSE)
  10105. {
  10106. fprintf(outfile,"%s\n",buf);
  10107. fprintf(outfile,"%s\n",payload);
  10108. ChargingProfileAdded = TRUE;
  10109. }
  10110. else
  10111. {
  10112. fprintf(outfile,"%s\n",buf);
  10113. }
  10114. }
  10115. }
  10116. }
  10117. else
  10118. {
  10119. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10120. {
  10121. if(ChargingProfileAdded == FALSE)
  10122. {
  10123. fprintf(outfile,"%s\n",buf);
  10124. fprintf(outfile,"%s\n",payload);
  10125. ChargingProfileAdded = TRUE;
  10126. }
  10127. else
  10128. {
  10129. fprintf(outfile,"%s\n",buf);
  10130. }
  10131. }
  10132. else if(tempstackLevelInt < stackLevelInt)
  10133. {
  10134. if(ChargingProfileAdded == FALSE)
  10135. {
  10136. fprintf(outfile,"%s\n",buf);
  10137. fprintf(outfile,"%s\n",payload);
  10138. ChargingProfileAdded = TRUE;
  10139. }
  10140. else
  10141. {
  10142. fprintf(outfile,"%s\n",buf);
  10143. }
  10144. }
  10145. else
  10146. {
  10147. if(ChargingProfileAdded == FALSE)
  10148. {
  10149. fprintf(outfile,"%s\n",buf);
  10150. fprintf(outfile,"%s\n",payload);
  10151. ChargingProfileAdded = TRUE;
  10152. }
  10153. else
  10154. {
  10155. fprintf(outfile,"%s\n",buf);
  10156. }
  10157. }
  10158. }
  10159. } // end of while loop
  10160. fclose(infile);
  10161. fclose(outfile);
  10162. sprintf(rmFileCmd,"rm -f %s",filename);
  10163. system(rmFileCmd);
  10164. rename(tempfile, filename);
  10165. }
  10166. sleep(1);
  10167. result = TRUE;
  10168. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10169. end:
  10170. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10171. {
  10172. if(connectorIdInt == 0)
  10173. {
  10174. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10175. {
  10176. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10177. }
  10178. }
  10179. else
  10180. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10181. }
  10182. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10183. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10184. return result;
  10185. }
  10186. int handleTriggerMessageRequest(char *uuid, char *payload)
  10187. {
  10188. mtrace();
  10189. int result = FAIL;
  10190. int connectorIdIsNULL = FALSE;
  10191. int connectorIdInt =0;
  10192. char sstr[40]={0},sstrtemp[100]={ 0 };
  10193. char requestedMessagestr[40]={0};
  10194. char comfirmstr[20]={0};
  10195. int c = 0;
  10196. char *loc;
  10197. DEBUG_INFO("handleTriggerMessageRequest\n");
  10198. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10199. strcpy(sstrtemp, stringtrimspace(payload));
  10200. c = 0;
  10201. loc = strstr(sstrtemp, "requestedMessage");
  10202. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10203. {
  10204. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10205. c++;
  10206. }
  10207. sstr[c] = '\0';
  10208. strcpy(requestedMessagestr, sstr);
  10209. c = 0;
  10210. loc = strstr(sstrtemp, "connectorId");
  10211. if(loc == NULL)
  10212. {
  10213. connectorIdIsNULL = TRUE;
  10214. }
  10215. else
  10216. {
  10217. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10218. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10219. {
  10220. sstr[c] = loc[strlen("connectorId")+2+c];
  10221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10222. c++;
  10223. }
  10224. sstr[c] = '\0';
  10225. connectorIdInt = atoi(sstr);
  10226. }
  10227. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10228. {
  10229. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10230. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10231. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10232. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10233. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10234. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10235. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10236. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10237. {
  10238. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10239. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10240. return TRUE;
  10241. }
  10242. else
  10243. {
  10244. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10245. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10246. }
  10247. }
  10248. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10249. {
  10250. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10251. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10252. return TRUE;
  10253. }
  10254. //==========================
  10255. // Trigger message
  10256. //==========================
  10257. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10258. {
  10259. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10260. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10261. {
  10262. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10263. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10264. }
  10265. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10266. }
  10267. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10268. {
  10269. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10270. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10271. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10272. }
  10273. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10274. {
  10275. //sendBootNotificationRequest();
  10276. server_sign = FALSE;
  10277. }
  10278. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10279. {
  10280. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10281. }
  10282. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10283. {
  10284. if(connectorIdIsNULL == FALSE)
  10285. {
  10286. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10287. {
  10288. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10289. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10290. }
  10291. }
  10292. else
  10293. {
  10294. for(int idx=0;idx< gunTotalNumber;idx++)
  10295. {
  10296. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10297. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10298. }
  10299. }
  10300. }
  10301. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10302. {
  10303. if(connectorIdIsNULL == FALSE)
  10304. {
  10305. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10306. {
  10307. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10308. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10309. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10310. }
  10311. }
  10312. else
  10313. {
  10314. for(int idx=0;idx< gunTotalNumber;idx++)
  10315. {
  10316. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10317. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10318. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10319. }
  10320. }
  10321. }
  10322. return result;
  10323. }
  10324. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10325. {
  10326. mtrace();
  10327. int result = FAIL;
  10328. int connectorIdInt =0;
  10329. char comfirmstr[20]={0};
  10330. int tempIndex = 0;
  10331. json_object *UnlockConnector;
  10332. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10333. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10334. UnlockConnector = json_tokener_parse(payload);
  10335. if(!is_error(UnlockConnector))
  10336. {
  10337. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10338. {
  10339. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10340. }
  10341. }
  10342. json_object_put(UnlockConnector);
  10343. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10344. if(gunTotalNumber == 0)
  10345. {
  10346. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10347. goto end;
  10348. }
  10349. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10350. {
  10351. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10352. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10353. goto end;
  10354. }
  10355. else
  10356. {
  10357. //check Transaction active
  10358. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10359. {
  10360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10361. {
  10362. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10363. }
  10364. else
  10365. {
  10366. tempIndex = connectorIdInt -1;
  10367. }
  10368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10369. {
  10370. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10371. {
  10372. //stop Transaction
  10373. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10374. }
  10375. }
  10376. }
  10377. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10378. {
  10379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10380. {
  10381. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10382. }
  10383. else
  10384. {
  10385. tempIndex = connectorIdInt -1;
  10386. }
  10387. for (int index = 0; index < CCS_QUANTITY; index++)
  10388. {
  10389. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10390. {
  10391. //stop Transaction
  10392. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10393. }
  10394. }
  10395. }
  10396. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10397. {
  10398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10399. {
  10400. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10401. }
  10402. else
  10403. {
  10404. tempIndex = connectorIdInt -1;
  10405. }
  10406. for (int index = 0; index < GB_QUANTITY; index++)
  10407. {
  10408. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10409. {
  10410. //stop Transaction
  10411. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10412. }
  10413. }
  10414. }
  10415. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10416. {
  10417. tempIndex = connectorIdInt -1;
  10418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10419. {
  10420. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  10421. {
  10422. //stop Transaction
  10423. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10424. }
  10425. }
  10426. }
  10427. else
  10428. {
  10429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10430. {
  10431. tempIndex = 2;
  10432. }
  10433. else
  10434. {
  10435. tempIndex = connectorIdInt-1;
  10436. }
  10437. for (int index = 0; index < AC_QUANTITY; index++)
  10438. {
  10439. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10440. {
  10441. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10442. }
  10443. }
  10444. }
  10445. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10446. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10447. result = TRUE;
  10448. return result;
  10449. }
  10450. end:
  10451. //json_object_put(obj); --- remove temporally
  10452. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10453. return result;
  10454. }
  10455. static char UpdateFirmwarepayloadData[300]={0};
  10456. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10457. {
  10458. mtrace();
  10459. int result = FAIL;
  10460. pthread_t t;
  10461. sendUpdateFirmwareConfirmation(uuid);
  10462. memset(UpdateFirmwarepayloadData, 0, 300);
  10463. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10464. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10465. ////pthread_join(t, NULL); //
  10466. //pthread_detach(t);
  10467. //sendUpdateFirmwareConfirmation(uuid);
  10468. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10469. return result;
  10470. }
  10471. void *UpdateFirmwareProcess(void *data)
  10472. {
  10473. pthread_detach(pthread_self());
  10474. mtrace();
  10475. int retriesInt =0, retryIntervalInt=0;
  10476. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10477. int port=0;
  10478. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10479. int isSuccess = 0;
  10480. char ftpbuf[1024];
  10481. char temp[1024];
  10482. char * pch;
  10483. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10484. json_object *UpdateFirmware;
  10485. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10486. if(!is_error(UpdateFirmware))
  10487. {
  10488. // Required data
  10489. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10490. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10491. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10492. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10493. // Optional data
  10494. if(json_object_object_get(UpdateFirmware, "retries"))
  10495. {
  10496. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10497. }
  10498. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10499. {
  10500. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10501. }
  10502. }
  10503. json_object_put(UpdateFirmware);
  10504. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10505. memset(path, 0, ARRAY_SIZE(path));
  10506. // Wait retrieveData
  10507. if(strlen(retrieveDatestr) > 10)
  10508. {
  10509. do
  10510. {
  10511. sleep(1);
  10512. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10513. }
  10514. // Ready to download
  10515. system("rm -f /mnt/*");
  10516. if(strncmp(locationstr,"http", 4) == 0)
  10517. {
  10518. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10519. sprintf(ftppath,"/%s", path);
  10520. DEBUG_INFO("locationstr: %s\n", locationstr);
  10521. DEBUG_INFO("protocol: %s\n",protocol);
  10522. DEBUG_INFO("host: %s\n",host);
  10523. DEBUG_INFO("path: %s\n",path);
  10524. DEBUG_INFO("ftppath: %s\n",ftppath);
  10525. int ftppathlen=strlen(ftppath);
  10526. int i=1;
  10527. char filenametemp[50];
  10528. while(i < ftppathlen)
  10529. {
  10530. int len=ftppathlen-i;
  10531. if(ftppath[len]== 47) // '/' ascll code: 47
  10532. {
  10533. DEBUG_INFO("compare '/' all right\n");
  10534. break;
  10535. }
  10536. i=i+1;
  10537. }
  10538. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10539. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10540. filenametemp[i+1] = 0;
  10541. do
  10542. {
  10543. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10544. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10545. sleep(1);
  10546. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10547. if(!isSuccess)
  10548. {
  10549. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10550. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10551. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10552. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10553. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10554. }
  10555. else
  10556. {
  10557. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10558. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10559. }
  10560. retriesInt--;
  10561. }while((isSuccess == 0)&&(retriesInt >= 0));
  10562. }
  10563. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10564. {
  10565. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10566. memset(temp, 0, ARRAY_SIZE(temp));
  10567. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10568. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10569. int ftppathlen=strlen(ftpbuf);
  10570. int i=1;
  10571. char filenametemp[50];
  10572. while(i < ftppathlen)
  10573. {
  10574. int len=ftppathlen-i;
  10575. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10576. {
  10577. DEBUG_INFO(" compare '/' all right\n");
  10578. break;
  10579. }
  10580. i=i+1;
  10581. }
  10582. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10583. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10584. filenametemp[i+1] = 0;
  10585. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10586. pch=strchr(temp,'@');
  10587. if(pch==NULL)
  10588. {
  10589. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10590. protocol, host, &port, path);
  10591. strcpy(user,"anonymous");
  10592. strcpy(password,"");
  10593. }
  10594. else
  10595. {
  10596. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10597. protocol, user, password, host, &port, path);
  10598. }
  10599. sscanf(host,"%[^/]%s",host1, path1);
  10600. sprintf(ftppath,"%s", path1);
  10601. //DEBUG_INFO("protocol =%s\n",protocol);
  10602. //DEBUG_INFO("user =%s\n",user);
  10603. //DEBUG_INFO("password =%s\n",password);
  10604. //DEBUG_INFO("host1 =%s\n",host1);
  10605. //DEBUG_INFO("port =%d\n",port);
  10606. //DEBUG_INFO("path1 =%s\n",path1);
  10607. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10608. //ftpFile(host, user, password, port, ftppath, fname);
  10609. //download firmware pthred
  10610. if(port == 0)
  10611. {
  10612. port = 21;
  10613. }
  10614. do
  10615. {
  10616. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10617. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10618. sleep(1);
  10619. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10620. if(!isSuccess)
  10621. {
  10622. //BulldogUtil.sleepMs(interval*1000);
  10623. DEBUG_INFO("Update firmware request and download file fail.\n");
  10624. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10625. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10626. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10627. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10628. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10629. }
  10630. else
  10631. {
  10632. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10633. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10634. }
  10635. retriesInt--;
  10636. }while((!isSuccess)&&(retriesInt >= 0));
  10637. }
  10638. else
  10639. {
  10640. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10641. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10642. sleep(1);
  10643. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10644. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10645. }
  10646. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10647. pthread_exit(NULL);
  10648. }
  10649. int handleCertificateSignedRequest(char *uuid, char *payload)
  10650. {
  10651. mtrace();
  10652. int result = PASS;
  10653. json_object *CertificateSigned;
  10654. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10655. CertificateSigned = json_tokener_parse(payload);
  10656. if(!is_error(CertificateSigned))
  10657. {
  10658. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10659. }
  10660. json_object_put(CertificateSigned);
  10661. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10662. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10663. fclose(fp);
  10664. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10665. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10666. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10667. sendCertificateSignedConfirmation(uuid);
  10668. return result;
  10669. }
  10670. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10671. {
  10672. mtrace();
  10673. int result = PASS;
  10674. json_object *DeleteCertificate;
  10675. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10676. DeleteCertificate = json_tokener_parse(payload);
  10677. if(!is_error(DeleteCertificate))
  10678. {
  10679. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10680. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10681. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10682. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10683. }
  10684. json_object_put(DeleteCertificate);
  10685. /*
  10686. * TODO: Delete certificateSigned process
  10687. */
  10688. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10689. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10690. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10691. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10692. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10693. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10694. sendDeleteCertificateConfirmation(uuid);
  10695. return result;
  10696. }
  10697. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10698. {
  10699. mtrace();
  10700. int result = PASS;
  10701. json_object *ExtendedTriggerMessage;
  10702. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10703. ExtendedTriggerMessage = json_tokener_parse(payload);
  10704. if(!is_error(ExtendedTriggerMessage))
  10705. {
  10706. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10707. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10708. {
  10709. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10710. }
  10711. else
  10712. {
  10713. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10714. }
  10715. }
  10716. json_object_put(ExtendedTriggerMessage);
  10717. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10718. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10719. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10720. {
  10721. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10722. }
  10723. else
  10724. {
  10725. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10726. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10727. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10728. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10729. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10730. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10731. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10732. {
  10733. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10734. }
  10735. else
  10736. {
  10737. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10738. }
  10739. }
  10740. sendExtendedTriggerMessageConfirmation(uuid);
  10741. //==========================
  10742. // Trigger message
  10743. //==========================
  10744. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10745. {
  10746. //sendBootNotificationRequest();
  10747. server_sign = FALSE;
  10748. }
  10749. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10750. {
  10751. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10752. }
  10753. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10754. {
  10755. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10756. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10757. {
  10758. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10759. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10760. }
  10761. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10762. }
  10763. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10764. {
  10765. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10766. }
  10767. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10768. {
  10769. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10770. {
  10771. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10772. }
  10773. else
  10774. {
  10775. for(int idx=0;idx< gunTotalNumber;idx++)
  10776. {
  10777. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10778. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10779. }
  10780. }
  10781. }
  10782. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10783. {
  10784. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10785. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10786. {
  10787. 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\" &");
  10788. }
  10789. }
  10790. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10791. {
  10792. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10793. {
  10794. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10795. }
  10796. else
  10797. {
  10798. for(int idx=0;idx< gunTotalNumber;idx++)
  10799. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10800. }
  10801. }
  10802. return result;
  10803. }
  10804. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10805. {
  10806. mtrace();
  10807. int result = PASS;
  10808. json_object *GetInstalledCertificateIds;
  10809. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10810. GetInstalledCertificateIds = json_tokener_parse(payload);
  10811. if(!is_error(GetInstalledCertificateIds))
  10812. {
  10813. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10814. }
  10815. json_object_put(GetInstalledCertificateIds);
  10816. /*
  10817. * TODO: Return installed certificate process
  10818. */
  10819. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10820. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10821. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10822. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10823. sendGetInstalledCertificateIdsConfirmation(uuid);
  10824. return result;
  10825. }
  10826. int handleGetLogRequest(char *uuid, char *payload)
  10827. {
  10828. mtrace();
  10829. int result = PASS;
  10830. json_object *GetLog;
  10831. DEBUG_INFO("handleGetLogRequest...\n");
  10832. GetLog = json_tokener_parse(payload);
  10833. if(!is_error(GetLog))
  10834. {
  10835. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10836. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10837. if(json_object_object_get(GetLog, "retries") != NULL)
  10838. {
  10839. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10840. }
  10841. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10842. {
  10843. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10844. }
  10845. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10846. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10847. {
  10848. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10849. }
  10850. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10851. {
  10852. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10853. }
  10854. }
  10855. json_object_put(GetLog);
  10856. /*
  10857. * TODO: Upload log process
  10858. */
  10859. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10860. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10861. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10862. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10863. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10864. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10865. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10866. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10867. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10868. sendGetLogConfirmation(uuid);
  10869. return result;
  10870. }
  10871. int handleInstallCertificateRequest(char *uuid, char *payload)
  10872. {
  10873. mtrace();
  10874. int result = PASS;
  10875. json_object *InstallCertificate;
  10876. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10877. InstallCertificate = json_tokener_parse(payload);
  10878. if(!is_error(InstallCertificate))
  10879. {
  10880. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10881. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10882. /*
  10883. * TODO: Install certificate process
  10884. */
  10885. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10886. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10887. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10888. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10889. sendInstallCertificateConfirmation(uuid);
  10890. }
  10891. json_object_put(InstallCertificate);
  10892. return result;
  10893. }
  10894. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10895. {
  10896. mtrace();
  10897. int result = PASS;
  10898. json_object *SignedUpdateFirmware;
  10899. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10900. SignedUpdateFirmware = json_tokener_parse(payload);
  10901. if(!is_error(SignedUpdateFirmware))
  10902. {
  10903. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10904. {
  10905. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10906. }
  10907. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10908. {
  10909. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10910. }
  10911. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10912. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10913. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10914. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10915. {
  10916. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10917. }
  10918. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10919. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10920. }
  10921. json_object_put(SignedUpdateFirmware);
  10922. /*
  10923. * TODO: Upgrade firmware process
  10924. */
  10925. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10926. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10927. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10928. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10929. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10930. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10931. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10932. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10933. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10934. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10935. sendInstallCertificateConfirmation(uuid);
  10936. return result;
  10937. }
  10938. int handleUnknownRequest(char *uuid, char *payload)
  10939. {
  10940. mtrace();
  10941. int result = PASS;
  10942. DEBUG_INFO("handleUnknownRequest...\n");
  10943. sendUnknownConfirmation(uuid);
  10944. result = PASS;
  10945. return result;
  10946. }
  10947. //==========================================
  10948. // Handle server response routine
  10949. //==========================================
  10950. void handleAuthorizeResponse(char *payload, int gun_index)
  10951. {
  10952. mtrace();
  10953. char expiryDatestr[30]={0};
  10954. char parentIdTagstr[20]={0};
  10955. char statusstr[20]={0};
  10956. int expiryDateISNULL=FALSE;
  10957. int parentIdTagISNULL=FALSE;
  10958. DEBUG_INFO("handleAuthorizeResponse...\n");
  10959. json_object *Authorize;
  10960. Authorize = json_tokener_parse(payload);
  10961. if(!is_error(Authorize))
  10962. {
  10963. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10964. {
  10965. // Required data
  10966. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10967. // Optional data
  10968. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10969. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10970. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10971. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10972. }
  10973. }
  10974. json_object_put(Authorize);
  10975. if(expiryDateISNULL == FALSE)
  10976. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10977. if(parentIdTagISNULL == FALSE)
  10978. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10979. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10980. //Update idTag information to authorization cache if supproted
  10981. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10982. {
  10983. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10984. }
  10985. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10986. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10987. authorizeRetryTimes = 0;
  10988. }
  10989. void handleBootNotificationResponse(char *payload, int gun_index)
  10990. {
  10991. mtrace();
  10992. char statusStr[12]={0};
  10993. char currentTimeStr[30]={0};
  10994. int intervalInt = 0;
  10995. DEBUG_INFO("handleBootNotificationResponse...\n");
  10996. json_object *BootNotification;
  10997. BootNotification = json_tokener_parse(payload);
  10998. if(!is_error(BootNotification))
  10999. {
  11000. // Required data
  11001. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11002. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11003. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11004. }
  11005. json_object_put(BootNotification);
  11006. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11007. BootNotificationInterval = intervalInt;
  11008. HeartBeatWaitTime = intervalInt;
  11009. //write back to ShmOCPP16Data->BootNotification
  11010. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11011. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11012. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11013. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11014. {
  11015. server_sign = TRUE;
  11016. server_pending =FALSE;
  11017. }
  11018. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11019. {
  11020. server_pending = TRUE;
  11021. }
  11022. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11023. srand(time(NULL));
  11024. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11025. SetOcppConnStatus(TRUE);
  11026. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11027. }
  11028. void handleDataTransferResponse(char *payload, int gun_index)
  11029. {
  11030. char sstr[160]={0};//sstr[200]={ 0 };
  11031. int c = 0;
  11032. char *loc;
  11033. DEBUG_INFO("handleDataTransferResponse ...\n");
  11034. loc = strstr(payload, "status");
  11035. printf("loc=%s\n",loc);
  11036. c = 0;
  11037. while (loc[3+strlen("status")+c] != '\"')
  11038. {
  11039. sstr[c] = loc[3+strlen("status")+c];
  11040. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11041. c++;
  11042. }
  11043. sstr[c] = '\0';
  11044. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11045. }
  11046. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11047. {
  11048. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11049. //struct json_object *obj;
  11050. // obj = json_tokener_parse(payload);
  11051. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11052. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11053. //No fields are defined.
  11054. }
  11055. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11056. {
  11057. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11058. //struct json_object *obj;
  11059. // obj = json_tokener_parse(payload);
  11060. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11061. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11062. //No fields are defined.
  11063. }
  11064. void handleHeartbeatResponse(char *payload, int gun_index)
  11065. {
  11066. mtrace();
  11067. DEBUG_INFO("handleHeartbeatResponse...\n");
  11068. json_object *Heartbeat;
  11069. Heartbeat = json_tokener_parse(payload);
  11070. if(!is_error(Heartbeat))
  11071. {
  11072. // Required data
  11073. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11074. }
  11075. json_object_put(Heartbeat);
  11076. if(FirstHeartBeat == 0)
  11077. {
  11078. FirstHeartBeat = 1;
  11079. DEBUG_INFO("FirstHeartBeat \n");
  11080. }
  11081. HeartBeatWithNOResponse = 0;
  11082. clientTime.Heartbeat=time((time_t*)NULL);
  11083. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11084. }
  11085. void handleMeterValuesResponse(char *payload, int gun_index)
  11086. {
  11087. mtrace();
  11088. DEBUG_INFO("handleMeterValuesResponse...\n");
  11089. }
  11090. void handleStartTransactionResponse(char *payload, int gun_index)
  11091. {
  11092. mtrace();
  11093. //int transactionIdInt = 0;
  11094. FILE *outfile;
  11095. char data[100]={0};
  11096. DEBUG_INFO("handleStartTransactionResponse...\n");
  11097. json_object *StartTransaction;
  11098. StartTransaction = json_tokener_parse(payload);
  11099. if(!is_error(StartTransaction))
  11100. {
  11101. // Required data
  11102. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11103. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11104. // Optional data
  11105. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11106. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11107. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11108. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11109. }
  11110. json_object_put(StartTransaction);
  11111. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11112. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11113. //-----------Start : write to the Queue TransactionId file -----------------//
  11114. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11115. {}
  11116. else
  11117. {
  11118. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11119. if(log == NULL)
  11120. {
  11121. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11122. return ;
  11123. }
  11124. else
  11125. {
  11126. fclose(log);
  11127. }
  11128. }
  11129. // open file for writing
  11130. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11131. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11132. {
  11133. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11134. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11135. fputs(data, outfile);
  11136. fclose (outfile);
  11137. }
  11138. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11139. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11140. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11141. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11142. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11143. }
  11144. void handleStatusNotificationResponse(char *payload, int gun_index)
  11145. {
  11146. mtrace();
  11147. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11148. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11149. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11150. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11151. }
  11152. void handleStopTransactionnResponse(char *payload, int gun_index)
  11153. {
  11154. mtrace();
  11155. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11156. json_object *StopTransaction;
  11157. StopTransaction = json_tokener_parse(payload);
  11158. if(!is_error(StopTransaction))
  11159. {
  11160. // Optional data
  11161. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11162. {
  11163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11164. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11166. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11168. }
  11169. }
  11170. json_object_put(StopTransaction);
  11171. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11172. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11173. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11174. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11175. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11176. }
  11177. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11178. {
  11179. mtrace();
  11180. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11181. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11182. }
  11183. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11184. {
  11185. mtrace();
  11186. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11187. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11188. }
  11189. void handleSignCertificateResponse(char *payload, int gun_index)
  11190. {
  11191. mtrace();
  11192. DEBUG_INFO("handleSignCertificateResponse...\n");
  11193. json_object *SignCertificate;
  11194. SignCertificate = json_tokener_parse(payload);
  11195. if(!is_error(SignCertificate))
  11196. {
  11197. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11198. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11199. }
  11200. json_object_put(SignCertificate);
  11201. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11202. }
  11203. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11204. {
  11205. mtrace();
  11206. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11207. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11208. }
  11209. //==========================================
  11210. // Handle Error routine
  11211. //==========================================
  11212. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11213. {
  11214. mtrace();
  11215. #ifdef SystemLogMessage
  11216. DEBUG_INFO("errorCode: %s\n", errorCode);
  11217. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11218. DEBUG_INFO("errorDetails: %s\n", payload);
  11219. #endif
  11220. }
  11221. //===============================================
  11222. // Common routine
  11223. //===============================================
  11224. int initialConfigurationTable(void)
  11225. {
  11226. //clock_t start_t, end_t, total_t;
  11227. FILE *fp;
  11228. FILE *outfile;
  11229. char str[512]={0};
  11230. char sstr[256]={0};
  11231. int c = 0;
  11232. char *loc;
  11233. int confVersion = 3;
  11234. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11235. //start_t = clock();
  11236. //printf("Starting of the program, start_t = %ld\n", start_t);
  11237. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11238. // Check configuration file size is correct
  11239. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11240. {
  11241. struct stat st;
  11242. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11243. if(st.st_size < 3100)
  11244. {
  11245. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11246. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11247. }
  11248. }
  11249. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11250. {
  11251. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11252. if(outfile == NULL)
  11253. {
  11254. DEBUG_INFO("Error opening file\n");
  11255. return FALSE;
  11256. }
  11257. /*Core Profile*/
  11258. //AllowOfflineTxForUnknownId
  11259. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11263. //AuthorizationCacheEnabled
  11264. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11268. //AuthorizeRemoteTxRequests
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11273. //BlinkRepeat
  11274. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11278. //ClockAlignedDataInterval
  11279. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11283. //ConnectionTimeOut
  11284. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11288. //GetConfigurationMaxKeys
  11289. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11293. // HeartbeatInterval
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11298. // LightIntensity
  11299. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11303. // LocalAuthorizeOffline
  11304. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11308. // LocalPreAuthorize
  11309. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11313. // MaxEnergyOnInvalidId
  11314. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11318. // MeterValuesAlignedData
  11319. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11323. else
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11326. // MeterValuesAlignedDataMaxLength
  11327. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11331. else
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11334. // MeterValuesSampledData
  11335. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11339. else
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11342. // MeterValuesSampledDataMaxLength
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11347. else
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11350. // MeterValueSampleInterval
  11351. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11355. // MinimumStatusDuration
  11356. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11359. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11361. // NumberOfConnectors
  11362. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11365. {
  11366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11367. }
  11368. else
  11369. {
  11370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11371. }
  11372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11373. // ResetRetries
  11374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11378. // ConnectorPhaseRotation
  11379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11383. // ConnectorPhaseRotationMaxLength
  11384. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11388. // StopTransactionOnEVSideDisconnect
  11389. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11393. // StopTransactionOnInvalidId
  11394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11398. // StopTxnAlignedData
  11399. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11403. // StopTxnAlignedDataMaxLength
  11404. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11408. // StopTxnSampledData
  11409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11413. else
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11416. // StopTxnSampledDataMaxLength
  11417. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11420. {
  11421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11422. }
  11423. else
  11424. {
  11425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11426. }
  11427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11428. // SupportedFeatureProfiles
  11429. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11433. // SupportedFeatureProfilesMaxLength
  11434. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11438. // TransactionMessageAttempts
  11439. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11442. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11444. // TransactionMessageRetryInterval
  11445. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11448. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11450. // UnlockConnectorOnEVSideDisconnect
  11451. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11455. // WebSocketPingInterval
  11456. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11460. // QueueOffLineStartTransactionMessage
  11461. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11465. // AuthorizationKey
  11466. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11470. // SecurityProfile
  11471. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11475. // DefaultPrice
  11476. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11480. // CustomDisplayCostAndPrice
  11481. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11485. // CustomIdleFeeAfterStop
  11486. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11490. // Configuration Version
  11491. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11495. //* Local Auth List Management Profile*/
  11496. #if 0
  11497. //For OCTT Test Case
  11498. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11501. #endif
  11502. #if 1
  11503. //LocalAuthListEnabled
  11504. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11508. #endif
  11509. //LocalAuthListMaxLength
  11510. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11514. //SendLocalListMaxLength
  11515. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11519. //ReserveConnectorZeroSupported
  11520. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11524. //* Smart Charging Profile */
  11525. //ChargeProfileMaxStackLevel
  11526. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11530. // ChargingScheduleAllowedChargingRateUnit
  11531. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11535. // ChargingScheduleMaxPeriods
  11536. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11540. // ConnectorSwitch3to1PhaseSupported
  11541. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11545. // MaxChargingProfilesInstalled
  11546. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11550. fclose(outfile);
  11551. }
  11552. else
  11553. {
  11554. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11555. char keystr[60]={0};
  11556. char readonlystr[10]={0};
  11557. char valuestr[256]={0};
  11558. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11559. if(fp == NULL) {
  11560. DEBUG_INFO("Error opening file");
  11561. return FALSE;
  11562. }
  11563. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11564. {
  11565. //DEBUG_INFO("Get Configuration \n");
  11566. if(strlen(str) > 0)
  11567. {
  11568. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11569. //*************************key*********************************/
  11570. if(strstr(str, "key") != NULL)
  11571. {
  11572. loc = strstr(str, "key");
  11573. c = 0;
  11574. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11575. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11576. {
  11577. sstr[c] = loc[strlen("key")+3+c];
  11578. c++;
  11579. }
  11580. sstr[c] = '\0';
  11581. strcpy(keystr,sstr);
  11582. }
  11583. //*************************readonly*********************************/
  11584. if(strstr(str, "readonly") != NULL)
  11585. {
  11586. loc = strstr(str, "readonly");
  11587. c = 0;
  11588. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11589. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11590. {
  11591. sstr[c] = loc[strlen("readonly")+2+c];
  11592. c++;
  11593. }
  11594. sstr[c] = '\0';
  11595. strcpy(readonlystr,sstr);
  11596. }
  11597. //*************************value*********************************/
  11598. if(strstr(str, "value") != NULL)
  11599. {
  11600. loc = strstr(str, "value");
  11601. c = 0;
  11602. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11603. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11604. {
  11605. sstr[c] = loc[strlen("value")+3+c];
  11606. c++;
  11607. }
  11608. sstr[c] = '\0';
  11609. strcpy(valuestr,sstr);
  11610. }
  11611. // DEBUG_INFO("keystr=%s\n",keystr);
  11612. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11613. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11614. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11615. {
  11616. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11617. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11619. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11620. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11621. }
  11622. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11623. {
  11624. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11627. }
  11628. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11629. {
  11630. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11632. }
  11633. if(strcmp(keystr, "BlinkRepeat") == 0)
  11634. {
  11635. //Charger.BlinkRepeat = Integer.parseInt(value);
  11636. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11638. }
  11639. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11640. {
  11641. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11643. }
  11644. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11645. {
  11646. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11648. }
  11649. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11650. {
  11651. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11653. }
  11654. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11655. {
  11656. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11658. HeartBeatWaitTime = atoi(valuestr);
  11659. }
  11660. if(strcmp(keystr, "LightIntensity") == 0)
  11661. {
  11662. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11664. }
  11665. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11666. {
  11667. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11669. }
  11670. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11671. {
  11672. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11674. }
  11675. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11676. {
  11677. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11679. }
  11680. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11681. {
  11682. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11684. }
  11685. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11686. {
  11687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11689. }
  11690. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11691. {
  11692. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11694. }
  11695. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11696. {
  11697. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11699. }
  11700. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11701. {
  11702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11704. }
  11705. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11706. {
  11707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11709. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11710. }
  11711. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11712. {
  11713. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11715. }
  11716. if(strcmp(keystr, "ResetRetries") == 0)
  11717. {
  11718. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11720. }
  11721. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11722. {
  11723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11725. }
  11726. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11727. {
  11728. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11730. }
  11731. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11732. {
  11733. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11735. }
  11736. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11737. {
  11738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11740. }
  11741. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11742. {
  11743. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11745. }
  11746. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11747. {
  11748. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11750. }
  11751. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11752. {
  11753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11755. }
  11756. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11757. {
  11758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11760. }
  11761. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11762. {
  11763. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11765. }
  11766. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11767. {
  11768. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11770. }
  11771. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11772. {
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11775. TransactionMessageAttemptsValue = atoi(valuestr);
  11776. }
  11777. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11778. {
  11779. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11781. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11782. }
  11783. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11784. {
  11785. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11787. }
  11788. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11789. {
  11790. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11792. }
  11793. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11794. {
  11795. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11797. }
  11798. if(strcmp(keystr, "AuthorizationKey") == 0)
  11799. {
  11800. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11801. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11803. }
  11804. if(strcmp(keystr, "SecurityProfile") == 0)
  11805. {
  11806. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11808. }
  11809. if(strcmp(keystr, "DefaultPrice") == 0)
  11810. {
  11811. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11813. }
  11814. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11815. {
  11816. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11818. }
  11819. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11820. {
  11821. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11823. }
  11824. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11825. {
  11826. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11828. }
  11829. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11830. {
  11831. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11833. }
  11834. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11835. {
  11836. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11838. }
  11839. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11840. {
  11841. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11843. }
  11844. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11845. {
  11846. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11848. }
  11849. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11850. {
  11851. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11853. }
  11854. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11855. {
  11856. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11858. }
  11859. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11860. {
  11861. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11863. }
  11864. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11865. {
  11866. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11868. }
  11869. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11870. {
  11871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11873. }
  11874. }
  11875. }
  11876. fclose(fp);
  11877. }
  11878. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11879. {
  11880. return PASS;
  11881. }
  11882. else
  11883. {
  11884. return FAIL;
  11885. }
  11886. }
  11887. void StoreConfigurationTable(void)
  11888. {
  11889. FILE *outfile;
  11890. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11891. if(outfile == NULL)
  11892. {
  11893. DEBUG_INFO("Error opening file");
  11894. return ;
  11895. }
  11896. /*Core Profile*/
  11897. //AllowOfflineTxForUnknownId
  11898. /*
  11899. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11900. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11903. */
  11904. //DEBUG_INFO("data=%s\n",data);
  11905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11906. //AuthorizationCacheEnabled
  11907. /*
  11908. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11911. */
  11912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11913. //AuthorizeRemoteTxRequests
  11914. /*
  11915. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11918. */
  11919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11920. //BlinkRepeat
  11921. /*
  11922. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11925. */
  11926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11927. //ClockAlignedDataInterval
  11928. /*
  11929. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11932. */
  11933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11934. //ConnectionTimeOut
  11935. /*
  11936. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11939. */
  11940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11941. //GetConfigurationMaxKeys
  11942. /*
  11943. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11946. */
  11947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11948. // HeartbeatInterval
  11949. /*
  11950. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11953. */
  11954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11955. // LightIntensity
  11956. /*
  11957. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11960. */
  11961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11962. // LocalAuthorizeOffline
  11963. /*
  11964. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11967. */
  11968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11969. // LocalPreAuthorize
  11970. /*
  11971. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11974. */
  11975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11976. // MaxEnergyOnInvalidId
  11977. /*
  11978. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11981. */
  11982. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11984. // MeterValuesAlignedData
  11985. /*
  11986. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11989. */
  11990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11991. // MeterValuesAlignedDataMaxLength
  11992. /*
  11993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11996. */
  11997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11998. // MeterValuesSampledData
  11999. /*
  12000. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12003. */
  12004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12005. // MeterValuesSampledDataMaxLength
  12006. /*
  12007. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12010. */
  12011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12012. // MeterValueSampleInterval
  12013. /*
  12014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12017. */
  12018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12019. // MinimumStatusDuration
  12020. /*
  12021. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12024. */
  12025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12026. // NumberOfConnectors
  12027. /*
  12028. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12031. {
  12032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12033. }
  12034. else
  12035. {
  12036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12037. }
  12038. */
  12039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12040. // ResetRetries
  12041. /*
  12042. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12045. */
  12046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12047. // ConnectorPhaseRotation
  12048. /*
  12049. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12052. */
  12053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12054. // ConnectorPhaseRotationMaxLength
  12055. /*
  12056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12059. */
  12060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12061. // StopTransactionOnEVSideDisconnect
  12062. /*
  12063. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12066. */
  12067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12068. // StopTransactionOnInvalidId
  12069. /*
  12070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12073. */
  12074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12075. // StopTxnAlignedData
  12076. /*
  12077. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12082. // StopTxnAlignedDataMaxLength
  12083. /*
  12084. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12087. */
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12089. // StopTxnSampledData
  12090. /*
  12091. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12094. */
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12096. // StopTxnSampledDataMaxLength
  12097. /*
  12098. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12101. */
  12102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12103. // SupportedFeatureProfiles
  12104. /*
  12105. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12108. */
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12110. // SupportedFeatureProfilesMaxLength
  12111. /*
  12112. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12115. */
  12116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12117. // TransactionMessageAttempts
  12118. /*
  12119. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12122. */
  12123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12124. // TransactionMessageRetryInterval
  12125. /*
  12126. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12129. */
  12130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12131. // UnlockConnectorOnEVSideDisconnect
  12132. /*
  12133. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12136. */
  12137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12138. // WebSocketPingInterval
  12139. /*
  12140. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12143. */
  12144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12145. // QueueOffLineStartTransactionMessage
  12146. /*
  12147. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12150. */
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12152. // AuthorizationKey
  12153. /*
  12154. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12157. */
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12159. // SecurityProfile
  12160. /*
  12161. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12164. */
  12165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12166. // DefaultPrice
  12167. /*
  12168. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12171. */
  12172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12173. // CustomDisplayCostAndPrice
  12174. /*
  12175. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12178. */
  12179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12180. // CustomIdleFeeAfterStop
  12181. /*
  12182. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12185. */
  12186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12187. // ConfigurationVersion
  12188. /*
  12189. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12192. */
  12193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12194. //* Local Auth List Management Profile*/
  12195. //LocalAuthListEnabled
  12196. /*
  12197. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12200. */
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12202. //LocalAuthListMaxLength
  12203. /*
  12204. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12207. */
  12208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12209. //SendLocalListMaxLength
  12210. /*
  12211. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12214. */
  12215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12216. //ReserveConnectorZeroSupported
  12217. /*
  12218. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12221. */
  12222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12223. //* Smart Charging Profile */
  12224. //ChargeProfileMaxStackLevel
  12225. /*
  12226. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12229. */
  12230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12231. // ChargingScheduleAllowedChargingRateUnit
  12232. /*
  12233. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12236. */
  12237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12238. // ChargingScheduleMaxPeriods
  12239. /*
  12240. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12243. */
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12245. // ConnectorSwitch3to1PhaseSupported
  12246. /*
  12247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12250. */
  12251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12252. // MaxChargingProfilesInstalled
  12253. /*
  12254. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12257. */
  12258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12259. fclose(outfile);
  12260. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12261. }
  12262. void getKeyValue(char *keyReq)
  12263. {
  12264. int isEmpty = FALSE;
  12265. int isKnowKey = FALSE;
  12266. DEBUG_INFO("keyReq = %s\n", keyReq);
  12267. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12268. isEmpty = TRUE;
  12269. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12270. {
  12271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12274. {
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12276. }
  12277. else
  12278. {
  12279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12280. }
  12281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12282. isKnowKey = TRUE;
  12283. }
  12284. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12285. {
  12286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12289. {
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12291. }
  12292. else
  12293. {
  12294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12295. }
  12296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12297. isKnowKey = TRUE;
  12298. }
  12299. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12300. {
  12301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12304. {
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12306. }
  12307. else
  12308. {
  12309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12310. }
  12311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12312. isKnowKey = TRUE;
  12313. }
  12314. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12315. {
  12316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12319. {
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12321. }
  12322. else
  12323. {
  12324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12325. }
  12326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12327. isKnowKey = TRUE;
  12328. }
  12329. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12330. {
  12331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12334. {
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12336. }
  12337. else
  12338. {
  12339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12340. }
  12341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12342. isKnowKey = TRUE;
  12343. }
  12344. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12345. {
  12346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12349. {
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12351. }
  12352. else
  12353. {
  12354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12355. }
  12356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12357. isKnowKey = TRUE;
  12358. }
  12359. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12360. {
  12361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12364. {
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12366. }
  12367. else
  12368. {
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12370. }
  12371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12372. isKnowKey = TRUE;
  12373. }
  12374. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12375. {
  12376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12379. {
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12381. }
  12382. else
  12383. {
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12385. }
  12386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12387. isKnowKey = TRUE;
  12388. }
  12389. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12390. {
  12391. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12394. {
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12396. }
  12397. else
  12398. {
  12399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12400. }
  12401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12402. isKnowKey = TRUE;
  12403. }
  12404. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12405. {
  12406. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12409. {
  12410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12411. }
  12412. else
  12413. {
  12414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12415. }
  12416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12417. isKnowKey = TRUE;
  12418. }
  12419. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12420. {
  12421. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12424. {
  12425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12426. }
  12427. else
  12428. {
  12429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12430. }
  12431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12432. isKnowKey = TRUE;
  12433. }
  12434. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12435. {
  12436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12439. {
  12440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12441. }
  12442. else
  12443. {
  12444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12445. }
  12446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12447. isKnowKey = TRUE;
  12448. }
  12449. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12450. {
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12454. {
  12455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12456. }
  12457. else
  12458. {
  12459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12460. }
  12461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12462. isKnowKey = TRUE;
  12463. }
  12464. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12465. {
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12469. {
  12470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12471. }
  12472. else
  12473. {
  12474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12475. }
  12476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12477. isKnowKey = TRUE;
  12478. }
  12479. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12480. {
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12484. {
  12485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12486. }
  12487. else
  12488. {
  12489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12490. }
  12491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12492. isKnowKey = TRUE;
  12493. }
  12494. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12495. {
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12499. {
  12500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12501. }
  12502. else
  12503. {
  12504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12505. }
  12506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12507. isKnowKey = TRUE;
  12508. }
  12509. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12510. {
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12514. {
  12515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12516. }
  12517. else
  12518. {
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12520. }
  12521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12522. isKnowKey = TRUE;
  12523. }
  12524. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12525. {
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12529. {
  12530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12531. }
  12532. else
  12533. {
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12535. }
  12536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12537. isKnowKey = TRUE;
  12538. }
  12539. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12540. {
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12544. {
  12545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12546. }
  12547. else
  12548. {
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12550. }
  12551. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12553. isKnowKey = TRUE;
  12554. }
  12555. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12556. {
  12557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12562. }
  12563. else
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12566. }
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12568. isKnowKey = TRUE;
  12569. }
  12570. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12571. {
  12572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12577. }
  12578. else
  12579. {
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12581. }
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12583. isKnowKey = TRUE;
  12584. }
  12585. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12586. {
  12587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12592. }
  12593. else
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12596. }
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12598. isKnowKey = TRUE;
  12599. }
  12600. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12601. {
  12602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12607. }
  12608. else
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12611. }
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12613. isKnowKey = TRUE;
  12614. }
  12615. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12616. {
  12617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12622. }
  12623. else
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12626. }
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12628. isKnowKey = TRUE;
  12629. }
  12630. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12631. {
  12632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12637. }
  12638. else
  12639. {
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12641. }
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12643. isKnowKey = TRUE;
  12644. }
  12645. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12646. {
  12647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12650. {
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12652. }
  12653. else
  12654. {
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12656. }
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12658. isKnowKey = TRUE;
  12659. }
  12660. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12661. {
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12665. {
  12666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12667. }
  12668. else
  12669. {
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12671. }
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12673. isKnowKey = TRUE;
  12674. }
  12675. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12676. {
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12680. {
  12681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12682. }
  12683. else
  12684. {
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12686. }
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12688. isKnowKey = TRUE;
  12689. }
  12690. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12691. {
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12695. {
  12696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12697. }
  12698. else
  12699. {
  12700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12701. }
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12703. isKnowKey = TRUE;
  12704. }
  12705. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12706. {
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12710. {
  12711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12712. }
  12713. else
  12714. {
  12715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12716. }
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12718. isKnowKey = TRUE;
  12719. }
  12720. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12721. {
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12725. {
  12726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12727. }
  12728. else
  12729. {
  12730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12731. }
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12733. isKnowKey = TRUE;
  12734. }
  12735. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12736. {
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12740. {
  12741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12742. }
  12743. else
  12744. {
  12745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12746. }
  12747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12748. isKnowKey = TRUE;
  12749. }
  12750. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12751. {
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12755. {
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12757. }
  12758. else
  12759. {
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12761. }
  12762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12763. isKnowKey = TRUE;
  12764. }
  12765. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12766. {
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12770. {
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12772. }
  12773. else
  12774. {
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12776. }
  12777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12778. isKnowKey = TRUE;
  12779. }
  12780. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12781. {
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12785. {
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12787. }
  12788. else
  12789. {
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12791. }
  12792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12793. isKnowKey = TRUE;
  12794. }
  12795. /*
  12796. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12797. {
  12798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12803. }
  12804. else
  12805. {
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12807. }
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12809. isKnowKey = TRUE;
  12810. }*/
  12811. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12812. {
  12813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12816. {
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12818. }
  12819. else
  12820. {
  12821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12822. }
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12824. isKnowKey = TRUE;
  12825. }
  12826. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12827. {
  12828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12833. }
  12834. else
  12835. {
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12837. }
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12839. isKnowKey = TRUE;
  12840. }
  12841. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12842. {
  12843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12848. }
  12849. else
  12850. {
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12852. }
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12854. isKnowKey = TRUE;
  12855. }
  12856. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12857. {
  12858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12863. }
  12864. else
  12865. {
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12867. }
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12869. isKnowKey = TRUE;
  12870. }
  12871. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12872. {
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12878. }
  12879. else
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12882. }
  12883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12884. isKnowKey = TRUE;
  12885. }
  12886. #if 1
  12887. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12888. {
  12889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12891. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12892. {
  12893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12894. }
  12895. else
  12896. {
  12897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12898. }
  12899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12900. isKnowKey = TRUE;
  12901. }
  12902. #endif
  12903. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12904. {
  12905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12907. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12908. {
  12909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12910. }
  12911. else
  12912. {
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12914. }
  12915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12916. isKnowKey = TRUE;
  12917. }
  12918. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12919. {
  12920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12922. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12923. {
  12924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12925. }
  12926. else
  12927. {
  12928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12929. }
  12930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12931. isKnowKey = TRUE;
  12932. }
  12933. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12934. {
  12935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12937. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12938. {
  12939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12940. }
  12941. else
  12942. {
  12943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12944. }
  12945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12946. isKnowKey = TRUE;
  12947. }
  12948. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12949. {
  12950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12952. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12953. {
  12954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12955. }
  12956. else
  12957. {
  12958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12959. }
  12960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12961. isKnowKey = TRUE;
  12962. }
  12963. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12964. {
  12965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12967. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12968. {
  12969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12970. }
  12971. else
  12972. {
  12973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12974. }
  12975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12976. isKnowKey = TRUE;
  12977. }
  12978. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12979. {
  12980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12982. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12983. {
  12984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12985. }
  12986. else
  12987. {
  12988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12989. }
  12990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12991. isKnowKey = TRUE;
  12992. }
  12993. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12994. {
  12995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12997. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12998. {
  12999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13000. }
  13001. else
  13002. {
  13003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13004. }
  13005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13006. isKnowKey = TRUE;
  13007. }
  13008. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13009. {
  13010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13012. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13013. {
  13014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13015. }
  13016. else
  13017. {
  13018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13019. }
  13020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13021. isKnowKey = TRUE;
  13022. }
  13023. //=========================================================
  13024. if(!isEmpty && !isKnowKey)
  13025. {
  13026. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13027. strcpy(unknownkey[UnknownKeynum], keyReq);
  13028. UnknownKeynum = UnknownKeynum + 1;
  13029. }
  13030. }
  13031. void processUnkownKey(void)
  13032. {
  13033. DEBUG_INFO("processUnkownKey...\n");
  13034. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13035. for(int index=0; index < UnknownKeynum; index++)
  13036. {
  13037. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13038. {
  13039. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13040. }
  13041. }
  13042. }
  13043. int setKeyValue(char *key, char *value)
  13044. {
  13045. int isSuccess = NotSupported;
  13046. int check_ascii=0;
  13047. char str[256]={0};
  13048. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13049. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13050. {
  13051. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13053. {
  13054. strcpy(str, (const char*)value);
  13055. for(int i = 0; str[i]; i++){
  13056. str[i] = tolower(str[i]);
  13057. }
  13058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13059. isSuccess = ConfigurationStatus_Accepted;
  13060. }
  13061. else
  13062. {
  13063. isSuccess = ConfigurationStatus_Rejected;
  13064. }
  13065. }
  13066. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13067. {
  13068. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13070. {
  13071. strcpy(str, (const char*)value);
  13072. for(int i = 0; str[i]; i++){
  13073. str[i] = tolower(str[i]);
  13074. }
  13075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13076. isSuccess = ConfigurationStatus_Accepted;
  13077. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13078. }
  13079. else
  13080. {
  13081. isSuccess = ConfigurationStatus_Rejected;
  13082. }
  13083. }
  13084. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13085. {
  13086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13087. {
  13088. strcpy(str, (const char*)value);
  13089. for(int i = 0; str[i]; i++)
  13090. {
  13091. str[i] = tolower(str[i]);
  13092. }
  13093. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13095. isSuccess = ConfigurationStatus_Accepted;
  13096. }
  13097. else
  13098. {
  13099. isSuccess = ConfigurationStatus_Rejected;
  13100. }
  13101. }
  13102. if(strcmp(key, "BlinkRepeat") == 0)
  13103. {
  13104. //Charger.BlinkRepeat = Integer.parseInt(value);
  13105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13106. {
  13107. check_ascii = value[0];
  13108. if( (check_ascii < 48) || (check_ascii > 57) )
  13109. {
  13110. isSuccess = ConfigurationStatus_Rejected;
  13111. }
  13112. else
  13113. {
  13114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13115. isSuccess = ConfigurationStatus_Accepted;
  13116. }
  13117. }
  13118. else
  13119. {
  13120. isSuccess = ConfigurationStatus_Rejected;
  13121. }
  13122. }
  13123. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13124. {
  13125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13126. {
  13127. check_ascii = value[0];
  13128. if( (check_ascii < 48) || (check_ascii > 57) )
  13129. {
  13130. isSuccess = ConfigurationStatus_Rejected;
  13131. }
  13132. else
  13133. {
  13134. if((atoi(value) == 0) || (atoi(value) >= 10))
  13135. {
  13136. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13138. isSuccess = ConfigurationStatus_Accepted;
  13139. }
  13140. else
  13141. isSuccess = ConfigurationStatus_Rejected;
  13142. }
  13143. }
  13144. else
  13145. {
  13146. isSuccess = ConfigurationStatus_Rejected;
  13147. }
  13148. }
  13149. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13150. {
  13151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13152. {
  13153. check_ascii = value[0];
  13154. if( (check_ascii < 48) || (check_ascii > 57) )
  13155. {
  13156. isSuccess = ConfigurationStatus_Rejected;
  13157. }
  13158. else
  13159. {
  13160. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13162. isSuccess = ConfigurationStatus_Accepted;
  13163. }
  13164. }
  13165. else
  13166. {
  13167. isSuccess = ConfigurationStatus_Rejected;
  13168. }
  13169. }
  13170. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13171. {
  13172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13173. {
  13174. check_ascii = value[0];
  13175. if( (check_ascii < 48) || (check_ascii > 57) )
  13176. {
  13177. isSuccess = ConfigurationStatus_Rejected;
  13178. }
  13179. else
  13180. {
  13181. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13183. isSuccess = ConfigurationStatus_Accepted;
  13184. }
  13185. }
  13186. else
  13187. {
  13188. isSuccess = ConfigurationStatus_Rejected;
  13189. }
  13190. }
  13191. if(strcmp(key, "HeartbeatInterval") == 0)
  13192. {
  13193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13194. {
  13195. check_ascii = value[0];
  13196. if( (check_ascii < 48) || (check_ascii > 57) )
  13197. {
  13198. isSuccess = ConfigurationStatus_Rejected;
  13199. }
  13200. else
  13201. {
  13202. if((atoi(value) == 0) || (atoi(value) >= 10))
  13203. {
  13204. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13206. HeartBeatWaitTime = atoi(value);
  13207. isSuccess = ConfigurationStatus_Accepted;
  13208. }
  13209. else
  13210. {
  13211. isSuccess = ConfigurationStatus_Rejected;
  13212. }
  13213. }
  13214. }
  13215. else
  13216. {
  13217. isSuccess = ConfigurationStatus_Rejected;
  13218. }
  13219. }
  13220. if(strcmp(key, "LightIntensity") == 0)
  13221. {
  13222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13223. {
  13224. check_ascii = value[0];
  13225. if( (check_ascii < 48) || (check_ascii > 57) )
  13226. {
  13227. isSuccess = ConfigurationStatus_Rejected;
  13228. }
  13229. else
  13230. {
  13231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13232. isSuccess = ConfigurationStatus_Accepted;
  13233. }
  13234. }
  13235. else
  13236. {
  13237. isSuccess = ConfigurationStatus_Rejected;
  13238. }
  13239. }
  13240. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13241. {
  13242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13243. {
  13244. strcpy(str, (const char*)value);
  13245. for(int i = 0; str[i]; i++)
  13246. {
  13247. str[i] = tolower(str[i]);
  13248. }
  13249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13250. isSuccess = ConfigurationStatus_Accepted;
  13251. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13252. }
  13253. else
  13254. {
  13255. isSuccess = ConfigurationStatus_Rejected;
  13256. }
  13257. }
  13258. if(strcmp(key, "LocalPreAuthorize") == 0)
  13259. {
  13260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13261. {
  13262. strcpy(str, (const char*)value);
  13263. for(int i = 0; str[i]; i++)
  13264. {
  13265. str[i] = tolower(str[i]);
  13266. }
  13267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13268. isSuccess = ConfigurationStatus_Accepted;
  13269. }
  13270. else
  13271. {
  13272. isSuccess = ConfigurationStatus_Rejected;
  13273. }
  13274. }
  13275. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13276. {
  13277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13278. {
  13279. check_ascii = value[0];
  13280. if( (check_ascii < 48) || (check_ascii > 57) )
  13281. {
  13282. isSuccess = ConfigurationStatus_Rejected;
  13283. }
  13284. else
  13285. {
  13286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13287. isSuccess = ConfigurationStatus_Accepted;
  13288. }
  13289. }
  13290. else
  13291. {
  13292. isSuccess = ConfigurationStatus_Rejected;
  13293. }
  13294. }
  13295. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13296. {
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13298. {
  13299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13300. isSuccess = ConfigurationStatus_Accepted;
  13301. }
  13302. else
  13303. {
  13304. isSuccess = ConfigurationStatus_Rejected;
  13305. }
  13306. }
  13307. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13308. {
  13309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13310. {
  13311. check_ascii = value[0];
  13312. if( (check_ascii < 48) || (check_ascii > 57) )
  13313. {
  13314. isSuccess = ConfigurationStatus_Rejected;
  13315. }
  13316. else
  13317. {
  13318. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13320. isSuccess = ConfigurationStatus_Accepted;
  13321. }
  13322. }
  13323. else
  13324. {
  13325. isSuccess = ConfigurationStatus_Rejected;
  13326. }
  13327. }
  13328. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13329. {
  13330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13331. {
  13332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13333. isSuccess = ConfigurationStatus_Accepted;
  13334. }
  13335. else
  13336. {
  13337. isSuccess = ConfigurationStatus_Rejected;
  13338. }
  13339. }
  13340. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13341. {
  13342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13343. {
  13344. check_ascii = value[0];
  13345. if( (check_ascii < 48) || (check_ascii > 57) )
  13346. {
  13347. isSuccess = ConfigurationStatus_Rejected;
  13348. }
  13349. else
  13350. {
  13351. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13353. isSuccess = ConfigurationStatus_Accepted;
  13354. }
  13355. }
  13356. else
  13357. {
  13358. isSuccess = ConfigurationStatus_Rejected;
  13359. }
  13360. }
  13361. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13362. {
  13363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13364. {
  13365. check_ascii = value[0];
  13366. if( (check_ascii < 48) || (check_ascii > 57) )
  13367. {
  13368. isSuccess = ConfigurationStatus_Rejected;
  13369. }
  13370. else
  13371. {
  13372. if((atoi(value) == 0) || (atoi(value) >= 10))
  13373. {
  13374. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13376. isSuccess = ConfigurationStatus_Accepted;
  13377. }
  13378. else
  13379. {
  13380. isSuccess = ConfigurationStatus_Rejected;
  13381. }
  13382. }
  13383. }
  13384. else
  13385. {
  13386. isSuccess = ConfigurationStatus_Rejected;
  13387. }
  13388. }
  13389. if(strcmp(key, "MinimumStatusDuration") == 0)
  13390. {
  13391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13392. {
  13393. check_ascii = value[0];
  13394. if( (check_ascii < 48) || (check_ascii > 57) )
  13395. {
  13396. isSuccess = ConfigurationStatus_Rejected;
  13397. }
  13398. else
  13399. {
  13400. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13401. {
  13402. isSuccess = ConfigurationStatus_Rejected;
  13403. }
  13404. else
  13405. {
  13406. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13408. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13409. isSuccess = ConfigurationStatus_Accepted;
  13410. }
  13411. }
  13412. }
  13413. else
  13414. {
  13415. isSuccess = ConfigurationStatus_Rejected;
  13416. }
  13417. }
  13418. if(strcmp(key, "NumberOfConnectors") == 0)
  13419. {
  13420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13421. {
  13422. check_ascii = value[0];
  13423. if( (check_ascii < 48) || (check_ascii > 57) )
  13424. {
  13425. isSuccess = ConfigurationStatus_Rejected;
  13426. }
  13427. else
  13428. {
  13429. //Charger.ResetRetries = Integer.parseInt(value);
  13430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13431. isSuccess = ConfigurationStatus_Accepted;
  13432. }
  13433. }
  13434. else
  13435. {
  13436. isSuccess = ConfigurationStatus_Rejected;
  13437. }
  13438. }
  13439. if(strcmp(key, "ResetRetries") == 0)
  13440. {
  13441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13442. {
  13443. check_ascii = value[0];
  13444. if( (check_ascii < 48) || (check_ascii > 57) )
  13445. {
  13446. isSuccess = ConfigurationStatus_Rejected;
  13447. }
  13448. else
  13449. {
  13450. //Charger.ResetRetries = Integer.parseInt(value);
  13451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13452. isSuccess = ConfigurationStatus_Accepted;
  13453. }
  13454. }
  13455. else
  13456. {
  13457. isSuccess = ConfigurationStatus_Rejected;
  13458. }
  13459. }
  13460. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13461. {
  13462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13463. {
  13464. strcpy(str, (const char*)value);
  13465. for(int i = 0; str[i]; i++)
  13466. {
  13467. str[i] = tolower(str[i]);
  13468. }
  13469. if(strcmp(str, "notapplicable")== 0)
  13470. {
  13471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13472. isSuccess = ConfigurationStatus_Accepted;
  13473. }
  13474. else if(strcmp(str, "unknown")== 0)
  13475. {
  13476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13477. isSuccess = ConfigurationStatus_Accepted;
  13478. }
  13479. else if(strcmp(str, "rst")== 0)
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13482. isSuccess = ConfigurationStatus_Accepted;
  13483. }
  13484. else if(strcmp(str, "rts")== 0)
  13485. {
  13486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13487. isSuccess = ConfigurationStatus_Accepted;
  13488. }
  13489. else if(strcmp(str, "srt")== 0)
  13490. {
  13491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13492. isSuccess = ConfigurationStatus_Accepted;
  13493. }
  13494. else if(strcmp(str, "str")== 0)
  13495. {
  13496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13497. isSuccess = ConfigurationStatus_Accepted;
  13498. }
  13499. else if(strcmp(str, "trs")== 0)
  13500. {
  13501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13502. isSuccess = ConfigurationStatus_Accepted;
  13503. }
  13504. else if(strcmp(str, "tsr")== 0)
  13505. {
  13506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13507. isSuccess = ConfigurationStatus_Accepted;
  13508. }
  13509. else
  13510. {
  13511. isSuccess = ConfigurationStatus_Rejected;
  13512. }
  13513. }
  13514. else
  13515. {
  13516. isSuccess = ConfigurationStatus_Rejected;
  13517. }
  13518. }
  13519. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13520. {
  13521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13522. {
  13523. check_ascii = value[0];
  13524. if( (check_ascii < 48) || (check_ascii > 57) )
  13525. {
  13526. isSuccess = ConfigurationStatus_Rejected;
  13527. }
  13528. else
  13529. {
  13530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13531. isSuccess = ConfigurationStatus_Accepted;
  13532. }
  13533. }
  13534. else
  13535. {
  13536. isSuccess = ConfigurationStatus_Rejected;
  13537. }
  13538. }
  13539. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13540. {
  13541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13542. {
  13543. strcpy(str, (const char*)value);
  13544. for(int i = 0; str[i]; i++)
  13545. {
  13546. str[i] = tolower(str[i]);
  13547. }
  13548. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13550. isSuccess = ConfigurationStatus_Accepted;
  13551. }
  13552. else
  13553. {
  13554. isSuccess = ConfigurationStatus_Rejected;
  13555. }
  13556. }
  13557. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13558. {
  13559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13560. {
  13561. strcpy(str, (const char*)value);
  13562. for(int i = 0; str[i]; i++)
  13563. {
  13564. str[i] = tolower(str[i]);
  13565. }
  13566. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13568. isSuccess = ConfigurationStatus_Accepted;
  13569. }
  13570. else
  13571. {
  13572. isSuccess = ConfigurationStatus_Rejected;
  13573. }
  13574. }
  13575. if(strcmp(key, "StopTxnAlignedData") == 0)
  13576. {
  13577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13578. {
  13579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13580. isSuccess = ConfigurationStatus_Accepted;
  13581. }
  13582. else
  13583. {
  13584. isSuccess = ConfigurationStatus_Rejected;
  13585. }
  13586. }
  13587. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13588. {
  13589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13590. {
  13591. check_ascii = value[0];
  13592. if( (check_ascii < 48) || (check_ascii > 57) )
  13593. {
  13594. isSuccess = ConfigurationStatus_Rejected;
  13595. }
  13596. else
  13597. {
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13599. isSuccess = ConfigurationStatus_Accepted;
  13600. }
  13601. }
  13602. else
  13603. {
  13604. isSuccess = ConfigurationStatus_Rejected;
  13605. }
  13606. }
  13607. if(strcmp(key, "StopTxnSampledData") == 0)
  13608. {
  13609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13610. {
  13611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13612. isSuccess = ConfigurationStatus_Accepted;
  13613. }
  13614. else
  13615. {
  13616. isSuccess = ConfigurationStatus_Rejected;
  13617. }
  13618. }
  13619. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13620. {
  13621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13622. {
  13623. check_ascii = value[0];
  13624. if( (check_ascii < 48) || (check_ascii > 57) )
  13625. {
  13626. isSuccess = ConfigurationStatus_Rejected;
  13627. }
  13628. else
  13629. {
  13630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13631. isSuccess = ConfigurationStatus_Accepted;
  13632. }
  13633. }
  13634. else
  13635. {
  13636. isSuccess = ConfigurationStatus_Rejected;
  13637. }
  13638. }
  13639. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13640. {
  13641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13642. {
  13643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13644. isSuccess = ConfigurationStatus_Accepted;
  13645. }
  13646. else
  13647. {
  13648. isSuccess = ConfigurationStatus_Rejected;
  13649. }
  13650. }
  13651. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13652. {
  13653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13654. {
  13655. check_ascii = value[0];
  13656. if( (check_ascii < 48) || (check_ascii > 57) )
  13657. {
  13658. isSuccess = ConfigurationStatus_Rejected;
  13659. }
  13660. else
  13661. {
  13662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13663. isSuccess = ConfigurationStatus_Accepted;
  13664. }
  13665. }
  13666. else
  13667. {
  13668. isSuccess = ConfigurationStatus_Rejected;
  13669. }
  13670. }
  13671. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13672. {
  13673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13674. {
  13675. check_ascii = value[0];
  13676. if( (check_ascii < 48) || (check_ascii > 57) )
  13677. {
  13678. isSuccess = ConfigurationStatus_Rejected;
  13679. }
  13680. else
  13681. {
  13682. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13684. TransactionMessageAttemptsValue = atoi(value);
  13685. isSuccess = ConfigurationStatus_Accepted;
  13686. }
  13687. }
  13688. else
  13689. {
  13690. isSuccess = ConfigurationStatus_Rejected;
  13691. }
  13692. }
  13693. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13694. {
  13695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13696. {
  13697. check_ascii = value[0];
  13698. if( (check_ascii < 48) || (check_ascii > 57) )
  13699. {
  13700. isSuccess = ConfigurationStatus_Rejected;
  13701. }
  13702. else
  13703. {
  13704. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13706. TransactionMessageRetryIntervalValue = atoi(value);
  13707. isSuccess = ConfigurationStatus_Accepted;
  13708. }
  13709. }
  13710. else
  13711. {
  13712. isSuccess = ConfigurationStatus_Rejected;
  13713. }
  13714. }
  13715. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13716. {
  13717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13718. {
  13719. strcpy(str, (const char*)value);
  13720. for(int i = 0; str[i]; i++)
  13721. {
  13722. str[i] = tolower(str[i]);
  13723. }
  13724. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13726. isSuccess = ConfigurationStatus_Accepted;
  13727. }
  13728. else
  13729. {
  13730. isSuccess = ConfigurationStatus_Rejected;
  13731. }
  13732. }
  13733. if(strcmp(key, "WebSocketPingInterval") == 0)
  13734. {
  13735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13736. {
  13737. check_ascii = value[0];
  13738. if( (check_ascii < 48) || (check_ascii > 57) )
  13739. {
  13740. isSuccess = ConfigurationStatus_Rejected;
  13741. }
  13742. else
  13743. {
  13744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13745. isSuccess = ConfigurationStatus_Accepted;
  13746. }
  13747. }
  13748. else
  13749. {
  13750. isSuccess = ConfigurationStatus_Rejected;
  13751. }
  13752. }
  13753. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13754. {
  13755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13756. {
  13757. strcpy(str, (const char*)value);
  13758. for(int i = 0; str[i]; i++)
  13759. {
  13760. str[i] = tolower(str[i]);
  13761. }
  13762. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13764. isSuccess = ConfigurationStatus_Accepted;
  13765. }
  13766. else
  13767. {
  13768. isSuccess = ConfigurationStatus_Rejected;
  13769. }
  13770. }
  13771. if(strcmp(key, "AuthorizationKey") == 0)
  13772. {
  13773. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13774. {
  13775. strcpy(str, (const char*)value);
  13776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13777. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13778. isSuccess = ConfigurationStatus_Accepted;
  13779. }
  13780. else
  13781. {
  13782. isSuccess = ConfigurationStatus_Rejected;
  13783. }
  13784. }
  13785. if(strcmp(key, "SecurityProfile") == 0)
  13786. {
  13787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13788. {
  13789. check_ascii = value[0];
  13790. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13791. {
  13792. isSuccess = ConfigurationStatus_Rejected;
  13793. }
  13794. else if(check_ascii == 0x33)
  13795. {
  13796. isSuccess = NotSupported;
  13797. }
  13798. else
  13799. {
  13800. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13801. {
  13802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13803. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13804. isSuccess = ConfigurationStatus_Accepted;
  13805. }
  13806. else
  13807. isSuccess = ConfigurationStatus_Rejected;
  13808. }
  13809. }
  13810. else
  13811. {
  13812. isSuccess = ConfigurationStatus_Rejected;
  13813. }
  13814. }
  13815. if(strcmp(key, "DefaultPrice") == 0)
  13816. {
  13817. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13818. {
  13819. strcpy(str, (const char*)value);
  13820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13821. isSuccess = ConfigurationStatus_Accepted;
  13822. }
  13823. else
  13824. {
  13825. isSuccess = ConfigurationStatus_Rejected;
  13826. }
  13827. }
  13828. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13829. {
  13830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13831. {
  13832. strcpy(str, (const char*)value);
  13833. for(int i = 0; str[i]; i++)
  13834. {
  13835. str[i] = tolower(str[i]);
  13836. }
  13837. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13839. isSuccess = ConfigurationStatus_Accepted;
  13840. }
  13841. else
  13842. {
  13843. isSuccess = ConfigurationStatus_Rejected;
  13844. }
  13845. }
  13846. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13847. {
  13848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13849. {
  13850. strcpy(str, (const char*)value);
  13851. for(int i = 0; str[i]; i++)
  13852. {
  13853. str[i] = tolower(str[i]);
  13854. }
  13855. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13857. isSuccess = ConfigurationStatus_Accepted;
  13858. }
  13859. else
  13860. {
  13861. isSuccess = ConfigurationStatus_Rejected;
  13862. }
  13863. }
  13864. #if 0
  13865. //For OCPP Test Case
  13866. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13867. {
  13868. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13869. {
  13870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13871. isSuccess = ConfigurationStatus_Accepted;
  13872. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13873. }
  13874. else
  13875. {
  13876. isSuccess = ConfigurationStatus_Rejected;
  13877. }
  13878. }
  13879. #endif
  13880. #if 1
  13881. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13882. {
  13883. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13884. {
  13885. strcpy(str, (const char*)value);
  13886. for(int i = 0; str[i]; i++)
  13887. {
  13888. str[i] = tolower(str[i]);
  13889. }
  13890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13891. isSuccess = ConfigurationStatus_Accepted;
  13892. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13893. }
  13894. else
  13895. {
  13896. isSuccess = ConfigurationStatus_Rejected;
  13897. }
  13898. }
  13899. #endif
  13900. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13901. {
  13902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13903. {
  13904. check_ascii = value[0];
  13905. if( (check_ascii < 48) || (check_ascii > 57) )
  13906. {
  13907. isSuccess = ConfigurationStatus_Rejected;
  13908. }
  13909. else
  13910. {
  13911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13912. isSuccess = ConfigurationStatus_Accepted;
  13913. }
  13914. }
  13915. else
  13916. {
  13917. isSuccess = ConfigurationStatus_Rejected;
  13918. }
  13919. }
  13920. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13921. {
  13922. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13923. {
  13924. check_ascii = value[0];
  13925. if( (check_ascii < 48) || (check_ascii > 57) )
  13926. {
  13927. isSuccess = ConfigurationStatus_Rejected;
  13928. }
  13929. else
  13930. {
  13931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13932. isSuccess = ConfigurationStatus_Accepted;
  13933. }
  13934. }
  13935. else
  13936. {
  13937. isSuccess = ConfigurationStatus_Rejected;
  13938. }
  13939. }
  13940. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13941. {
  13942. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13943. {
  13944. strcpy(str, (const char*)value);
  13945. for(int i = 0; str[i]; i++)
  13946. {
  13947. str[i] = tolower(str[i]);
  13948. }
  13949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13950. isSuccess = ConfigurationStatus_Accepted;
  13951. }
  13952. else
  13953. {
  13954. isSuccess = ConfigurationStatus_Rejected;
  13955. }
  13956. }
  13957. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13958. {
  13959. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13960. {
  13961. check_ascii = value[0];
  13962. if( (check_ascii < 48) || (check_ascii > 57) )
  13963. {
  13964. isSuccess = ConfigurationStatus_Rejected;
  13965. }
  13966. else
  13967. {
  13968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13969. isSuccess = ConfigurationStatus_Accepted;
  13970. }
  13971. }
  13972. else
  13973. {
  13974. isSuccess = ConfigurationStatus_Rejected;
  13975. }
  13976. }
  13977. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13978. {
  13979. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13980. {
  13981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13982. isSuccess = ConfigurationStatus_Accepted;
  13983. }
  13984. else
  13985. {
  13986. isSuccess = ConfigurationStatus_Rejected;
  13987. }
  13988. }
  13989. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13990. {
  13991. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13992. {
  13993. check_ascii = value[0];
  13994. if( (check_ascii < 48) || (check_ascii > 57) )
  13995. {
  13996. isSuccess = ConfigurationStatus_Rejected;
  13997. }
  13998. else
  13999. {
  14000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14001. isSuccess = ConfigurationStatus_Accepted;
  14002. }
  14003. }
  14004. else
  14005. {
  14006. isSuccess = ConfigurationStatus_Rejected;
  14007. }
  14008. }
  14009. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14010. {
  14011. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14012. {
  14013. strcpy(str, (const char*)value);
  14014. for(int i = 0; str[i]; i++)
  14015. {
  14016. str[i] = tolower(str[i]);
  14017. }
  14018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14019. isSuccess = ConfigurationStatus_Accepted;
  14020. }
  14021. else
  14022. {
  14023. isSuccess = ConfigurationStatus_Rejected;
  14024. }
  14025. }
  14026. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14027. {
  14028. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14029. {
  14030. check_ascii = value[0];
  14031. if( (check_ascii < 48) || (check_ascii > 57) )
  14032. {
  14033. isSuccess = ConfigurationStatus_Rejected;
  14034. }
  14035. else
  14036. {
  14037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14038. isSuccess = ConfigurationStatus_Accepted;
  14039. }
  14040. }
  14041. else
  14042. {
  14043. isSuccess = ConfigurationStatus_Rejected;
  14044. }
  14045. }
  14046. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14047. return isSuccess;
  14048. }
  14049. int TransactionMessageAttemptsGet(void)
  14050. {
  14051. return TransactionMessageAttemptsValue;
  14052. }
  14053. int FirstHeartBeatResponse(void)
  14054. {
  14055. return FirstHeartBeat;
  14056. }
  14057. int TransactionMessageRetryIntervalGet(void)
  14058. {
  14059. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14060. }
  14061. int ReadHttpStatus(int sock)
  14062. {
  14063. //char c;
  14064. char buff[1024]="",*ptr=buff+1;
  14065. int bytes_received, status;
  14066. DEBUG_INFO("Begin Response ..\n");
  14067. while((bytes_received = recv(sock, ptr, 1, 0))){
  14068. if(bytes_received==-1){
  14069. perror("ReadHttpStatus");
  14070. exit(1);
  14071. }
  14072. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14073. ptr++;
  14074. }
  14075. *ptr=0;
  14076. ptr=buff+1;
  14077. sscanf(ptr,"%*s %d ", &status);
  14078. DEBUG_INFO("%s\n",ptr);
  14079. DEBUG_INFO("status=%d\n",status);
  14080. DEBUG_INFO("End Response ..\n");
  14081. return (bytes_received>0)?status:0;
  14082. }
  14083. //the only filed that it parsed is 'Content-Length'
  14084. int ParseHeader(int sock)
  14085. {
  14086. //char c;
  14087. char buff[1024]="",*ptr=buff+4;
  14088. int bytes_received;
  14089. DEBUG_INFO("Begin HEADER ..\n");
  14090. while((bytes_received = recv(sock, ptr, 1, 0))){
  14091. if(bytes_received==-1){
  14092. perror("Parse Header");
  14093. exit(1);
  14094. }
  14095. if(
  14096. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14097. (ptr[-1]=='\r') && (*ptr=='\n' )
  14098. ) break;
  14099. ptr++;
  14100. }
  14101. *ptr=0;
  14102. ptr=buff+4;
  14103. //printf("%s",ptr);
  14104. if(bytes_received){
  14105. ptr=strstr(ptr,"Content-Length:");
  14106. if(ptr){
  14107. sscanf(ptr,"%*s %d",&bytes_received);
  14108. }else
  14109. bytes_received=-1; //unknown size
  14110. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14111. }
  14112. DEBUG_INFO("End HEADER ..\n");
  14113. return bytes_received ;
  14114. }
  14115. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14116. {
  14117. int result = TRUE;
  14118. char rmFileCmd[100]={0};
  14119. char FilePath[100]={0};
  14120. char ftpbuf[200];
  14121. int systemresult;
  14122. //DEBUG_INFO("filename=%s\n",filename);
  14123. //DEBUG_INFO("url=%s\n",url);
  14124. sprintf(FilePath,"/mnt/%s",filename);
  14125. system("ping 8.8.8.8 &");
  14126. if((access(FilePath,F_OK))!=-1)
  14127. {
  14128. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14129. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14130. system(rmFileCmd);
  14131. }
  14132. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14133. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14134. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14135. systemresult = system(ftpbuf);
  14136. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14137. if(systemresult != 0)
  14138. {
  14139. DEBUG_INFO("http DownLoad error!\n");
  14140. result = FALSE;
  14141. }
  14142. system("pkill ping");
  14143. return result;
  14144. }
  14145. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14146. {
  14147. int result = TRUE;
  14148. char rmFileCmd[100]={0};
  14149. char FilePath[100]={0};
  14150. char ftpbuf[200];
  14151. int systemresult;
  14152. //char temp[100];
  14153. sprintf(FilePath,"/mnt/%s",filename);
  14154. system("ping 8.8.8.8 &");
  14155. if((access(FilePath,F_OK))!=-1)
  14156. {
  14157. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14158. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14159. system(rmFileCmd);
  14160. }
  14161. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14162. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14163. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14164. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14165. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14166. systemresult = system(ftpbuf);
  14167. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14168. if(systemresult != 0)
  14169. {
  14170. printf("wget error!\n");
  14171. result = FALSE;
  14172. }
  14173. system("pkill ping");
  14174. return result;
  14175. }
  14176. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14177. {
  14178. char rmFileCmd[100]={0};
  14179. char FilePath[100]={0};
  14180. char buf[512];
  14181. int systemresult = 0;
  14182. //DEBUG_INFO("filename=%s\n",filename);
  14183. //DEBUG_INFO("url=%s\n",url);
  14184. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14185. if((access(FilePath,F_OK))!=-1)
  14186. {
  14187. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14188. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14189. system(rmFileCmd);
  14190. }
  14191. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14192. if(fp == NULL)
  14193. {
  14194. DEBUG_INFO("log is NULL\n");
  14195. return FALSE;
  14196. }
  14197. else
  14198. {
  14199. fprintf(fp, "%s\n", url);
  14200. fprintf(fp, "%s\n", filename);
  14201. fclose(fp);
  14202. }
  14203. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14204. if(phpFP == NULL)
  14205. {
  14206. DEBUG_INFO("PHP upload fail.\n");
  14207. return FALSE;
  14208. }
  14209. else
  14210. {
  14211. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14212. {
  14213. if(strstr(buf, "result") != NULL)
  14214. {
  14215. sscanf(buf, "result: %d", &systemresult);
  14216. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14217. }
  14218. }
  14219. pclose(phpFP);
  14220. }
  14221. if(systemresult != 1)
  14222. {
  14223. DEBUG_INFO("HTTP upload error!\n");
  14224. return FALSE;
  14225. }
  14226. return TRUE;
  14227. }
  14228. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14229. {
  14230. struct hostent* server;
  14231. char *IPbuffer;
  14232. char ftpbuf[200];
  14233. int systemresult;
  14234. // To retrieve host information
  14235. server = gethostbyname(location);
  14236. // To convert an Internet network
  14237. // address into ASCII string
  14238. IPbuffer = inet_ntoa(*((struct in_addr*)
  14239. server->h_addr_list[0]));
  14240. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14241. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14242. /* format : ftpput -u username -p passwd IP target source*/
  14243. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14244. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14245. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14246. systemresult = system(ftpbuf);
  14247. DEBUG_INFO("systemresult=%d\n",systemresult);
  14248. if(systemresult != 0)
  14249. {
  14250. DEBUG_INFO("ftpput error!\n");
  14251. return FALSE;
  14252. }
  14253. return TRUE;
  14254. }
  14255. int GetOcppServerURL()
  14256. {
  14257. int result = FALSE;
  14258. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14259. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14260. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14261. struct yuarel url;
  14262. char urlStr[512];
  14263. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14264. {
  14265. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14266. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14267. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14268. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14269. if(yuarel_parse(&url, urlStr) != -1)
  14270. {
  14271. sprintf(OcppProtocol, "%s", url.scheme);
  14272. sprintf(OcppHost, "%s", url.host);
  14273. if(url.path == NULL)
  14274. OcppTempPath[0] = '\0';
  14275. else
  14276. {
  14277. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14278. {
  14279. sprintf(OcppTempPath, "%s/", url.path);
  14280. }
  14281. else
  14282. {
  14283. sprintf(OcppTempPath, "%s", url.path);
  14284. }
  14285. }
  14286. if(url.port == 0)
  14287. {
  14288. if(strcmp(OcppProtocol, "wss") == 0)
  14289. OcppPort = 443;
  14290. else
  14291. OcppPort = 80;
  14292. }
  14293. else
  14294. OcppPort = url.port;
  14295. result = TRUE;
  14296. }
  14297. }
  14298. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14299. {
  14300. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14301. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14302. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14303. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14304. if(yuarel_parse(&url, urlStr) != -1)
  14305. {
  14306. sprintf(OcppProtocol, "%s", url.scheme);
  14307. sprintf(OcppHost, "%s", url.host);
  14308. if(url.path == NULL)
  14309. OcppTempPath[0] = '\0';
  14310. else
  14311. sprintf(OcppTempPath, "%s", url.path);
  14312. if(url.port == 0)
  14313. {
  14314. if(strcmp(OcppProtocol, "wss") == 0)
  14315. OcppPort = 443;
  14316. else
  14317. OcppPort = 80;
  14318. }
  14319. else
  14320. OcppPort = url.port;
  14321. result = TRUE;
  14322. }
  14323. }
  14324. else
  14325. {
  14326. strcpy(OcppHost,"");
  14327. }
  14328. return result;
  14329. }
  14330. int GetOcppPath()
  14331. {
  14332. int result = FALSE;
  14333. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14334. {
  14335. if(OcppTempPath == NULL)
  14336. {
  14337. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14338. }
  14339. else
  14340. {
  14341. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14342. }
  14343. result = TRUE;
  14344. goto End;
  14345. }
  14346. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14347. {
  14348. if(OcppTempPath == NULL)
  14349. {
  14350. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14351. }
  14352. else
  14353. {
  14354. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14355. }
  14356. result = TRUE;
  14357. goto End;
  14358. }
  14359. else
  14360. {
  14361. strcpy(OcppPath,"");
  14362. }
  14363. End:
  14364. return result;
  14365. }
  14366. int GetOcppPort()
  14367. {
  14368. return OcppPort;
  14369. }
  14370. int GetOcppConnStatus(void)
  14371. {
  14372. return ShmOCPP16Data->OcppConnStatus;
  14373. }
  14374. void SetOcppConnStatus(uint8_t status)
  14375. {
  14376. ShmOCPP16Data->OcppConnStatus = status;
  14377. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14378. }
  14379. int GetHeartBeatWithNOResponse(void)
  14380. {
  14381. return HeartBeatWithNOResponse;
  14382. }
  14383. void SetHeartBeatWithNOResponse(void)
  14384. {
  14385. HeartBeatWithNOResponse = 0;
  14386. }
  14387. void GetStartTransactionIdTag(int gun_index)
  14388. {
  14389. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14390. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14391. }
  14392. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14393. {
  14394. char ch;
  14395. FILE *fptr1;
  14396. int temptransactionId;
  14397. char str[100]={0};
  14398. temptransactionId = 0;
  14399. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14400. {
  14401. DEBUG_INFO("IdTag is empty.\n");
  14402. return temptransactionId;
  14403. }
  14404. /*------ Read the file ----------------*/
  14405. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14406. if (!fptr1)
  14407. {
  14408. DEBUG_INFO("QueueTransactionId file open error.\n");
  14409. //printf(" File not found or unable to open the input file!!\n");
  14410. return temptransactionId;
  14411. }
  14412. ch=fgetc(fptr1);
  14413. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14414. rewind(fptr1);
  14415. if(ch!=EOF)
  14416. {
  14417. // printf("%c",ch);
  14418. while (fgets(str, 100, fptr1) != NULL)
  14419. {
  14420. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14421. if(str[0]=='\0')
  14422. {
  14423. break;
  14424. }
  14425. char *revbuf[8] = {0}; // Variable store string split
  14426. int num = 0;// Quantity after string split
  14427. DEBUG_INFO("Transaction queue data= %s\n", str);
  14428. splitstring(str,",",revbuf,&num); // String split
  14429. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14430. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14431. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14432. DEBUG_INFO("------------------------------\n");
  14433. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14434. {
  14435. if(isStopTransaction)
  14436. {
  14437. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14438. {
  14439. temptransactionId = atoi(revbuf[2]);
  14440. //break;
  14441. }
  14442. }
  14443. else
  14444. {
  14445. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14446. {
  14447. temptransactionId = atoi(revbuf[2]);
  14448. //break;
  14449. }
  14450. }
  14451. }
  14452. }
  14453. }
  14454. else
  14455. DEBUG_INFO("EOF\n");
  14456. fclose(fptr1);
  14457. /*------- End of reading ---------------*/
  14458. return temptransactionId;
  14459. }
  14460. void SetTransactionIdZero(int transactionId)
  14461. {
  14462. char ch;
  14463. FILE *fptr1, *fptr2;
  14464. int temptransactionId = 0;
  14465. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14466. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14467. if (!fptr1)
  14468. {
  14469. //printf(" File not found or unable to open the input file!!\n");
  14470. return ;
  14471. }
  14472. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14473. if (!fptr2)
  14474. {
  14475. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14476. fclose(fptr1);
  14477. return ;
  14478. }
  14479. ch=fgetc(fptr1);
  14480. rewind(fptr1);
  14481. if(ch!=EOF)
  14482. {
  14483. // copy all contents to the temporary file except the specific line
  14484. while (fgets(str, 100, fptr1) != NULL)
  14485. {
  14486. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14487. if(str[0]=='\0')
  14488. {
  14489. break;
  14490. }
  14491. char *revbuf[8] = {0};
  14492. int num = 0;
  14493. strcpy(strtemp, str);
  14494. splitstring(str,",",revbuf,&num);
  14495. if(revbuf[2][0] != '\0')
  14496. {
  14497. temptransactionId = atoi(revbuf[2]);
  14498. if(transactionId != temptransactionId)
  14499. {
  14500. fprintf(fptr2, "%s\n", strtemp);
  14501. }
  14502. }
  14503. }
  14504. }
  14505. fclose(fptr1);
  14506. fclose(fptr2);
  14507. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14508. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14509. /*------ Read the file ----------------*/
  14510. }
  14511. int InternetDisconnect(void)
  14512. {
  14513. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14514. }
  14515. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14516. void storeTempStopTransaction(int gun_index)
  14517. {
  14518. char guid[37]={0};
  14519. int tempIndex = 0;
  14520. char TempStopTransaction[256];
  14521. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14522. DEBUG_INFO("storeTempStopTransaction...\n");
  14523. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14524. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14525. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14526. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14527. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14528. {
  14529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14530. {
  14531. tempIndex = ((gun_index==2) ? 1: 0);
  14532. }
  14533. else
  14534. {
  14535. tempIndex = gun_index;
  14536. }
  14537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14538. {
  14539. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14540. {
  14541. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14542. }
  14543. }// END OF CHAdeMO_QUANTITY
  14544. }
  14545. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14546. {
  14547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14548. {
  14549. tempIndex = ((gun_index==2) ? 1: 0);
  14550. }
  14551. else
  14552. {
  14553. tempIndex = gun_index;
  14554. }
  14555. for (int index = 0; index < CCS_QUANTITY; index++)
  14556. {
  14557. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14558. {
  14559. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14560. }
  14561. }// END OF CCS_QUANTITY
  14562. }
  14563. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14564. {
  14565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14566. {
  14567. tempIndex = ((gun_index==2) ? 1: 0);
  14568. }
  14569. else
  14570. {
  14571. tempIndex = gun_index;
  14572. }
  14573. for (int index = 0; index < GB_QUANTITY; index++)
  14574. {
  14575. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14576. {
  14577. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14578. }
  14579. }// END OF GB_QUANTITY
  14580. }
  14581. else if(gunType[gun_index] == GUN_TYPE_DO)
  14582. {
  14583. tempIndex = gun_index;
  14584. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14585. {
  14586. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14587. {
  14588. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14589. }
  14590. }
  14591. }
  14592. else
  14593. {
  14594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14595. {
  14596. tempIndex = 2;
  14597. }
  14598. else
  14599. {
  14600. tempIndex = gun_index;
  14601. }
  14602. for (int index = 0; index < AC_QUANTITY; index++)
  14603. {
  14604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14605. {
  14606. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14607. }
  14608. }// END OF AC_QUANTITY
  14609. }
  14610. //Stop Transaction Time
  14611. struct timeval tmnow;
  14612. struct tm *tm;
  14613. char buf[28];//, usec_buf[6];
  14614. gettimeofday(&tmnow, NULL);
  14615. time_t t;
  14616. t = time(NULL);
  14617. /*UTC time and date*/
  14618. tm = gmtime(&t);
  14619. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14621. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14623. random_uuid(guid);
  14624. /***********************************transactionData******************************************************/
  14625. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14627. //=================================
  14628. //1. Transaction_Begin
  14629. //=================================
  14630. //============================== Energy.Active.Import.Interval ===========================================
  14631. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14632. {
  14633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14636. 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*/]);
  14637. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14638. 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))
  14639. {
  14640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14641. }
  14642. else
  14643. {
  14644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14645. }
  14646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14648. }
  14649. //=================================
  14650. //2. Transaction_End
  14651. //=================================
  14652. //2.1====================================== Current.Import L1 ==============================================
  14653. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14654. {
  14655. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14656. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14657. {
  14658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14659. {
  14660. tempIndex = ((gun_index==2) ? 1: 0);
  14661. }
  14662. else
  14663. {
  14664. tempIndex = gun_index;
  14665. }
  14666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14667. {
  14668. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14669. {
  14670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14671. }
  14672. }// End of for CHAdeMO_QUANTITY
  14673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14674. }
  14675. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14676. {
  14677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14678. {
  14679. tempIndex = ((gun_index==2) ? 1: 0);
  14680. }
  14681. else
  14682. {
  14683. tempIndex = gun_index;
  14684. }
  14685. for (int index = 0; index < CCS_QUANTITY; index++)
  14686. {
  14687. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14688. {
  14689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14690. }
  14691. }// End of for CCS_QUANTITY
  14692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14693. }
  14694. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14695. {
  14696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14697. {
  14698. tempIndex = ((gun_index==2) ? 1: 0);
  14699. }
  14700. else
  14701. {
  14702. tempIndex = gun_index;
  14703. }
  14704. for (int index = 0; index < GB_QUANTITY; index++)
  14705. {
  14706. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14707. {
  14708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14709. }
  14710. }// End of for GB_QUANTITY
  14711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14712. }
  14713. else if(gunType[gun_index] == GUN_TYPE_DO)
  14714. {
  14715. tempIndex = gun_index;
  14716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14717. {
  14718. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14721. }
  14722. }
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14724. }
  14725. else
  14726. {
  14727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14728. {
  14729. tempIndex = 2;
  14730. }
  14731. else
  14732. {
  14733. tempIndex = gun_index;
  14734. }
  14735. for (int index = 0; index < AC_QUANTITY; index++)
  14736. {
  14737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14738. {
  14739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14740. }
  14741. }// End of for AC_QUANTITY
  14742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14743. }
  14744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14747. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14750. }
  14751. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14752. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14753. {
  14754. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14755. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14756. {
  14757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14758. {
  14759. tempIndex = ((gun_index==2) ? 1: 0);
  14760. }
  14761. else
  14762. {
  14763. tempIndex = gun_index;
  14764. }
  14765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14766. {
  14767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14768. {
  14769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14770. }
  14771. }// END OF CHAdeMO_QUANTITY
  14772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14773. }
  14774. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14775. {
  14776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14777. {
  14778. tempIndex = ((gun_index==2) ? 1: 0);
  14779. }
  14780. else
  14781. {
  14782. tempIndex = gun_index;
  14783. }
  14784. for (int index = 0; index < CCS_QUANTITY; index++)
  14785. {
  14786. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14787. {
  14788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14789. }
  14790. }// END OF CCS_QUANTITY
  14791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14792. }
  14793. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14794. {
  14795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14796. {
  14797. tempIndex = ((gun_index==2) ? 1: 0);
  14798. }
  14799. else
  14800. {
  14801. tempIndex = gun_index;
  14802. }
  14803. for (int index = 0; index < GB_QUANTITY; index++)
  14804. {
  14805. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14806. {
  14807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14808. }
  14809. }// END OF GB_QUANTITY
  14810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14811. }
  14812. else if(gunType[gun_index] == GUN_TYPE_DO)
  14813. {
  14814. tempIndex = gun_index;
  14815. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14816. {
  14817. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14818. {
  14819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14820. }
  14821. }
  14822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14823. }
  14824. else
  14825. {
  14826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14827. {
  14828. tempIndex = 2;
  14829. }
  14830. else
  14831. {
  14832. tempIndex = gun_index;
  14833. }
  14834. for (int index = 0; index < AC_QUANTITY; index++)
  14835. {
  14836. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14837. {
  14838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14839. }
  14840. }// END OF AC_QUANTITY
  14841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14842. }
  14843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14846. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14849. }
  14850. //2.3====================================== Power.Active.Import =========================================
  14851. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14852. {
  14853. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14855. {
  14856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14857. {
  14858. tempIndex = ((gun_index==2) ? 1: 0);
  14859. }
  14860. else
  14861. {
  14862. tempIndex = gun_index;
  14863. }
  14864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14865. {
  14866. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14867. {
  14868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14869. }
  14870. } // End for CHAdeMO_QUANTITY
  14871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14872. }
  14873. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14874. {
  14875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14876. {
  14877. tempIndex = ((gun_index==2) ? 1: 0);
  14878. }
  14879. else
  14880. {
  14881. tempIndex = gun_index;
  14882. }
  14883. for (int index = 0; index < CCS_QUANTITY; index++)
  14884. {
  14885. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14888. }
  14889. } // END for CCS_QUANTITY
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14891. }
  14892. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14893. {
  14894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14895. {
  14896. tempIndex = ((gun_index==2) ? 1: 0);
  14897. }
  14898. else
  14899. {
  14900. tempIndex = gun_index;
  14901. }
  14902. for (int index = 0; index < GB_QUANTITY; index++)
  14903. {
  14904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14905. {
  14906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14907. }
  14908. }// END for GB_QUANTITY
  14909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14910. }
  14911. else if(gunType[gun_index] == GUN_TYPE_DO)
  14912. {
  14913. tempIndex = gun_index;
  14914. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14915. {
  14916. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14917. {
  14918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14919. }
  14920. }
  14921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14922. }
  14923. else
  14924. {
  14925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14926. {
  14927. tempIndex = 2;
  14928. }
  14929. else
  14930. {
  14931. tempIndex = gun_index;
  14932. }
  14933. for (int index = 0; index < AC_QUANTITY; index++)
  14934. {
  14935. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14936. {
  14937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14938. }
  14939. } // END for AC_QUANTITY
  14940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14941. }
  14942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14945. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14948. }
  14949. //2.4====================================== Voltage L1 ====================================================
  14950. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14951. {
  14952. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14953. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14954. {
  14955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14956. {
  14957. tempIndex = ((gun_index==2) ? 1: 0);
  14958. }
  14959. else
  14960. {
  14961. tempIndex = gun_index;
  14962. }
  14963. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14964. {
  14965. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14966. {
  14967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14968. }
  14969. } // END OF FOR CHAdeMO_QUANTITY
  14970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14971. }
  14972. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14973. {
  14974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14975. {
  14976. tempIndex = ((gun_index==2) ? 1: 0);
  14977. }
  14978. else
  14979. {
  14980. tempIndex = gun_index;
  14981. }
  14982. for (int index = 0; index < CCS_QUANTITY; index++)
  14983. {
  14984. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14985. {
  14986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14987. }
  14988. } // END OF FOR CCS_QUANTITY
  14989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14990. }
  14991. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14992. {
  14993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14994. {
  14995. tempIndex = ((gun_index==2) ? 1: 0);
  14996. }
  14997. else
  14998. {
  14999. tempIndex = gun_index;
  15000. }
  15001. for (int index = 0; index < GB_QUANTITY; index++)
  15002. {
  15003. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15004. {
  15005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15006. }
  15007. } // END OF FOR GB_QUANTITY
  15008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15009. }
  15010. else if(gunType[gun_index] == GUN_TYPE_DO)
  15011. {
  15012. tempIndex = gun_index;
  15013. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15014. {
  15015. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15016. {
  15017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15018. }
  15019. }
  15020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15021. }
  15022. else
  15023. {
  15024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15025. {
  15026. tempIndex = 2;
  15027. }
  15028. else
  15029. {
  15030. tempIndex = gun_index;
  15031. }
  15032. for (int index = 0; index < AC_QUANTITY; index++)
  15033. {
  15034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15035. {
  15036. 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
  15037. }
  15038. } // END OF FOR AC_QUANTITY
  15039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15040. }
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15044. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15047. }
  15048. //2.5============================================== End SoC =========================================================
  15049. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15050. {
  15051. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15052. 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))
  15053. {
  15054. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15055. {
  15056. tempIndex = ((gun_index==2) ? 1: 0);
  15057. }
  15058. else
  15059. {
  15060. tempIndex = gun_index;
  15061. }
  15062. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15063. {
  15064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15065. {
  15066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15067. {
  15068. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15069. }
  15070. }
  15071. }
  15072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15073. {
  15074. for (int index = 0; index < CCS_QUANTITY; index++)
  15075. {
  15076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15077. {
  15078. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15079. }
  15080. }
  15081. }
  15082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15083. {
  15084. for (int index = 0; index < GB_QUANTITY; index++)
  15085. {
  15086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15087. {
  15088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15089. }
  15090. }
  15091. }
  15092. else if(gunType[gun_index] == GUN_TYPE_DO)
  15093. {
  15094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15095. {
  15096. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15097. {
  15098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15099. }
  15100. }
  15101. }
  15102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15108. } // END FOR DC CASE
  15109. }
  15110. //2.6====================================== Current.Import L2 ==============================================
  15111. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15112. {
  15113. // AC 3 phase L2 current
  15114. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15115. {
  15116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15117. {
  15118. tempIndex = 2;
  15119. }
  15120. else
  15121. {
  15122. tempIndex = gun_index;
  15123. }
  15124. for (int index = 0; index < AC_QUANTITY; index++)
  15125. {
  15126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15127. {
  15128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15129. }
  15130. }// End of for AC_QUANTITY
  15131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15132. }
  15133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15138. }
  15139. //2.7====================================== Current.Import L3 ==============================================
  15140. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15141. {
  15142. // AC 3 phase L3 current
  15143. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15144. {
  15145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15146. {
  15147. tempIndex = 2;
  15148. }
  15149. else
  15150. {
  15151. tempIndex = gun_index;
  15152. }
  15153. for (int index = 0; index < AC_QUANTITY; index++)
  15154. {
  15155. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15156. {
  15157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15158. }
  15159. }// End of for AC_QUANTITY
  15160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15161. }
  15162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15167. }
  15168. //2.9====================================== Voltage L2 ====================================================
  15169. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15170. {
  15171. // AC 3 phase L2 volatge
  15172. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15173. {
  15174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15175. {
  15176. tempIndex = 2;
  15177. }
  15178. else
  15179. {
  15180. tempIndex = gun_index;
  15181. }
  15182. for (int index = 0; index < AC_QUANTITY; index++)
  15183. {
  15184. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15185. {
  15186. 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
  15187. }
  15188. } // END OF FOR AC_QUANTITY
  15189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15190. }
  15191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15196. }
  15197. //2.10====================================== Voltage L3 ====================================================
  15198. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15199. {
  15200. // AC 3 phase L3 volatge
  15201. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15202. {
  15203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15204. {
  15205. tempIndex = 2;
  15206. }
  15207. else
  15208. {
  15209. tempIndex = gun_index;
  15210. }
  15211. for (int index = 0; index < AC_QUANTITY; index++)
  15212. {
  15213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15214. {
  15215. 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
  15216. }
  15217. } // END OF FOR AC_QUANTITY
  15218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15219. }
  15220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15225. }
  15226. //====================== Start SoC ================================
  15227. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15228. {
  15229. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15230. 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))
  15231. {
  15232. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15233. {
  15234. tempIndex = ((gun_index==2) ? 1: 0);
  15235. }
  15236. else
  15237. {
  15238. tempIndex = gun_index;
  15239. }
  15240. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15241. {
  15242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15243. {
  15244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15245. {
  15246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15247. }
  15248. }
  15249. }
  15250. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15251. {
  15252. for (int index = 0; index < CCS_QUANTITY; index++)
  15253. {
  15254. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15255. {
  15256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15257. }
  15258. }
  15259. }
  15260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15261. {
  15262. for (int index = 0; index < GB_QUANTITY; index++)
  15263. {
  15264. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15265. {
  15266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15267. }
  15268. }
  15269. }
  15270. else if(gunType[gun_index] == GUN_TYPE_DO)
  15271. {
  15272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15273. {
  15274. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15275. {
  15276. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15277. }
  15278. }
  15279. }
  15280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15286. } // END FOR DC CASE
  15287. }
  15288. //======================================== Message create ==============================================
  15289. json_object *StopTransaction = json_object_new_object();
  15290. json_object *transactionDatas = json_object_new_array();
  15291. json_object *sampledValues = json_object_new_array();
  15292. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15293. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15294. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15295. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15296. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15297. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15298. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15299. {
  15300. json_object *transactionData = json_object_new_object();
  15301. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15302. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15303. {
  15304. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15305. {
  15306. json_object *sampledValue = json_object_new_object();
  15307. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15308. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15309. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15310. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15311. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15312. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15313. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15314. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15315. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15316. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15317. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15318. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15319. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15320. json_object_array_add(sampledValues, sampledValue);
  15321. }
  15322. }
  15323. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15324. json_object_array_add(transactionDatas, transactionData);
  15325. }
  15326. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15327. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15328. ,MESSAGE_TYPE_CALL
  15329. ,guid
  15330. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15331. json_object_put(StopTransaction);
  15332. // Check File "TempStopTransaction" Exist
  15333. if((access(TempStopTransaction,F_OK))!=-1)
  15334. {
  15335. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15336. fclose(fopen(TempStopTransaction, "w"));
  15337. }
  15338. else
  15339. {
  15340. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15341. FILE *log = fopen(TempStopTransaction, "w+");
  15342. if(log == NULL)
  15343. {
  15344. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15345. return ;
  15346. }
  15347. else
  15348. {
  15349. fclose(log);
  15350. }
  15351. }
  15352. //Add TempStopTransaction | Update TempStopTransaction
  15353. // open file for writing
  15354. FILE *outfile;
  15355. outfile = fopen (TempStopTransaction, "a");
  15356. //DEBUG_INFO("data = %s\n", queuedata);
  15357. fputs(queuedata, outfile);
  15358. fputs("\n", outfile);
  15359. fclose (outfile);
  15360. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15361. }
  15362. void checkTempStopTransaction(int gun_index)
  15363. {
  15364. FILE *fptr1;
  15365. char ch;
  15366. char str[QUEUE_MESSAGE_LENGTH]={0};
  15367. char guid[37]={0};
  15368. char tempdata[65]={0};
  15369. char connectorStr[2]={0};
  15370. char TempStopTransaction[256];
  15371. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15372. fptr1 = fopen(TempStopTransaction, "r");
  15373. //TempStopTransaction格式: 槍號,StopTransaction封包
  15374. if (!fptr1)
  15375. {
  15376. //printf(" File not found or unable to open the input file!!\n");
  15377. return ;
  15378. }
  15379. ch=fgetc(fptr1);
  15380. //printf(" Now the content of the file %s is : \n",fname);
  15381. rewind(fptr1);
  15382. if(ch!=EOF)
  15383. {
  15384. // copy all contents to the temporary file except the specific line
  15385. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15386. {
  15387. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15388. if(str[0]=='\0')
  15389. {
  15390. break;
  15391. }
  15392. //TempStopTransaction格式: 槍號,StopTransaction封包
  15393. strncpy(connectorStr, str, 1);
  15394. if(atoi(connectorStr) != (gun_index+1))
  15395. {
  15396. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15397. fclose(fptr1);
  15398. return ;
  15399. }
  15400. //random_uuid(guid);
  15401. strncpy(guid, str+6, 36); //copy guid
  15402. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15403. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15404. {
  15405. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15406. }
  15407. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15408. OCPP_insert_transaction_msg(NO, str);
  15409. memset(str,0,ARRAY_SIZE(str));
  15410. }
  15411. }
  15412. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15413. fclose(fptr1);
  15414. remove(TempStopTransaction); // remove the original file
  15415. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15416. }
  15417. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15418. {
  15419. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15420. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15421. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15422. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15423. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15424. }
  15425. int GetWebSocketPingInterval(void)
  15426. {
  15427. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15428. }
  15429. int GetServerSign(void)
  15430. {
  15431. return server_sign;
  15432. }
  15433. uint8_t GetOcppSecurityProfile()
  15434. {
  15435. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15436. }
  15437. void GetOcppChargerBoxId(uint8_t *data)
  15438. {
  15439. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15440. }
  15441. void GetOcppSecurityPassword(uint8_t *data)
  15442. {
  15443. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15444. }
  15445. void SetOcppVersion(uint8_t *version)
  15446. {
  15447. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15448. DEBUG_INFO("ocpp version: %s\n", version);
  15449. if(strstr((char*)version, "ocpp1.6") != NULL)
  15450. {
  15451. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15452. }
  15453. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15454. {
  15455. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15456. system("pkill OcppBackend");
  15457. }
  15458. }
  15459. void SetServerSign(int value)
  15460. {
  15461. server_sign = value;
  15462. }
  15463. int GetBootNotificationInterval(void)
  15464. {
  15465. return BootNotificationInterval;
  15466. }
  15467. int GetInternetConn(void)
  15468. {
  15469. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15470. }
  15471. int GetBackendConnectionTimeout(void)
  15472. {
  15473. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15474. }
  15475. int isConnectorInitMode(int gun_index)
  15476. {
  15477. int tempIndex = 0;
  15478. int result = TRUE;
  15479. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15480. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15481. {
  15482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15483. {
  15484. tempIndex = ((gun_index==2) ? 1: 0);
  15485. }
  15486. else
  15487. {
  15488. tempIndex = gun_index;
  15489. }
  15490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15491. {
  15492. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15493. {
  15494. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15495. } //end of the same index
  15496. }//end of for CHAdeMO_QUANTITY
  15497. }
  15498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15499. {
  15500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15501. {
  15502. tempIndex = ((gun_index==2) ? 1: 0);
  15503. }
  15504. else
  15505. {
  15506. tempIndex = gun_index;
  15507. }
  15508. for (int index = 0; index < CCS_QUANTITY; index++)
  15509. {
  15510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15511. {
  15512. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15513. } //end of the same index
  15514. } // end of for CCS_QUANTITY
  15515. }
  15516. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15517. {
  15518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15519. {
  15520. tempIndex = ((gun_index==2) ? 1: 0);
  15521. }
  15522. else
  15523. {
  15524. tempIndex = gun_index;
  15525. }
  15526. for (int index = 0; index < GB_QUANTITY; index++)
  15527. {
  15528. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15529. {
  15530. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15531. } //end of the same index
  15532. } // end of for GB_QUANTITY
  15533. }
  15534. else if(gunType[gun_index] == GUN_TYPE_DO)
  15535. {
  15536. tempIndex = gun_index;
  15537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15538. {
  15539. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15540. {
  15541. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15542. } //end of the same index
  15543. }
  15544. }
  15545. else
  15546. {
  15547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15548. {
  15549. tempIndex = 2;
  15550. }
  15551. else
  15552. {
  15553. tempIndex = gun_index;
  15554. }
  15555. for (int index = 0; index < AC_QUANTITY; index++)
  15556. {
  15557. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15558. {
  15559. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15560. }//end of the same index
  15561. }//end of for AC_QUANTITY
  15562. }
  15563. return result;
  15564. }
  15565. void refreshProcDogTimer()
  15566. {
  15567. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15568. }
  15569. void InitialSystemValue(void)
  15570. {
  15571. int connectorIndex = 0;
  15572. //int valueASCII = 0;
  15573. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15574. gunTotalNumber=0;
  15575. SystemInitial = 0;
  15576. locallistVersion=0;
  15577. BootNotificationInterval = 0;
  15578. authorizeRetryTimes = 0;
  15579. GunStatusInterval = 10;
  15580. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15581. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15582. //Hear Beat
  15583. HeartBeatWithNOResponse = 0;
  15584. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15585. FirstHeartBeat = 0;
  15586. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15587. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15588. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15589. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15590. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15591. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15592. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15593. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15594. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15595. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15596. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15597. memset(gunType, 0, ARRAY_SIZE(gunType));
  15598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15599. {
  15600. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15601. {
  15602. // DO series
  15603. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15604. {
  15605. SystemInitial = SystemInitial + 1;
  15606. gunTotalNumber = gunTotalNumber + 1;
  15607. gunType[connectorIndex] = GUN_TYPE_DO;
  15608. connectorIndex = connectorIndex + 1;
  15609. }
  15610. }
  15611. else
  15612. {
  15613. // DM, DW, DS series
  15614. //check connector / socket type (index: 8, 9, 10)
  15615. for(int index=7; index <10 ; index++)
  15616. {
  15617. if(index != 8)
  15618. {
  15619. // DC Connector
  15620. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15621. {
  15622. SystemInitial = SystemInitial + 1;
  15623. gunTotalNumber = gunTotalNumber + 1;
  15624. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15625. connectorIndex = connectorIndex + 1;
  15626. }
  15627. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15628. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15629. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15630. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15631. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15632. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15633. {
  15634. SystemInitial = SystemInitial + 1;
  15635. gunTotalNumber = gunTotalNumber + 1;
  15636. gunType[connectorIndex] = GUN_TYPE_CCS;
  15637. connectorIndex = connectorIndex + 1;
  15638. }
  15639. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15640. {
  15641. SystemInitial = SystemInitial + 1;
  15642. gunTotalNumber = gunTotalNumber + 1;
  15643. gunType[connectorIndex] = GUN_TYPE_GBT;
  15644. connectorIndex = connectorIndex + 1;
  15645. }
  15646. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15647. {
  15648. SystemInitial = SystemInitial + 1;
  15649. gunTotalNumber = gunTotalNumber + 1;
  15650. gunType[connectorIndex] = GUN_TYPE_DO;
  15651. connectorIndex = connectorIndex + 1;
  15652. }
  15653. }
  15654. else
  15655. {
  15656. // AC Connector
  15657. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15658. {
  15659. SystemInitial = SystemInitial + 1;
  15660. gunTotalNumber = gunTotalNumber + 1;
  15661. gunType[connectorIndex] = GUN_TYPE_AC;
  15662. connectorIndex = connectorIndex + 1;
  15663. }
  15664. }
  15665. }
  15666. }
  15667. //DEBUG_INFO("DC ...\n");
  15668. }
  15669. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15670. {
  15671. //check connector / socket type (index: 8, 9, 10)
  15672. for(int index=7; index <10 ; index++)
  15673. {
  15674. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15675. {
  15676. SystemInitial = SystemInitial + 1;
  15677. gunTotalNumber = gunTotalNumber + 1;
  15678. gunType[connectorIndex] = GUN_TYPE_AC;
  15679. connectorIndex = connectorIndex + 1;
  15680. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15681. }
  15682. }
  15683. }
  15684. //Status && ConnectorPlugIn Setting
  15685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15686. {
  15687. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15688. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15689. }
  15690. for (int index = 0; index < CCS_QUANTITY; index++)
  15691. {
  15692. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15693. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15694. }
  15695. for (int index = 0; index < GB_QUANTITY; index++)
  15696. {
  15697. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15698. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15699. }
  15700. for (int index = 0; index < AC_QUANTITY; index++)
  15701. {
  15702. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15703. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15704. }
  15705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15706. {
  15707. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15708. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15709. }
  15710. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15711. {
  15712. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15713. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15714. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15715. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15716. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15717. }
  15718. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15719. clientTime.Heartbeat=time((time_t*)NULL);
  15720. sleep(1);
  15721. }
  15722. void LWS_Send(char *str)
  15723. {
  15724. //=====================================================
  15725. // Check InternetConn 0: disconnected, 1: connected
  15726. //====================================================
  15727. if(GetOcppConnStatus() == 0)
  15728. {
  15729. DEBUG_INFO("offline now !!!\n");
  15730. return;
  15731. }
  15732. // Only disable isWebsocketSendable operation initiated by charger
  15733. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15734. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15735. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15736. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15737. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15738. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15739. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15740. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15741. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15742. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15743. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15744. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15745. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15746. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15747. {
  15748. isWebsocketSendable = 0;
  15749. }
  15750. pthread_mutex_lock(&lock_send);
  15751. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15752. sprintf((char *)SendBuffer, "%s", str);
  15753. SendBufLen = strlen(str);
  15754. pthread_mutex_unlock(&lock_send);
  15755. lws_callback_on_writable(wsi_client);
  15756. //lws_service(context, 0);
  15757. //sleep(1);
  15758. }
  15759. void LWS_SendNow(char *str)
  15760. {
  15761. //=====================================================
  15762. // Check InternetConn 0: disconnected, 1: connected
  15763. //====================================================
  15764. if(GetOcppConnStatus() == 0)
  15765. {
  15766. DEBUG_INFO("offline now !!!\n");
  15767. return;
  15768. }
  15769. // Only disable isWebsocketSendable operation initiated by charger
  15770. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15771. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15772. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15773. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15774. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15775. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15776. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15777. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15778. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15779. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15780. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15781. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15782. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15783. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15784. {
  15785. isWebsocketSendable = 0;
  15786. }
  15787. pthread_mutex_lock(&lock_send);
  15788. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15789. sprintf((char *)SendBuffer, "%s", str);
  15790. SendBufLen = strlen(str);
  15791. pthread_mutex_unlock(&lock_send);
  15792. lws_callback_on_writable(wsi_client);
  15793. lws_service(context, 0);
  15794. //sleep(1);
  15795. }