MessageHandler.c 773 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180
  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 localversion=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 statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~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. localversion = argv[5] ? atoi(argv[5]) : 0;
  444. //printf("localversion=%d\n", localversion);
  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()
  679. {
  680. int result = -1;
  681. static time_t lastTime;
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime)>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 = 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. statusModeChage[gun_index] = TRUE;
  2642. }
  2643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2644. {
  2645. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2646. if((access(filenmae,F_OK))!=-1)
  2647. {
  2648. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2649. sprintf(str,"rm -f %s",filenmae);
  2650. system(str);
  2651. }
  2652. }
  2653. #if 1 // for TempStopTransaction
  2654. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2655. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2656. {
  2657. checkTempStopTransaction(gun_index);
  2658. }
  2659. #endif
  2660. }
  2661. }
  2662. }
  2663. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2664. {
  2665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2666. {
  2667. tempIndex = ((gun_index==2) ? 1: 0);
  2668. }
  2669. else
  2670. {
  2671. tempIndex = gun_index;
  2672. }
  2673. for (int index = 0; index < CCS_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2676. {
  2677. 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]*/ )
  2678. {
  2679. // Sent unplug message for California pricing logic
  2680. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2681. {
  2682. uint8_t ts[20];
  2683. getNowDatetime(ts);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2686. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2687. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2688. }
  2689. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2690. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2692. statusModeChage[gun_index] = TRUE;
  2693. }
  2694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2695. {
  2696. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2697. if((access(filenmae,F_OK))!=-1)
  2698. {
  2699. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2700. sprintf(str,"rm -f %s",filenmae);
  2701. system(str);
  2702. }
  2703. }
  2704. #if 1 // for TempStopTransaction
  2705. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2706. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2707. {
  2708. checkTempStopTransaction(gun_index);
  2709. }
  2710. #endif
  2711. }
  2712. }
  2713. }
  2714. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2715. {
  2716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2717. {
  2718. tempIndex = ((gun_index==2) ? 1: 0);
  2719. }
  2720. else
  2721. {
  2722. tempIndex = gun_index;
  2723. }
  2724. for (int index = 0; index < GB_QUANTITY; index++)
  2725. {
  2726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2727. {
  2728. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2729. {
  2730. // Sent unplug message for California pricing logic
  2731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2732. {
  2733. uint8_t ts[20];
  2734. getNowDatetime(ts);
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2736. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2737. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2738. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2739. }
  2740. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2741. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2742. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2743. statusModeChage[gun_index] = TRUE;
  2744. }
  2745. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2746. {
  2747. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2748. if((access(filenmae,F_OK))!=-1)
  2749. {
  2750. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2751. sprintf(str,"rm -f %s",filenmae);
  2752. system(str);
  2753. }
  2754. }
  2755. #if 1 // for TempStopTransaction
  2756. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2757. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2758. {
  2759. checkTempStopTransaction(gun_index);
  2760. }
  2761. #endif
  2762. }
  2763. }
  2764. }
  2765. else if(gunType[gun_index] == GUN_TYPE_DO)
  2766. {
  2767. tempIndex = gun_index;
  2768. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2769. {
  2770. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2771. {
  2772. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2773. {
  2774. // Sent unplug message for California pricing logic
  2775. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2776. {
  2777. uint8_t ts[20];
  2778. getNowDatetime(ts);
  2779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2780. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2782. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2783. }
  2784. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2785. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2786. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2787. statusModeChage[gun_index] = TRUE;
  2788. }
  2789. 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
  2790. {
  2791. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2792. if((access(filenmae,F_OK))!=-1)
  2793. {
  2794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2795. sprintf(str,"rm -f %s",filenmae);
  2796. system(str);
  2797. }
  2798. }
  2799. #if 1 // for TempStopTransaction
  2800. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2801. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2802. {
  2803. checkTempStopTransaction(gun_index);
  2804. }
  2805. #endif
  2806. }
  2807. }
  2808. }
  2809. else
  2810. {
  2811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2812. {
  2813. tempIndex = 2;
  2814. }
  2815. else
  2816. {
  2817. tempIndex = gun_index;
  2818. }
  2819. for (int index = 0; index < AC_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2822. {
  2823. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2824. {
  2825. // Sent unplug message for California pricing logic
  2826. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2827. {
  2828. uint8_t ts[20];
  2829. getNowDatetime(ts);
  2830. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2831. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2832. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2833. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2834. }
  2835. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2836. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2837. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2838. statusModeChage[gun_index] = TRUE;
  2839. }
  2840. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2841. {
  2842. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2843. if((access(filenmae,F_OK))!=-1)
  2844. {
  2845. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2846. sprintf(str,"rm -f %s",filenmae);
  2847. system(str);
  2848. }
  2849. }
  2850. #if 1 // for TempStopTransaction
  2851. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2852. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2853. {
  2854. checkTempStopTransaction(gun_index);
  2855. }
  2856. #endif
  2857. }
  2858. }// END
  2859. }
  2860. if(isWebsocketSendable && (server_sign == TRUE) &&
  2861. (
  2862. (statusModeChage[gun_index] == TRUE) ||
  2863. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2864. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2865. )
  2866. )
  2867. {
  2868. if(SystemInitial > 0)
  2869. SystemInitial -= 1;
  2870. sendStatusNotificationRequest(gun_index);
  2871. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2872. statusModeChage[gun_index] = FALSE;
  2873. }
  2874. //==============================================
  2875. // Meter report
  2876. //==============================================
  2877. // Trigger MeterValue
  2878. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2879. {
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2881. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2882. }
  2883. // ClockAlign MeterValue
  2884. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2885. {
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. reqClockAlignMeter[gun_index] = 1;
  2902. }
  2903. }// End for CHAdeMO
  2904. }
  2905. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2906. {
  2907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2908. {
  2909. tempIndex = ((gun_index==2) ? 1: 0);
  2910. }
  2911. else
  2912. {
  2913. tempIndex = gun_index;
  2914. }
  2915. for (int index = 0; index < CCS_QUANTITY; index++)
  2916. {
  2917. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2918. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2919. {
  2920. reqClockAlignMeter[gun_index] = 1;
  2921. }
  2922. } // End for CCS
  2923. }
  2924. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2925. {
  2926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2927. {
  2928. tempIndex = ((gun_index==2) ? 1: 0);
  2929. }
  2930. else
  2931. {
  2932. tempIndex = gun_index;
  2933. }
  2934. for (int index = 0; index < GB_QUANTITY; index++)
  2935. {
  2936. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2937. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2938. {
  2939. reqClockAlignMeter[gun_index] = 1;
  2940. }
  2941. }// End for GB
  2942. }
  2943. else if(gunType[gun_index] == GUN_TYPE_DO)
  2944. {
  2945. tempIndex = gun_index;
  2946. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2947. {
  2948. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2949. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2950. {
  2951. reqClockAlignMeter[gun_index] = 1;
  2952. }
  2953. }
  2954. }
  2955. else
  2956. {
  2957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2958. {
  2959. tempIndex = 2;
  2960. }
  2961. else
  2962. {
  2963. tempIndex = gun_index;
  2964. }
  2965. for (int index = 0; index < AC_QUANTITY; index++)
  2966. {
  2967. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2968. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2969. {
  2970. reqClockAlignMeter[gun_index] = 1;
  2971. }
  2972. }//End for AC
  2973. }
  2974. if(reqClockAlignMeter[gun_index] == 1)
  2975. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2976. }
  2977. // Sample period MeterValue
  2978. 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))))
  2979. {
  2980. //check Transaction active
  2981. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2982. {
  2983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2984. {
  2985. tempIndex = ((gun_index==2) ? 1: 0);
  2986. }
  2987. else
  2988. {
  2989. tempIndex = gun_index;
  2990. }
  2991. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2992. {
  2993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2994. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2995. {
  2996. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2997. {
  2998. reqSampleMeter[gun_index] = 1;
  2999. }
  3000. }
  3001. }// End for CHAdeMO
  3002. }
  3003. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3004. {
  3005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3006. {
  3007. tempIndex = ((gun_index==2) ? 1: 0);
  3008. }
  3009. else
  3010. {
  3011. tempIndex = gun_index;
  3012. }
  3013. for (int index = 0; index < CCS_QUANTITY; index++)
  3014. {
  3015. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3016. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3017. {
  3018. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3019. {
  3020. reqSampleMeter[gun_index] = 1;
  3021. }
  3022. }
  3023. } // End for CCS
  3024. }
  3025. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3026. {
  3027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3028. {
  3029. tempIndex = ((gun_index==2) ? 1: 0);
  3030. }
  3031. else
  3032. {
  3033. tempIndex = gun_index;
  3034. }
  3035. for (int index = 0; index < GB_QUANTITY; index++)
  3036. {
  3037. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3038. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3039. {
  3040. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3041. {
  3042. reqSampleMeter[gun_index] = 1;
  3043. }
  3044. }
  3045. }// End for GB
  3046. }
  3047. else if(gunType[gun_index] == GUN_TYPE_DO)
  3048. {
  3049. tempIndex = gun_index;
  3050. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3051. {
  3052. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3053. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3054. {
  3055. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3056. {
  3057. reqSampleMeter[gun_index] = 1;
  3058. }
  3059. }
  3060. }
  3061. }
  3062. else
  3063. {
  3064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3065. {
  3066. tempIndex = 2;
  3067. }
  3068. else
  3069. {
  3070. tempIndex = gun_index;
  3071. }
  3072. for (int index = 0; index < AC_QUANTITY; index++)
  3073. {
  3074. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3075. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3076. {
  3077. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3078. {
  3079. reqSampleMeter[gun_index] = 1;
  3080. }
  3081. }
  3082. }//End for AC
  3083. }
  3084. if(reqSampleMeter[gun_index] == 1)
  3085. {
  3086. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3087. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3088. storeTempStopTransaction(gun_index);
  3089. }
  3090. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3091. }
  3092. //==============================================
  3093. // Check Connector reserved
  3094. //==============================================
  3095. //===============================
  3096. // Check if Reserve is expired
  3097. //===============================
  3098. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3099. {
  3100. double diff_t;
  3101. struct tm tp;
  3102. // current time
  3103. time_t t = time(NULL);
  3104. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3105. tp.tm_isdst = -1;
  3106. time_t utc = mktime(&tp);
  3107. diff_t = difftime(utc, t);
  3108. if(diff_t <= 0)
  3109. {
  3110. DEBUG_INFO("reserve expired.\n");
  3111. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3112. }
  3113. }//END OF Check if Reserve is expired
  3114. //==========================================
  3115. // csu trigger FirmwareStatusNotificationReq
  3116. //==========================================
  3117. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3118. {
  3119. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3120. }
  3121. //==========================================
  3122. // csu trigger DiagnosticsStatusNotificationReq
  3123. //==========================================
  3124. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3125. {
  3126. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3127. }
  3128. //==========================================
  3129. // csu trigger CancelReservationConf
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3132. {
  3133. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3134. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3135. }
  3136. //==========================================
  3137. // csu trigger ChangeAvailabilityConf
  3138. //==========================================
  3139. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3140. {
  3141. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3142. }
  3143. //==========================================
  3144. // csu trigger UnlockConnectorConf
  3145. //==========================================
  3146. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3147. {
  3148. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3149. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3150. }
  3151. //==========================================
  3152. // csu trigger ReserveNowConf
  3153. //==========================================
  3154. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3155. {
  3156. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3157. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3158. }
  3159. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3160. {
  3161. sendSignCertificateRequest();
  3162. }
  3163. }
  3164. }
  3165. //==========================================
  3166. // send request routine
  3167. //==========================================
  3168. int sendAuthorizeRequest(int gun_index)
  3169. {
  3170. mtrace();
  3171. int result = FAIL;
  3172. char message[100]={0};
  3173. char guid[37];
  3174. char tempdata[65]={0};
  3175. DEBUG_INFO("sendAuthorizeRequest...\n");
  3176. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3177. //Local Authorize
  3178. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3179. {
  3180. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3181. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3182. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3183. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3184. result = PASS;
  3185. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3186. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3187. authorizeRetryTimes = 0;
  3188. return result;
  3189. }
  3190. 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))||
  3191. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3192. {
  3193. // Query from cache
  3194. DEBUG_INFO("Authorize from cache.\n");
  3195. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3196. // Query from list
  3197. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3198. {
  3199. DEBUG_INFO("Authorize from list.\n");
  3200. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3201. }
  3202. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3203. {
  3204. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3205. {
  3206. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3207. }
  3208. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3209. {
  3210. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3211. }
  3212. if(!GetOcppConnStatus())
  3213. {
  3214. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3215. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3216. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3217. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3218. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3219. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3220. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3221. authorizeRetryTimes = 0;
  3222. return result;
  3223. }
  3224. }
  3225. else
  3226. {
  3227. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3228. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3229. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3230. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3231. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3232. else
  3233. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3234. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3235. result = PASS;
  3236. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3237. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3238. authorizeRetryTimes = 0;
  3239. return result;
  3240. }
  3241. }
  3242. //initialize struct Authorize
  3243. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3244. //get data from shared memory
  3245. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3246. random_uuid(guid);
  3247. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3248. LWS_Send(message);
  3249. sprintf(tempdata, "Authorize,%d", gun_index);
  3250. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3251. {
  3252. result = PASS;
  3253. DEBUG_INFO("Authorize mapItem pass\n");
  3254. }
  3255. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3256. return result;
  3257. }
  3258. int sendBootNotificationRequest(void)
  3259. {
  3260. mtrace();
  3261. int result = FAIL;
  3262. char message[500]={0}, payload[700]={0};
  3263. char guid[37]={0};
  3264. char tempdata[65]={0};
  3265. // Fill BootNotification fields
  3266. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3267. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3268. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3269. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3270. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3271. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3272. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3273. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3274. ShmOCPP16Data->ChargeBoxId
  3275. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3276. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3277. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3278. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3279. ,ShmOCPP16Data->BootNotification.CpIccid
  3280. ,ShmOCPP16Data->BootNotification.CpImsi);
  3281. random_uuid(guid);
  3282. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3283. LWS_Send(message);
  3284. sprintf(tempdata, "BootNotification,0");
  3285. 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*/)
  3286. {
  3287. result = PASS;
  3288. }
  3289. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3290. strcpy(queuedata,message);
  3291. return result;
  3292. }
  3293. int sendDataTransferRequest(int gun_index)
  3294. {
  3295. mtrace();
  3296. char message[1000]={0};
  3297. char guid[37]={0};
  3298. char tempdata[65]={0};
  3299. int result = FAIL;
  3300. random_uuid(guid);
  3301. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3302. MESSAGE_TYPE_CALL,
  3303. guid,
  3304. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3305. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3306. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3307. LWS_Send(message);
  3308. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3309. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3310. {
  3311. result = PASS;
  3312. DEBUG_INFO("DataTransfer mapItem pass\n");
  3313. }
  3314. return result;
  3315. }
  3316. int sendDiagnosticsStatusNotificationRequest(char *status)
  3317. {
  3318. mtrace();
  3319. int result = FAIL;
  3320. char message[110]={0};
  3321. char guid[37]={0};
  3322. char tempdata[65]={0};
  3323. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3324. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3325. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3326. random_uuid(guid);
  3327. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3328. LWS_SendNow(message);
  3329. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3330. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3331. {
  3332. result = PASS;
  3333. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3334. }
  3335. //#ifdef SystemLogMessage
  3336. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3337. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3338. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3339. //#endif
  3340. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3341. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3342. //record status
  3343. if(strcmp(status,"Idle")==0)
  3344. {
  3345. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3346. }
  3347. else if(strcmp(status,"Uploaded")==0)
  3348. {
  3349. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3350. }
  3351. else if(strcmp(status,"UploadFailed")==0)
  3352. {
  3353. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3354. }
  3355. else if(strcmp(status,"Uploading")==0)
  3356. {
  3357. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3358. }
  3359. return result;
  3360. }
  3361. int sendFirmwareStatusNotificationRequest(char *status)
  3362. {
  3363. mtrace();
  3364. int result = FAIL;
  3365. char message[110]={0};
  3366. char guid[37]={0};
  3367. char tempdata[65]={0};
  3368. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3369. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3370. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3371. random_uuid(guid);
  3372. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3373. LWS_SendNow(message);
  3374. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3375. 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*/)
  3376. {
  3377. result = PASS;
  3378. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3379. }
  3380. //#ifdef SystemLogMessage
  3381. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3382. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3383. //#endif
  3384. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3385. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3386. //record status
  3387. if(strcmp(status,"Downloaded")==0)
  3388. {
  3389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3390. }
  3391. else if(strcmp(status,"DownloadFailed")==0)
  3392. {
  3393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3394. }
  3395. else if(strcmp(status,"Downloading")==0)
  3396. {
  3397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3398. }
  3399. else if(strcmp(status,"Idle")==0)
  3400. {
  3401. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3402. }
  3403. else if(strcmp(status,"InstallationFailed")==0)
  3404. {
  3405. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3406. }
  3407. else if(strcmp(status,"Installing")==0)
  3408. {
  3409. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3410. }
  3411. else if(strcmp(status,"Installed")==0)
  3412. {
  3413. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3414. }
  3415. return result;
  3416. }
  3417. int sendHeartbeatRequest(int gun_index)
  3418. {
  3419. mtrace();
  3420. int result = FAIL;
  3421. char message[80]={0};
  3422. char guid[37]={0};
  3423. char tempdata[65]={0};
  3424. random_uuid(guid);
  3425. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3426. , MESSAGE_TYPE_CALL
  3427. , guid );
  3428. LWS_Send(message);
  3429. sprintf(tempdata, "Heartbeat,%d", 0);
  3430. 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*/)
  3431. {
  3432. result = PASS;
  3433. }
  3434. return result;
  3435. }
  3436. int sendStartTransactionRequest(int gun_index)
  3437. {
  3438. mtrace();
  3439. int result = FAIL;
  3440. char message[250]={0};
  3441. char guid[37]={0};
  3442. struct timeval tmnow;
  3443. struct tm *tm;
  3444. char buf[28];//, usec_buf[6];
  3445. char tempdata[65]={0};
  3446. int tempIndex = 0;
  3447. DEBUG_INFO("sendStartTransactionRequest...\n");
  3448. gettimeofday(&tmnow, NULL);
  3449. time_t t;
  3450. t = time(NULL);
  3451. /*UTC time and date*/
  3452. tm = gmtime(&t);
  3453. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3454. #if 0 // remove temporally
  3455. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3456. strcat(buf,".");
  3457. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3458. strcat(buf,usec_buf);
  3459. #endif
  3460. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3461. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3462. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3463. // clear StartTransaction Response
  3464. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3465. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3466. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3467. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3468. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3469. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3471. {
  3472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3473. {
  3474. tempIndex = ((gun_index==2) ? 1: 0);
  3475. }
  3476. else
  3477. {
  3478. tempIndex = gun_index;
  3479. }
  3480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3481. {
  3482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3483. {
  3484. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3485. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3486. }
  3487. }
  3488. }
  3489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3490. {
  3491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3492. {
  3493. tempIndex = ((gun_index==2) ? 1: 0);
  3494. }
  3495. else
  3496. {
  3497. tempIndex = gun_index;
  3498. }
  3499. for (int index = 0; index < CCS_QUANTITY; index++)
  3500. {
  3501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3502. {
  3503. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3504. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3505. }
  3506. }
  3507. }
  3508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3509. {
  3510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3511. {
  3512. tempIndex = ((gun_index==2) ? 1: 0);
  3513. }
  3514. else
  3515. {
  3516. tempIndex = gun_index;
  3517. }
  3518. for (int index = 0; index < GB_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3521. {
  3522. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3523. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3524. }
  3525. }
  3526. }
  3527. else if(gunType[gun_index] == GUN_TYPE_DO)
  3528. {
  3529. tempIndex = gun_index;
  3530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3531. {
  3532. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3533. {
  3534. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3535. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3536. }
  3537. }
  3538. }
  3539. else
  3540. {
  3541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3542. {
  3543. tempIndex = 2;
  3544. }
  3545. else
  3546. {
  3547. tempIndex = gun_index;
  3548. }
  3549. for (int index = 0; index < AC_QUANTITY; index++)
  3550. {
  3551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3552. {
  3553. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3554. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3555. }
  3556. }
  3557. }
  3558. random_uuid(guid);
  3559. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3560. {
  3561. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3562. , gun_index +1
  3563. , MESSAGE_TYPE_CALL
  3564. , guid
  3565. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3566. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3567. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3568. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3569. }
  3570. else
  3571. {
  3572. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3573. , gun_index +1
  3574. , MESSAGE_TYPE_CALL
  3575. , guid
  3576. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3577. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3578. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3579. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3580. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3581. }
  3582. #if 1
  3583. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3584. 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*/)
  3585. {
  3586. result = PASS;
  3587. }
  3588. #endif
  3589. strcpy(queuedata, message);
  3590. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3591. OCPP_insert_transaction_msg(YES, queuedata);
  3592. return result;
  3593. }
  3594. int sendStatusNotificationRequest(int gun_index)
  3595. {
  3596. mtrace();
  3597. int result = FAIL;
  3598. char message[600]={0};
  3599. char guid[37];
  3600. int currentStatus = 0;
  3601. struct timeval tmnow;
  3602. struct tm *tm;
  3603. char buf[28];//, usec_buf[6];
  3604. char tempdata[65]={0};
  3605. int tempIndex = 0;
  3606. uint8_t isStateChanged = TRUE;
  3607. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3608. gettimeofday(&tmnow, NULL);
  3609. time_t t;
  3610. t = time(NULL);
  3611. /*UTC time and date*/
  3612. tm = gmtime(&t);
  3613. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3614. #if 0 // remove temporally
  3615. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3616. strcat(buf,".");
  3617. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3618. strcat(buf,usec_buf);
  3619. #endif
  3620. printf("%s",buf);
  3621. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3622. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3623. // it's option
  3624. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3625. /*
  3626. enum _SYSTEM_STATUS
  3627. {
  3628. S_BOOTING = 0,
  3629. S_IDLE, = 1
  3630. S_AUTHORIZING, =2
  3631. S_REASSIGN_CHECK, =3
  3632. S_REASSIGN, =4
  3633. S_PRECHARGE, =5
  3634. S_PREPARING_FOR_EV, =6
  3635. S_PREPARING_FOR_EVSE, =7
  3636. S_CHARGING, =8
  3637. S_TERMINATING, =9
  3638. S_COMPLETE, =10
  3639. S_ALARM, =11
  3640. S_FAULT =12
  3641. }
  3642. */
  3643. //check Transaction active
  3644. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3645. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3646. {
  3647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3648. {
  3649. tempIndex = ((gun_index==2) ? 1: 0);
  3650. }
  3651. else
  3652. {
  3653. tempIndex = gun_index;
  3654. }
  3655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3656. {
  3657. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3658. {
  3659. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3660. {
  3661. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3662. {
  3663. currentStatus = Preparing; //OCPP Status: Preparing
  3664. }
  3665. else
  3666. {
  3667. currentStatus = Available; //OCPP Status: Available
  3668. }
  3669. }
  3670. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3671. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3672. ) //S_PRECHARGE
  3673. {
  3674. currentStatus = Preparing; //OCPP Status: Preparing
  3675. }
  3676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3677. {
  3678. currentStatus = Charging; //OCPP Status: Charging
  3679. }
  3680. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3681. {
  3682. currentStatus = Finishing; //OCPP Status: Finishing
  3683. }
  3684. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3685. {
  3686. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3687. }
  3688. 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
  3689. {
  3690. currentStatus = Unavailable; //OCPP Status: Unavailable
  3691. }
  3692. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3693. {
  3694. currentStatus = Faulted; //OCPP Status: Faulted
  3695. }
  3696. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3697. {
  3698. currentStatus = Reserved; //OCPP Status: Reserved
  3699. }
  3700. } //end of the same index
  3701. }//end of for CHAdeMO_QUANTITY
  3702. }
  3703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3718. {
  3719. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3720. {
  3721. currentStatus = Preparing; //OCPP Status: Preparing
  3722. }
  3723. else
  3724. {
  3725. currentStatus = Available; //OCPP Status: Available
  3726. }
  3727. }
  3728. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3729. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3730. ) //S_PRECHARGE
  3731. {
  3732. currentStatus = Preparing; //OCPP Status: Preparing
  3733. }
  3734. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3735. {
  3736. currentStatus = Charging; //OCPP Status: Charging
  3737. }
  3738. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3739. {
  3740. currentStatus = Finishing; //OCPP Status: Finishing
  3741. }
  3742. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3743. {
  3744. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3745. }
  3746. 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
  3747. {
  3748. currentStatus = Unavailable; //OCPP Status : Unavailable
  3749. }
  3750. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3751. {
  3752. currentStatus = Faulted; //OCPP Status: Faulted
  3753. }
  3754. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3755. {
  3756. currentStatus = Reserved; //OCPP Status: Reserved
  3757. }
  3758. } //end of the same index
  3759. } // end of for CCS_QUANTITY
  3760. }
  3761. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3762. {
  3763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3764. {
  3765. tempIndex = ((gun_index==2) ? 1: 0);
  3766. }
  3767. else
  3768. {
  3769. tempIndex = gun_index;
  3770. }
  3771. for (int index = 0; index < GB_QUANTITY; index++)
  3772. {
  3773. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3774. {
  3775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3776. {
  3777. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3778. {
  3779. currentStatus = Preparing; //OCPP Status: Preparing
  3780. }
  3781. else
  3782. {
  3783. currentStatus = Available; //OCPP Status: Available
  3784. }
  3785. }
  3786. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3787. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3788. ) //S_PRECHARGE
  3789. {
  3790. currentStatus = Preparing; //OCPP Status: Preparing
  3791. }
  3792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3793. {
  3794. currentStatus = Charging; //OCPP Status: Charging
  3795. }
  3796. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3797. {
  3798. currentStatus = Finishing; //OCPP Status: Finishing
  3799. }
  3800. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3801. {
  3802. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3803. }
  3804. 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
  3805. {
  3806. currentStatus = Unavailable; //OCPP Status: Unavailable
  3807. }
  3808. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3809. {
  3810. currentStatus = Faulted; //OCPP Status: Faulted
  3811. }
  3812. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3813. {
  3814. currentStatus = Reserved; //OCPP Status: Reserved
  3815. }
  3816. } //end of the same index
  3817. } // end of for GB_QUANTITY
  3818. }
  3819. else if(gunType[gun_index] == GUN_TYPE_DO)
  3820. {
  3821. tempIndex = gun_index;
  3822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3823. {
  3824. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3825. {
  3826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3827. {
  3828. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3829. {
  3830. currentStatus = Preparing; //OCPP Status: Preparing
  3831. }
  3832. else
  3833. {
  3834. currentStatus = Available; //OCPP Status: Available
  3835. }
  3836. }
  3837. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3838. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3839. ) //S_PRECHARGE
  3840. {
  3841. currentStatus = Preparing; //OCPP Status: Preparing
  3842. }
  3843. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3844. {
  3845. currentStatus = Charging; //OCPP Status: Charging
  3846. }
  3847. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3848. {
  3849. currentStatus = Finishing; //OCPP Status: Finishing
  3850. }
  3851. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3852. {
  3853. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3854. }
  3855. 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
  3856. {
  3857. currentStatus = Unavailable; //OCPP Status: Unavailable
  3858. }
  3859. 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
  3860. {
  3861. currentStatus = Faulted; //OCPP Status: Faulted
  3862. }
  3863. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3864. {
  3865. currentStatus = Reserved; //OCPP Status: Reserved
  3866. }
  3867. } //end of the same index
  3868. }
  3869. }
  3870. else
  3871. {
  3872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3873. {
  3874. tempIndex = 2;
  3875. }
  3876. else
  3877. {
  3878. tempIndex = gun_index;
  3879. }
  3880. for (int index = 0; index < AC_QUANTITY; index++)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3883. {
  3884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3885. {
  3886. 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))
  3887. {
  3888. currentStatus = Preparing; //OCPP Status: Preparing
  3889. }
  3890. else
  3891. {
  3892. currentStatus = Available; //OCPP Status: Available
  3893. }
  3894. }
  3895. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3896. {
  3897. currentStatus = Preparing; //OCPP Status: Preparing
  3898. }
  3899. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3900. {
  3901. currentStatus = Charging; //OCPP Status: Charging
  3902. }
  3903. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3904. {
  3905. currentStatus = Finishing; //OCPP Status: Finishing
  3906. }
  3907. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3908. {
  3909. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3910. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3911. else
  3912. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3913. }
  3914. 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
  3915. {
  3916. currentStatus = Unavailable; //OCPP Status: Unavailable
  3917. }
  3918. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3919. {
  3920. currentStatus = Faulted; //OCPP Status: Faulted
  3921. }
  3922. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3923. {
  3924. currentStatus = Reserved; //OCPP Status: Reserved
  3925. }
  3926. }//end of the same index
  3927. }//end of for AC_QUANTITY
  3928. }
  3929. //it's option
  3930. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3931. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3932. {
  3933. isStateChanged = FALSE;
  3934. }
  3935. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3936. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3937. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3938. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3939. random_uuid(guid);
  3940. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3941. , MESSAGE_TYPE_CALL
  3942. , guid
  3943. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3944. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3945. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3946. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3947. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3948. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3949. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3950. if((server_sign == TRUE) && isStateChanged)
  3951. {
  3952. LWS_Send(message);
  3953. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3954. 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*/)
  3955. {
  3956. //DEBUG_ERROR("statusNotification mapitem pass");
  3957. result = PASS;
  3958. }
  3959. }
  3960. else
  3961. {
  3962. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3963. result = PASS;
  3964. }
  3965. return result;
  3966. }
  3967. int sendStopTransactionRequest(int gun_index)
  3968. {
  3969. mtrace();
  3970. int result = FAIL;
  3971. //char message[1500]={0};
  3972. char guid[37]={0};
  3973. char tempdata[65]={0};
  3974. int tempIndex = 0;
  3975. char TempStopTransaction[256];
  3976. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3977. //int idx_sample=0;
  3978. DEBUG_INFO("sendStopTransactionRequest \n");
  3979. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3980. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3981. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3982. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3984. {
  3985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3986. {
  3987. tempIndex = ((gun_index==2) ? 1: 0);
  3988. }
  3989. else
  3990. {
  3991. tempIndex = gun_index;
  3992. }
  3993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3994. {
  3995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3996. {
  3997. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3998. }
  3999. }// END OF CHAdeMO_QUANTITY
  4000. }
  4001. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4002. {
  4003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4004. {
  4005. tempIndex = ((gun_index==2) ? 1: 0);
  4006. }
  4007. else
  4008. {
  4009. tempIndex = gun_index;
  4010. }
  4011. for (int index = 0; index < CCS_QUANTITY; index++)
  4012. {
  4013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4014. {
  4015. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4016. }
  4017. }// END OF CCS_QUANTITY
  4018. }
  4019. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4020. {
  4021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4022. {
  4023. tempIndex = ((gun_index==2) ? 1: 0);
  4024. }
  4025. else
  4026. {
  4027. tempIndex = gun_index;
  4028. }
  4029. for (int index = 0; index < GB_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4032. {
  4033. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4034. }
  4035. }// END OF GB_QUANTITY
  4036. }
  4037. else if(gunType[gun_index] == GUN_TYPE_DO)
  4038. {
  4039. tempIndex = gun_index;
  4040. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4043. {
  4044. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4045. }
  4046. }// END OF GB_QUANTITY
  4047. }
  4048. else
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4051. {
  4052. tempIndex = 2;
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < AC_QUANTITY; index++)
  4059. {
  4060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4061. {
  4062. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4063. }
  4064. }// END OF AC_QUANTITY
  4065. }
  4066. //====================================== Stop Transaction Time =====================================================
  4067. struct timeval tmnow;
  4068. struct tm *tm;
  4069. char buf[28];//, usec_buf[6];
  4070. gettimeofday(&tmnow, NULL);
  4071. time_t t;
  4072. t = time(NULL);
  4073. /*UTC time and date*/
  4074. tm = gmtime(&t);
  4075. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4077. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4078. random_uuid(guid);
  4079. /***********************************transactionData******************************************************/
  4080. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4082. //=================================
  4083. // Transaction_Begin
  4084. //=================================
  4085. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4086. {
  4087. //============================================ Energy.Active.Import.Interval ================================
  4088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4091. 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*/]);
  4092. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4093. 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))
  4094. {
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4096. }
  4097. else
  4098. {
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4100. }
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4103. }
  4104. //=================================
  4105. // Transaction_End
  4106. //=================================
  4107. // ================================= Current.Import L1 ===============================================
  4108. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4109. {
  4110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4114. {
  4115. tempIndex = ((gun_index==2) ? 1: 0);
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4124. {
  4125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4126. }
  4127. }// End of for CHAdeMO_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4129. }
  4130. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4131. {
  4132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4133. {
  4134. tempIndex = ((gun_index==2) ? 1: 0);
  4135. }
  4136. else
  4137. {
  4138. tempIndex = gun_index;
  4139. }
  4140. for (int index = 0; index < CCS_QUANTITY; index++)
  4141. {
  4142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4143. {
  4144. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4145. }
  4146. }// End of for CCS_QUANTITY
  4147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4148. }
  4149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4150. {
  4151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4152. {
  4153. tempIndex = ((gun_index==2) ? 1: 0);
  4154. }
  4155. else
  4156. {
  4157. tempIndex = gun_index;
  4158. }
  4159. for (int index = 0; index < GB_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4162. {
  4163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4164. }
  4165. }// End of for GB_QUANTITY
  4166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4167. }
  4168. else if(gunType[gun_index] == GUN_TYPE_DO)
  4169. {
  4170. tempIndex = gun_index;
  4171. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4176. }
  4177. }
  4178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4179. }
  4180. else
  4181. {
  4182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4183. {
  4184. tempIndex = 2;
  4185. }
  4186. else
  4187. {
  4188. tempIndex = gun_index;
  4189. }
  4190. for (int index = 0; index < AC_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4195. }
  4196. }// End of for AC_QUANTITY
  4197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4198. }
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4204. }
  4205. // ================================= Energy.Active.Import.Interval ==============================================
  4206. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4207. {
  4208. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4209. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4210. {
  4211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4212. {
  4213. tempIndex = ((gun_index==2) ? 1: 0);
  4214. }
  4215. else
  4216. {
  4217. tempIndex = gun_index;
  4218. }
  4219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4222. {
  4223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4224. }
  4225. }// END OF CHAdeMO_QUANTITY
  4226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4227. }
  4228. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < CCS_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4243. }
  4244. }// END OF CCS_QUANTITY
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4246. }
  4247. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4250. {
  4251. tempIndex = ((gun_index==2) ? 1: 0);
  4252. }
  4253. else
  4254. {
  4255. tempIndex = gun_index;
  4256. }
  4257. for (int index = 0; index < GB_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4260. {
  4261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4262. }
  4263. }// END OF GB_QUANTITY
  4264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4265. }
  4266. else if(gunType[gun_index] == GUN_TYPE_DO)
  4267. {
  4268. tempIndex = gun_index;
  4269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4272. {
  4273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4274. }
  4275. }
  4276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4277. }
  4278. else
  4279. {
  4280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4281. {
  4282. tempIndex = 2;
  4283. }
  4284. else
  4285. {
  4286. tempIndex = gun_index;
  4287. }
  4288. for (int index = 0; index < AC_QUANTITY; index++)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4291. {
  4292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4293. }
  4294. }// END OF AC_QUANTITY
  4295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4296. }
  4297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4302. }
  4303. //=================================== Power.Active.Import ==================================================
  4304. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4305. {
  4306. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4318. {
  4319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4320. {
  4321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4322. }
  4323. } // End for CHAdeMO_QUANTITY
  4324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4325. }
  4326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4327. {
  4328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4329. {
  4330. tempIndex = ((gun_index==2) ? 1: 0);
  4331. }
  4332. else
  4333. {
  4334. tempIndex = gun_index;
  4335. }
  4336. for (int index = 0; index < CCS_QUANTITY; index++)
  4337. {
  4338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4339. {
  4340. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4341. }
  4342. } // END for CCS_QUANTITY
  4343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4344. }
  4345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < GB_QUANTITY; index++)
  4356. {
  4357. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4358. {
  4359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4360. }
  4361. }// END for GB_QUANTITY
  4362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4363. }
  4364. else if(gunType[gun_index] == GUN_TYPE_DO)
  4365. {
  4366. tempIndex = gun_index;
  4367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4372. }
  4373. }
  4374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4375. }
  4376. else
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4379. {
  4380. tempIndex = 2;
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < AC_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4389. {
  4390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4391. }
  4392. } // END for AC_QUANTITY
  4393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4394. }
  4395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4400. }
  4401. //============================ Voltage L1 ====================================
  4402. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4403. {
  4404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4405. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4406. {
  4407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4408. {
  4409. tempIndex = ((gun_index==2) ? 1: 0);
  4410. }
  4411. else
  4412. {
  4413. tempIndex = gun_index;
  4414. }
  4415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4418. {
  4419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4420. }
  4421. } // END OF FOR CHAdeMO_QUANTITY
  4422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4423. }
  4424. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4425. {
  4426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4427. {
  4428. tempIndex = ((gun_index==2) ? 1: 0);
  4429. }
  4430. else
  4431. {
  4432. tempIndex = gun_index;
  4433. }
  4434. for (int index = 0; index < CCS_QUANTITY; index++)
  4435. {
  4436. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4437. {
  4438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4439. }
  4440. } // END OF FOR CCS_QUANTITY
  4441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4442. }
  4443. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4444. {
  4445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4446. {
  4447. tempIndex = ((gun_index==2) ? 1: 0);
  4448. }
  4449. else
  4450. {
  4451. tempIndex = gun_index;
  4452. }
  4453. for (int index = 0; index < GB_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4456. {
  4457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4458. }
  4459. } // END OF FOR GB_QUANTITY
  4460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4461. }
  4462. else if(gunType[gun_index] == GUN_TYPE_DO)
  4463. {
  4464. tempIndex = gun_index;
  4465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4468. {
  4469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4470. }
  4471. }
  4472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4473. }
  4474. else
  4475. {
  4476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4477. {
  4478. tempIndex = 2;
  4479. }
  4480. else
  4481. {
  4482. tempIndex = gun_index;
  4483. }
  4484. for (int index = 0; index < AC_QUANTITY; index++)
  4485. {
  4486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4487. {
  4488. 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
  4489. }
  4490. } // END OF FOR AC_QUANTITY
  4491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4492. }
  4493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4498. }
  4499. //====================== End SoC ================================
  4500. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4501. {
  4502. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4503. 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))
  4504. {
  4505. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4506. {
  4507. tempIndex = ((gun_index==2) ? 1: 0);
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4514. {
  4515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4516. {
  4517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4518. {
  4519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4520. }
  4521. }
  4522. }
  4523. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4524. {
  4525. for (int index = 0; index < CCS_QUANTITY; index++)
  4526. {
  4527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4528. {
  4529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4530. }
  4531. }
  4532. }
  4533. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4534. {
  4535. for (int index = 0; index < GB_QUANTITY; index++)
  4536. {
  4537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4538. {
  4539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4540. }
  4541. }
  4542. }
  4543. else if(gunType[gun_index] == GUN_TYPE_DO)
  4544. {
  4545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4546. {
  4547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4548. {
  4549. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4550. }
  4551. }
  4552. }
  4553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4559. } // END FOR DC CASE
  4560. }
  4561. // ================================= Current.Import L2 ===============================================
  4562. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4563. {
  4564. // AC 3 phse L2 current
  4565. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4566. {
  4567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4568. {
  4569. tempIndex = 2;
  4570. }
  4571. else
  4572. {
  4573. tempIndex = gun_index;
  4574. }
  4575. for (int index = 0; index < AC_QUANTITY; index++)
  4576. {
  4577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4578. {
  4579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4580. }
  4581. }// End of for AC_QUANTITY
  4582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4583. }
  4584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4589. }
  4590. // ================================= Current.Import L3 ===============================================
  4591. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4592. {
  4593. // AC 3 phse L3 current
  4594. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4595. {
  4596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4597. {
  4598. tempIndex = 2;
  4599. }
  4600. else
  4601. {
  4602. tempIndex = gun_index;
  4603. }
  4604. for (int index = 0; index < AC_QUANTITY; index++)
  4605. {
  4606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4607. {
  4608. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4609. }
  4610. }// End of for AC_QUANTITY
  4611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4612. }
  4613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4618. }
  4619. //============================ Voltage L2 ====================================
  4620. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4621. {
  4622. // AC 3 phse L2 voltage
  4623. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4624. {
  4625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4626. {
  4627. tempIndex = 2;
  4628. }
  4629. else
  4630. {
  4631. tempIndex = gun_index;
  4632. }
  4633. for (int index = 0; index < AC_QUANTITY; index++)
  4634. {
  4635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4636. {
  4637. 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
  4638. }
  4639. } // END OF FOR AC_QUANTITY
  4640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4641. }
  4642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4647. }
  4648. //============================ Voltage L3 ====================================
  4649. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4650. {
  4651. // AC 3 phse L3 voltage
  4652. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4653. {
  4654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4655. {
  4656. tempIndex = 2;
  4657. }
  4658. else
  4659. {
  4660. tempIndex = gun_index;
  4661. }
  4662. for (int index = 0; index < AC_QUANTITY; index++)
  4663. {
  4664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4665. {
  4666. 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
  4667. }
  4668. } // END OF FOR AC_QUANTITY
  4669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4670. }
  4671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4676. }
  4677. //====================== Start SoC ================================
  4678. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4679. {
  4680. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4681. 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))
  4682. {
  4683. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4692. {
  4693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4694. {
  4695. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4696. {
  4697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4698. }
  4699. }
  4700. }
  4701. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4702. {
  4703. for (int index = 0; index < CCS_QUANTITY; index++)
  4704. {
  4705. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4706. {
  4707. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4708. }
  4709. }
  4710. }
  4711. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4712. {
  4713. for (int index = 0; index < GB_QUANTITY; index++)
  4714. {
  4715. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4716. {
  4717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4718. }
  4719. }
  4720. }
  4721. else if(gunType[gun_index] == GUN_TYPE_DO)
  4722. {
  4723. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4724. {
  4725. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4726. {
  4727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4728. }
  4729. }
  4730. }
  4731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4737. } // END FOR DC CASE
  4738. }
  4739. //================================================ Message create ====================================================
  4740. json_object *StopTransaction = json_object_new_object();
  4741. json_object *transactionDatas = json_object_new_array();
  4742. json_object *sampledValues = json_object_new_array();
  4743. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4744. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4745. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4746. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4747. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4748. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4749. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4750. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4751. {
  4752. json_object *transactionData = json_object_new_object();
  4753. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4754. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4755. {
  4756. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4757. {
  4758. json_object *sampledValue = json_object_new_object();
  4759. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4760. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4761. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4762. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4763. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4764. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4765. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4766. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4767. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4768. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4769. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4770. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4771. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4772. json_object_array_add(sampledValues, sampledValue);
  4773. }
  4774. }
  4775. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4776. json_object_array_add(transactionDatas, transactionData);
  4777. }
  4778. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4779. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4780. ,MESSAGE_TYPE_CALL
  4781. ,guid
  4782. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4783. json_object_put(StopTransaction);
  4784. #if 1 // for TempStopTransaction
  4785. //Delete TempStopTransaction
  4786. if((access(TempStopTransaction,F_OK))!=-1)
  4787. {
  4788. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4789. }
  4790. #endif
  4791. #if 1
  4792. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4793. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4794. {
  4795. result = PASS;
  4796. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4797. }
  4798. #endif
  4799. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4800. OCPP_insert_transaction_msg(NO, queuedata);
  4801. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4802. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4803. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4804. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4805. {
  4806. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4807. }
  4808. //for test
  4809. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4810. return result;
  4811. }
  4812. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4813. {
  4814. mtrace();
  4815. int result = FAIL;
  4816. char guid[37]={0};
  4817. char tempdata[65]={0};
  4818. int tempIndex = 0;
  4819. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4820. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4821. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4822. //set value
  4823. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4824. 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) )?
  4825. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4826. -1);
  4827. random_uuid(guid);
  4828. //UTC Date time
  4829. struct timeval tmnow;
  4830. struct tm *tm;
  4831. char buf[28];//, usec_buf[6];
  4832. gettimeofday(&tmnow, NULL);
  4833. time_t t;
  4834. t = time(NULL);
  4835. /*UTC time and date*/
  4836. tm = gmtime(&t);
  4837. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4839. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4840. //********************************(1)Current.Import L1************************************************/
  4841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4843. (dataType == ReadingContext_Trigger))
  4844. {
  4845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4847. {
  4848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4849. {
  4850. tempIndex = ((gun_index==2) ? 1: 0);
  4851. }
  4852. else
  4853. {
  4854. tempIndex = gun_index;
  4855. }
  4856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4857. {
  4858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4859. {
  4860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4861. }
  4862. }
  4863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4864. }
  4865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4866. {
  4867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4868. {
  4869. tempIndex = ((gun_index==2) ? 1: 0);
  4870. }
  4871. else
  4872. {
  4873. tempIndex = gun_index;
  4874. }
  4875. for (int index = 0; index < CCS_QUANTITY; index++)
  4876. {
  4877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4878. {
  4879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4880. }
  4881. }
  4882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4883. }
  4884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4885. {
  4886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4887. {
  4888. tempIndex = ((gun_index==2) ? 1: 0);
  4889. }
  4890. else
  4891. {
  4892. tempIndex = gun_index;
  4893. }
  4894. for (int index = 0; index < GB_QUANTITY; index++)
  4895. {
  4896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4897. {
  4898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4899. }
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4902. }
  4903. else if(gunType[gun_index] == GUN_TYPE_DO)
  4904. {
  4905. tempIndex = gun_index;
  4906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4909. {
  4910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4911. }
  4912. }
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4914. }
  4915. else
  4916. {
  4917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4918. {
  4919. tempIndex = 2;
  4920. }
  4921. else
  4922. {
  4923. tempIndex = gun_index;
  4924. }
  4925. for (int index = 0; index < AC_QUANTITY; index++)
  4926. {
  4927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4928. {
  4929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4930. }
  4931. }
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4933. }
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4939. }
  4940. //********************************(2)Energy.Active.Import.Register ************************************************/
  4941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4943. (dataType == ReadingContext_Trigger))
  4944. {
  4945. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4949. {
  4950. tempIndex = ((gun_index==2) ? 1: 0);
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4959. {
  4960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4961. }
  4962. }
  4963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CCS_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4978. {
  4979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4980. }
  4981. }
  4982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4983. }
  4984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4985. {
  4986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4987. {
  4988. tempIndex = ((gun_index==2) ? 1: 0);
  4989. }
  4990. else
  4991. {
  4992. tempIndex = gun_index;
  4993. }
  4994. for (int index = 0; index < GB_QUANTITY; index++)
  4995. {
  4996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4997. {
  4998. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4999. }
  5000. }
  5001. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_DO)
  5004. {
  5005. tempIndex = gun_index;
  5006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5011. }
  5012. }
  5013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5014. }
  5015. else
  5016. {
  5017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5018. {
  5019. tempIndex = 2;
  5020. }
  5021. else
  5022. {
  5023. tempIndex = gun_index;
  5024. }
  5025. for (int index = 0; index < AC_QUANTITY; index++)
  5026. {
  5027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5028. {
  5029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5030. }
  5031. }
  5032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5033. }
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5039. }
  5040. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5041. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5042. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5043. (dataType == ReadingContext_Trigger))
  5044. {
  5045. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5046. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5047. {
  5048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5049. {
  5050. tempIndex = ((gun_index==2) ? 1: 0);
  5051. }
  5052. else
  5053. {
  5054. tempIndex = gun_index;
  5055. }
  5056. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5057. {
  5058. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5059. {
  5060. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5061. }
  5062. } // END OF FOR CHAdeMO_QUANTITY
  5063. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5064. }
  5065. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5066. {
  5067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5068. {
  5069. tempIndex = ((gun_index==2) ? 1: 0);
  5070. }
  5071. else
  5072. {
  5073. tempIndex = gun_index;
  5074. }
  5075. for (int index = 0; index < CCS_QUANTITY; index++)
  5076. {
  5077. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5078. {
  5079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5080. }
  5081. } // END OF CCS_QUANTITY
  5082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5083. }
  5084. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5085. {
  5086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5087. {
  5088. tempIndex = ((gun_index==2) ? 1: 0);
  5089. }
  5090. else
  5091. {
  5092. tempIndex = gun_index;
  5093. }
  5094. for (int index = 0; index < GB_QUANTITY; index++)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5097. {
  5098. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5099. }
  5100. } // END OF GB_QUANTITY
  5101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5102. }
  5103. else if(gunType[gun_index] == GUN_TYPE_DO)
  5104. {
  5105. tempIndex = gun_index;
  5106. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5107. {
  5108. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5109. {
  5110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5111. }
  5112. }
  5113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5114. }
  5115. else
  5116. {
  5117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5118. {
  5119. tempIndex = 2;
  5120. }
  5121. else
  5122. {
  5123. tempIndex = gun_index;
  5124. }
  5125. for (int index = 0; index < AC_QUANTITY; index++)
  5126. {
  5127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5128. {
  5129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5130. }
  5131. }
  5132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5133. }
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5139. }
  5140. //********************************(4)Power.Active.Import************************************************/
  5141. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5142. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5143. (dataType == ReadingContext_Trigger))
  5144. {
  5145. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5146. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5147. {
  5148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5149. {
  5150. tempIndex = ((gun_index==2) ? 1: 0);
  5151. }
  5152. else
  5153. {
  5154. tempIndex = gun_index;
  5155. }
  5156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5157. {
  5158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5159. {
  5160. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5161. }
  5162. } // END OF FOR
  5163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5164. }
  5165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5166. {
  5167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5168. {
  5169. tempIndex = ((gun_index==2) ? 1: 0);
  5170. }
  5171. else
  5172. {
  5173. tempIndex = gun_index;
  5174. }
  5175. for (int index = 0; index < CCS_QUANTITY; index++)
  5176. {
  5177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5178. {
  5179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5180. }
  5181. }
  5182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5183. }
  5184. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5185. {
  5186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5187. {
  5188. tempIndex = ((gun_index==2) ? 1: 0);
  5189. }
  5190. else
  5191. {
  5192. tempIndex = gun_index;
  5193. }
  5194. for (int index = 0; index < GB_QUANTITY; index++)
  5195. {
  5196. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5197. {
  5198. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5200. }
  5201. }
  5202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5203. }
  5204. else if(gunType[gun_index] == GUN_TYPE_DO)
  5205. {
  5206. tempIndex = gun_index;
  5207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5208. {
  5209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5210. {
  5211. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5212. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5213. }
  5214. }
  5215. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5216. }
  5217. else
  5218. {
  5219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5220. {
  5221. tempIndex = 2;
  5222. }
  5223. else
  5224. {
  5225. tempIndex = gun_index;
  5226. }
  5227. for (int index = 0; index < AC_QUANTITY; index++)
  5228. {
  5229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5230. {
  5231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5232. }
  5233. }
  5234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5235. }
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5241. }
  5242. //***********************************************(5)VOLTAGE L1******************************************************/
  5243. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5244. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5245. (dataType == ReadingContext_Trigger))
  5246. {
  5247. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5248. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5249. {
  5250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5251. {
  5252. tempIndex = ((gun_index==2) ? 1: 0);
  5253. }
  5254. else
  5255. {
  5256. tempIndex = gun_index;
  5257. }
  5258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5261. {
  5262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5263. }
  5264. }
  5265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5266. }
  5267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5268. {
  5269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5270. {
  5271. tempIndex = ((gun_index==2) ? 1: 0);
  5272. }
  5273. else
  5274. {
  5275. tempIndex = gun_index;
  5276. }
  5277. for (int index = 0; index < CCS_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5280. {
  5281. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5282. }
  5283. }
  5284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5285. }
  5286. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5287. {
  5288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5289. {
  5290. tempIndex = ((gun_index==2) ? 1: 0);
  5291. }
  5292. else
  5293. {
  5294. tempIndex = gun_index;
  5295. }
  5296. for (int index = 0; index < GB_QUANTITY; index++)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5299. {
  5300. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5301. }
  5302. }
  5303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5304. }
  5305. else if(gunType[gun_index] == GUN_TYPE_DO)
  5306. {
  5307. tempIndex = gun_index;
  5308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5313. }
  5314. }
  5315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5316. }
  5317. else
  5318. {
  5319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5320. {
  5321. tempIndex = 2;
  5322. }
  5323. else
  5324. {
  5325. tempIndex = gun_index;
  5326. }
  5327. for (int index = 0; index < AC_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5332. }
  5333. }
  5334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5335. }
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5341. }
  5342. //***********************************************(6)SOC******************************************************/
  5343. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5344. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5345. (dataType == ReadingContext_Trigger))
  5346. {
  5347. 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))
  5348. {
  5349. //idx_sample=5;
  5350. //sampledValue = NULL;
  5351. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5352. {
  5353. tempIndex = ((gun_index==2) ? 1: 0);
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5360. {
  5361. //tempIndex = ((gun_index==2) ? 1: 0);
  5362. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5363. {
  5364. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5365. {
  5366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5367. }
  5368. }
  5369. }
  5370. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5371. {
  5372. //tempIndex = ((gun_index==2) ? 1: 0);
  5373. for (int index = 0; index < CCS_QUANTITY; index++)
  5374. {
  5375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5376. {
  5377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5378. }
  5379. }
  5380. }
  5381. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5382. {
  5383. //tempIndex = ((gun_index==2) ? 1: 0);
  5384. for (int index = 0; index < GB_QUANTITY; index++)
  5385. {
  5386. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5387. {
  5388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5389. }
  5390. }
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_DO)
  5393. {
  5394. //tempIndex = ((gun_index==2) ? 1: 0);
  5395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5398. {
  5399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5400. }
  5401. }
  5402. }
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5408. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5409. }
  5410. }
  5411. //********************************(7)Current.Import L2************************************************/
  5412. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5413. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5414. (dataType == ReadingContext_Trigger))
  5415. {
  5416. // Only for AC 3 phase
  5417. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5418. {
  5419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5420. {
  5421. tempIndex = 2;
  5422. }
  5423. else
  5424. {
  5425. tempIndex = gun_index;
  5426. }
  5427. for (int index = 0; index < AC_QUANTITY; index++)
  5428. {
  5429. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5430. {
  5431. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5432. }
  5433. }
  5434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5435. }
  5436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5441. }
  5442. //********************************(8)Current.Import L3************************************************/
  5443. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5444. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5445. (dataType == ReadingContext_Trigger))
  5446. {
  5447. // Only for AC 3 phase
  5448. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5449. {
  5450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5451. {
  5452. tempIndex = 2;
  5453. }
  5454. else
  5455. {
  5456. tempIndex = gun_index;
  5457. }
  5458. for (int index = 0; index < AC_QUANTITY; index++)
  5459. {
  5460. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5461. {
  5462. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5463. }
  5464. }
  5465. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5466. }
  5467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5472. }
  5473. //***********************************************(9)VOLTAGE L2******************************************************/
  5474. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5475. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5476. (dataType == ReadingContext_Trigger))
  5477. {
  5478. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5479. {
  5480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5481. {
  5482. tempIndex = 2;
  5483. }
  5484. else
  5485. {
  5486. tempIndex = gun_index;
  5487. }
  5488. for (int index = 0; index < AC_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5491. {
  5492. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5493. }
  5494. }
  5495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5496. }
  5497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5502. }
  5503. //***********************************************(10)VOLTAGE L3******************************************************/
  5504. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5505. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5506. (dataType == ReadingContext_Trigger))
  5507. {
  5508. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5509. {
  5510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5511. {
  5512. tempIndex = 2;
  5513. }
  5514. else
  5515. {
  5516. tempIndex = gun_index;
  5517. }
  5518. for (int index = 0; index < AC_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5521. {
  5522. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5523. }
  5524. }
  5525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5526. }
  5527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5532. }
  5533. // Message create ====================================================================================================
  5534. if(TRUE)
  5535. {
  5536. json_object *MeterValueReq = json_object_new_object();
  5537. json_object *MeterValues = json_object_new_array();
  5538. json_object *sampledValues = json_object_new_array();
  5539. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5540. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5541. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5542. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5543. {
  5544. json_object *MeterValue = json_object_new_object();
  5545. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5546. {
  5547. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5548. {
  5549. json_object *sampledValue = json_object_new_object();
  5550. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5551. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5552. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5553. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5554. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5555. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5556. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5557. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5558. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5559. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5560. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5561. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5562. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5563. json_object_array_add(sampledValues, sampledValue);
  5564. }
  5565. }
  5566. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5567. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5568. json_object_array_add(MeterValues, MeterValue);
  5569. }
  5570. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5571. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5572. ,gun_index + 1
  5573. ,MESSAGE_TYPE_CALL
  5574. ,guid
  5575. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5576. json_object_put(MeterValueReq);
  5577. }
  5578. // Put request guid to hash map
  5579. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5580. 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*/)
  5581. {
  5582. result = PASS;
  5583. //DEBUG_INFO("MeterValues mapitem pass\n");
  5584. }
  5585. if((dataType != ReadingContext_Trigger) &&
  5586. (dataType != ReadingContext_Sample_Clock) &&
  5587. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5588. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5589. else
  5590. {
  5591. if(FirstHeartBeat)
  5592. LWS_Send(queuedata +2);
  5593. }
  5594. return result;
  5595. }
  5596. int sendLogStatusNotificationRequest(char *status)
  5597. {
  5598. mtrace();
  5599. int result = PASS;
  5600. char message[4096]={0};
  5601. char guid[37]={0};
  5602. char tempdata[128]={0};
  5603. json_object *LogStatusNotification = json_object_new_object();
  5604. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5605. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5606. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5607. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5608. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5609. random_uuid(guid);
  5610. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5611. json_object_put(LogStatusNotification);
  5612. LWS_Send(message);
  5613. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5614. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5615. {
  5616. result = PASS;
  5617. }
  5618. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5619. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5620. return result;
  5621. }
  5622. int sendSecurityEventNotificationRequest()
  5623. {
  5624. mtrace();
  5625. int result = PASS;
  5626. char message[4096]={0};
  5627. char guid[37]={0};
  5628. char tempdata[128]={0};
  5629. json_object *SecurityEventNotification = json_object_new_object();
  5630. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5631. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5632. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5633. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5634. random_uuid(guid);
  5635. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5636. json_object_put(SecurityEventNotification);
  5637. LWS_Send(message);
  5638. sprintf(tempdata, "SecurityEventNotification,0");
  5639. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5640. {
  5641. result = PASS;
  5642. }
  5643. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5644. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5645. return result;
  5646. }
  5647. int sendSignCertificateRequest()
  5648. {
  5649. mtrace();
  5650. int result = PASS;
  5651. char message[4096]={0};
  5652. char guid[37]={0};
  5653. char tempdata[128]={0};
  5654. json_object *SignCertificate = json_object_new_object();
  5655. DEBUG_INFO("sendSignCertificateRequest...\n");
  5656. // Read csr file content
  5657. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5658. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5659. char *line = NULL;
  5660. size_t len = 0;
  5661. while(getline(&line, &len, fp) != -1)
  5662. {
  5663. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5664. {
  5665. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5666. }
  5667. }
  5668. fclose(fp);
  5669. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5670. random_uuid(guid);
  5671. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5672. json_object_put(SignCertificate);
  5673. LWS_Send(message);
  5674. sprintf(tempdata, "SignCertificate,0");
  5675. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5676. {
  5677. result = PASS;
  5678. }
  5679. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5680. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5681. return result;
  5682. }
  5683. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5684. {
  5685. mtrace();
  5686. int result = PASS;
  5687. char message[110]={0};
  5688. char guid[37]={0};
  5689. char tempdata[65]={0};
  5690. json_object *FirmwareStatusNotification = json_object_new_object();
  5691. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5692. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5693. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5694. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5695. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5696. random_uuid(guid);
  5697. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5698. json_object_put(FirmwareStatusNotification);
  5699. LWS_Send(message);
  5700. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5701. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5702. {
  5703. result = PASS;
  5704. }
  5705. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5706. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5707. return result;
  5708. }
  5709. //==========================================
  5710. // send confirm routine
  5711. //==========================================
  5712. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5713. {
  5714. mtrace();
  5715. int result = FAIL;
  5716. char message[100]={0};
  5717. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5718. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5719. LWS_Send(message);
  5720. result = TRUE;
  5721. return result;
  5722. }
  5723. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5724. {
  5725. mtrace();
  5726. int result = FAIL;
  5727. char message[100]={0};
  5728. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5729. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5730. LWS_Send(message);
  5731. result = TRUE;
  5732. return result;
  5733. }
  5734. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5735. {
  5736. mtrace();
  5737. int result = FAIL;
  5738. char message[100]={0};
  5739. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5740. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5741. LWS_Send(message);
  5742. result = TRUE;
  5743. return result;
  5744. }
  5745. int sendClearCacheConfirmation(char *uuid,char *payload)
  5746. {
  5747. mtrace();
  5748. int result = FAIL;
  5749. char message[500]={0};
  5750. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5751. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5752. LWS_Send(message);
  5753. return result;
  5754. }
  5755. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5756. {
  5757. mtrace();
  5758. int result = FAIL;
  5759. char message[500]={0};
  5760. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5761. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5762. LWS_Send(message);
  5763. return result;
  5764. }
  5765. int sendDataTransferConfirmation(char *uuid,char *payload)
  5766. {
  5767. mtrace();
  5768. char statusStr[20]={0};
  5769. char dataStr[10]={0};
  5770. char sstr[20]={0};
  5771. int c = 0;
  5772. char *loc;
  5773. int result = FAIL;
  5774. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5775. /**********************status**************************/
  5776. loc = strstr(payload, "status");
  5777. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5778. c = 0;
  5779. while (loc[3+strlen("status")+c] != '\"')
  5780. {
  5781. sstr[c] = loc[3+strlen("status")+c];
  5782. c++;
  5783. }
  5784. sstr[c] = '\0';
  5785. strcpy(statusStr, sstr);
  5786. /**********************data**************************/
  5787. loc = strstr(payload, "data");
  5788. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5789. c = 0;
  5790. while (loc[3+strlen("data")+c] != '\"')
  5791. {
  5792. sstr[c] = loc[3+strlen("data")+c];
  5793. c++;
  5794. }
  5795. sstr[c] = '\0';
  5796. strcpy(dataStr, sstr);
  5797. return result;
  5798. }
  5799. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5800. {
  5801. mtrace();
  5802. int result = FAIL;
  5803. char message[1000]={0};
  5804. int CompositeScheduleIndex = 0;
  5805. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5806. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5807. if(nPeriod == 0)
  5808. {
  5809. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5810. {
  5811. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5812. ,MESSAGE_TYPE_CALLRESULT
  5813. ,uuid
  5814. ,payload
  5815. ,connectorIdInt);
  5816. }
  5817. else
  5818. {
  5819. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5820. ,MESSAGE_TYPE_CALLRESULT
  5821. ,uuid
  5822. ,payload
  5823. ,connectorIdInt
  5824. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5825. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5826. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5827. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5828. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5829. }
  5830. }
  5831. else
  5832. {
  5833. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5834. ,MESSAGE_TYPE_CALLRESULT
  5835. ,uuid
  5836. ,payload
  5837. ,connectorIdInt
  5838. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5839. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5840. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5841. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5842. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5843. {
  5844. if (idx_sample == 0)
  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. else
  5852. {
  5853. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5854. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5855. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5856. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5857. }
  5858. }
  5859. sprintf(message + strlen(message), "]}}]");
  5860. }
  5861. LWS_Send(message);
  5862. result = TRUE;
  5863. return result;
  5864. }
  5865. int sendGetConfigurationConfirmation(char *uuid)
  5866. {
  5867. mtrace();
  5868. int result = FAIL;
  5869. int MaxKeySupported = 0;
  5870. int sentConfigurationNumber= 0;
  5871. int sentunConfigurationNumber= 0;
  5872. char message[4000]={0};
  5873. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5874. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5875. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5876. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5877. ,MESSAGE_TYPE_CALLRESULT
  5878. ,uuid );
  5879. //configuration key
  5880. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5881. {
  5882. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5883. {
  5884. if (sentConfigurationNumber == 0)
  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. else
  5892. {
  5893. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5894. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5895. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5896. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5897. }
  5898. sentConfigurationNumber = sentConfigurationNumber + 1;
  5899. }
  5900. }
  5901. sprintf(message + strlen(message), "]");
  5902. if(UnknownKeynum != 0)
  5903. {
  5904. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5905. //unkown key
  5906. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5907. {
  5908. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5909. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5910. if(sentunConfigurationNumber == 0)
  5911. {
  5912. sprintf(message + strlen(message), "\"%s\""
  5913. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5914. }
  5915. else
  5916. {
  5917. sprintf(message + strlen(message), ",\"%s\""
  5918. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5919. }
  5920. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5921. }
  5922. sprintf(message + strlen(message), "]");
  5923. }
  5924. sprintf(message + strlen(message), "}]");
  5925. LWS_Send(message);
  5926. return result;
  5927. }
  5928. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5929. {
  5930. mtrace();
  5931. int result = FAIL;
  5932. char message[400]={0};
  5933. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5934. if(strcmp(payload,"")==0)
  5935. {
  5936. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5937. }
  5938. else
  5939. {
  5940. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5941. }
  5942. LWS_Send(message);
  5943. result = TRUE;
  5944. return result;
  5945. }
  5946. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5947. {
  5948. mtrace();
  5949. int result = FAIL;
  5950. char message[80]={0};
  5951. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5952. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5953. LWS_Send(message);
  5954. result = TRUE;
  5955. return result;
  5956. }
  5957. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5958. {
  5959. mtrace();
  5960. int result = FAIL;
  5961. char message[80]={0};
  5962. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5964. LWS_Send(message);
  5965. result = TRUE;
  5966. return result;
  5967. }
  5968. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5969. {
  5970. mtrace();
  5971. int result = FAIL;
  5972. char message[80]={0};
  5973. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5974. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5975. LWS_Send(message);
  5976. result = TRUE;
  5977. return result;
  5978. }
  5979. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5980. {
  5981. mtrace();
  5982. int result = FAIL;
  5983. char message[80]={0};
  5984. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5985. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5987. LWS_Send(message);
  5988. result = TRUE;
  5989. return result;
  5990. }
  5991. int sendResetConfirmation(char *uuid,char *payload)
  5992. {
  5993. mtrace();
  5994. int result = FAIL;
  5995. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5996. char message[80]={0};
  5997. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5999. LWS_Send(message);
  6000. result = TRUE;
  6001. return result;
  6002. }
  6003. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6004. {
  6005. mtrace();
  6006. int result = FAIL;
  6007. char message[500]={0};
  6008. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6009. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6010. LWS_Send(message);
  6011. result = TRUE;
  6012. return result;
  6013. }
  6014. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6015. {
  6016. mtrace();
  6017. int result = FAIL;
  6018. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6019. char message[80]={0};
  6020. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6022. LWS_Send(message);
  6023. result = TRUE;
  6024. return result;
  6025. }
  6026. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6027. {
  6028. mtrace();
  6029. int result = FAIL;
  6030. char message[80]={0};
  6031. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6033. LWS_Send(message);
  6034. result = TRUE;
  6035. return result;
  6036. }
  6037. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6038. {
  6039. mtrace();
  6040. int result = FAIL;
  6041. char message[80]={0};
  6042. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6043. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6044. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6045. LWS_Send(message);
  6046. result = TRUE;
  6047. return result;
  6048. }
  6049. int sendUpdateFirmwareConfirmation(char *uuid)
  6050. {
  6051. mtrace();
  6052. int result = FAIL;
  6053. char message[60]={0};
  6054. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6055. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6056. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6057. LWS_Send(message);
  6058. result = TRUE;
  6059. return result;
  6060. }
  6061. int sendCertificateSignedConfirmation(char *uuid)
  6062. {
  6063. mtrace();
  6064. int result = PASS;
  6065. char message[4096]={0};
  6066. json_object *CertificateSigned = json_object_new_object();
  6067. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6068. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6069. sprintf(message,"[%d,\"%s\",%s]"
  6070. ,MESSAGE_TYPE_CALLRESULT
  6071. ,uuid
  6072. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6073. json_object_put(CertificateSigned);
  6074. LWS_Send(message);
  6075. return result;
  6076. }
  6077. int sendDeleteCertificateConfirmation(char *uuid)
  6078. {
  6079. mtrace();
  6080. int result = PASS;
  6081. char message[4096]={0};
  6082. json_object *DeleteCertificate = json_object_new_object();
  6083. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6084. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6085. sprintf(message,"[%d,\"%s\",%s]"
  6086. ,MESSAGE_TYPE_CALLRESULT
  6087. ,uuid
  6088. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6089. json_object_put(DeleteCertificate);
  6090. LWS_Send(message);
  6091. return result;
  6092. }
  6093. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6094. {
  6095. mtrace();
  6096. int result = PASS;
  6097. char message[4096]={0};
  6098. json_object *ExtendedTriggerMessage = json_object_new_object();
  6099. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6100. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6101. sprintf(message,"[%d,\"%s\",%s]"
  6102. ,MESSAGE_TYPE_CALLRESULT
  6103. ,uuid
  6104. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6105. json_object_put(ExtendedTriggerMessage);
  6106. LWS_Send(message);
  6107. return result;
  6108. }
  6109. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6110. {
  6111. mtrace();
  6112. int result = PASS;
  6113. char message[4096]={0};
  6114. json_object *GetInstalledCertificateIds = json_object_new_object();
  6115. json_object *certificateHashDataDatas = json_object_new_array();
  6116. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6117. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6118. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6119. {
  6120. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6121. {
  6122. json_object *certificateHashData = json_object_new_object();
  6123. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6124. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6125. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6126. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6127. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6128. }
  6129. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6130. }
  6131. else
  6132. {
  6133. json_object_put(certificateHashDataDatas);
  6134. }
  6135. sprintf(message,"[%d,\"%s\",%s]"
  6136. ,MESSAGE_TYPE_CALLRESULT
  6137. ,uuid
  6138. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6139. json_object_put(GetInstalledCertificateIds);
  6140. LWS_Send(message);
  6141. return result;
  6142. }
  6143. int sendGetLogConfirmation(char *uuid)
  6144. {
  6145. mtrace();
  6146. int result = PASS;
  6147. char message[4096]={0};
  6148. json_object *GetLog = json_object_new_object();
  6149. DEBUG_INFO("sendGetLogConfirmation...\n");
  6150. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6151. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6152. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6153. sprintf(message,"[%d,\"%s\",%s]"
  6154. ,MESSAGE_TYPE_CALLRESULT
  6155. ,uuid
  6156. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6157. json_object_put(GetLog);
  6158. LWS_Send(message);
  6159. return result;
  6160. }
  6161. int sendInstallCertificateConfirmation(char *uuid)
  6162. {
  6163. mtrace();
  6164. int result = PASS;
  6165. char message[4096]={0};
  6166. json_object *InstallCertificate = json_object_new_object();
  6167. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6168. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6169. sprintf(message,"[%d,\"%s\",%s]"
  6170. ,MESSAGE_TYPE_CALLRESULT
  6171. ,uuid
  6172. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6173. json_object_put(InstallCertificate);
  6174. LWS_Send(message);
  6175. return result;
  6176. }
  6177. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6178. {
  6179. mtrace();
  6180. int result = PASS;
  6181. char message[4096]={0};
  6182. json_object *SignedUpdateFirmware = json_object_new_object();
  6183. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6184. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6185. sprintf(message,"[%d,\"%s\",%s]"
  6186. ,MESSAGE_TYPE_CALLRESULT
  6187. ,uuid
  6188. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6189. json_object_put(SignedUpdateFirmware);
  6190. LWS_Send(message);
  6191. return result;
  6192. }
  6193. int sendUnknownConfirmation(char *uuid)
  6194. {
  6195. mtrace();
  6196. int result = PASS;
  6197. char message[256]={0};
  6198. DEBUG_INFO("sendUnknownConfirmation...\n");
  6199. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6200. LWS_Send(message);
  6201. return result;
  6202. }
  6203. //==========================================
  6204. // Handle server request routine Start
  6205. //==========================================
  6206. int handleCancelReservationRequest(char *uuid, char *payload)
  6207. {
  6208. mtrace();
  6209. int result = FAIL;
  6210. int gunNO = 0;
  6211. int reservationIdInt = -1;
  6212. char comfirmstr[20];
  6213. DEBUG_INFO("handleCancelReservationRequest...\n");
  6214. json_object *CancelReservation;
  6215. CancelReservation = json_tokener_parse(payload);
  6216. if(!is_error(CancelReservation))
  6217. {
  6218. // Required data
  6219. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6220. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6221. }
  6222. json_object_put(CancelReservation);
  6223. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6224. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6225. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6226. if(reservationIdInt != -1)
  6227. {
  6228. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6229. //check Transaction active
  6230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6232. {
  6233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6234. {
  6235. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6236. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6237. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6238. {
  6239. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6240. }
  6241. else
  6242. {
  6243. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6244. }
  6245. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6246. goto end;
  6247. }
  6248. }
  6249. for (int index = 0; index < CCS_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6252. {
  6253. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6254. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6255. if(gunType[2] == GUN_TYPE_CCS)
  6256. {
  6257. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6258. }
  6259. else
  6260. {
  6261. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6262. }
  6263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6264. goto end;
  6265. }
  6266. }
  6267. for (int index = 0; index < GB_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6270. {
  6271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6272. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6273. if(gunType[2] == GUN_TYPE_GBT)
  6274. {
  6275. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6276. }
  6277. else
  6278. {
  6279. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6280. }
  6281. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6282. goto end;
  6283. }
  6284. }
  6285. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6288. {
  6289. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6290. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6291. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6292. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6293. goto end;
  6294. }
  6295. }
  6296. for (int index = 0; index < AC_QUANTITY; index++)
  6297. {
  6298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6299. {
  6300. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6301. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6303. {
  6304. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6305. }
  6306. else
  6307. {
  6308. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6309. }
  6310. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6311. goto end;
  6312. }
  6313. }
  6314. }
  6315. //The reservationId does NOT match the reservationId
  6316. sendCancelReservationConfirmation(uuid, comfirmstr);
  6317. end:
  6318. // Fill in ocpp packet uuid
  6319. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6320. return result;
  6321. }
  6322. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6323. {
  6324. mtrace();
  6325. int result = FAIL;
  6326. int gunIndex = 0;
  6327. char typeStr[16]={0};
  6328. char comfirmstr[20];
  6329. int specificId = FALSE;
  6330. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6331. json_object *ChangeAvailability;
  6332. ChangeAvailability = json_tokener_parse(payload);
  6333. if(!is_error(ChangeAvailability))
  6334. {
  6335. // Required data
  6336. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6337. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6338. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6339. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6340. }
  6341. json_object_put(ChangeAvailability);
  6342. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6343. {
  6344. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6345. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6346. }
  6347. else if(gunIndex == 0)
  6348. {
  6349. for(int i=0; i < gunTotalNumber; i++)
  6350. {
  6351. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6352. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6353. }
  6354. }
  6355. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6357. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6358. {
  6359. specificId = TRUE;
  6360. }
  6361. if(specificId == FALSE)
  6362. goto end;
  6363. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6364. {
  6365. //----------------------gunIndex is 0 ------------------------------------------------//
  6366. if(gunIndex == 0)
  6367. {
  6368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6369. {
  6370. for(int i=0; i < gunTotalNumber; i++)
  6371. {
  6372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6373. {
  6374. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6375. {
  6376. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6377. {
  6378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6379. goto end;
  6380. }
  6381. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6382. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6383. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6384. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6385. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6386. {
  6387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6388. goto end;
  6389. }
  6390. }
  6391. }//END FOR CHAdeMO_QUANTITY
  6392. for (int index = 0; index < CCS_QUANTITY; index++)
  6393. {
  6394. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6395. {
  6396. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6397. {
  6398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6399. goto end;
  6400. }
  6401. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6405. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6406. {
  6407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6408. goto end;
  6409. }
  6410. }
  6411. }//END FOR CCS_QUANTITY
  6412. for (int index = 0; index < GB_QUANTITY; index++)
  6413. {
  6414. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6415. {
  6416. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6417. {
  6418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6419. goto end;
  6420. }
  6421. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6422. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6423. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6424. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6425. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6426. {
  6427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6428. goto end;
  6429. }
  6430. }
  6431. }// END FOR GB_QUANTITY
  6432. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6433. {
  6434. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6435. {
  6436. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6437. {
  6438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6439. goto end;
  6440. }
  6441. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6444. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6445. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6446. {
  6447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6448. goto end;
  6449. }
  6450. }
  6451. }// END FOR GENERAL_GUN_QUANTITY
  6452. for (int index = 0; index < AC_QUANTITY; index++)
  6453. {
  6454. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6455. {
  6456. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6457. {
  6458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6459. goto end;
  6460. }
  6461. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6464. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6466. {
  6467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6468. goto end;
  6469. }
  6470. }
  6471. }//END FOR AC_QUANTITY
  6472. }// END FOR gunTotalNumber
  6473. }
  6474. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6475. {
  6476. for(int i=0; i < gunTotalNumber; i++)
  6477. {
  6478. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6479. {
  6480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6481. goto end;
  6482. }
  6483. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6484. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6485. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6486. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6487. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6488. {
  6489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6490. goto end;
  6491. }
  6492. }
  6493. }
  6494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6495. goto end;
  6496. }
  6497. //----------------------gunIndex is not 0 ------------------------------------------------//
  6498. //check Transaction active
  6499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6500. {
  6501. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6502. {
  6503. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6504. {
  6505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6506. goto end;
  6507. }
  6508. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6509. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6510. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6511. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6513. {
  6514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6515. goto end;
  6516. }
  6517. else
  6518. {
  6519. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6521. goto end;
  6522. }
  6523. }
  6524. }//END FOR CHAdeMO_QUANTITY
  6525. for (int index = 0; index < CCS_QUANTITY; index++)
  6526. {
  6527. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6528. {
  6529. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6530. {
  6531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6532. goto end;
  6533. }
  6534. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6535. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6536. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6537. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6538. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6539. {
  6540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6541. goto end;
  6542. }
  6543. else
  6544. {
  6545. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6547. goto end;
  6548. }
  6549. }
  6550. }//END FOR CCS_QUANTITY
  6551. for (int index = 0; index < GB_QUANTITY; index++)
  6552. {
  6553. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6554. {
  6555. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6556. {
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6558. goto end;
  6559. }
  6560. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6561. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6563. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6564. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6565. {
  6566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6567. goto end;
  6568. }
  6569. else
  6570. {
  6571. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6573. goto end;
  6574. }
  6575. }
  6576. }// END FOR GB_QUANTITY
  6577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6578. {
  6579. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6580. {
  6581. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6582. {
  6583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6584. goto end;
  6585. }
  6586. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6587. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6588. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6589. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6590. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6591. {
  6592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6593. goto end;
  6594. }
  6595. else
  6596. {
  6597. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6599. goto end;
  6600. }
  6601. }
  6602. }// END FOR GENERAL_GUN_QUANTITY
  6603. for (int index = 0; index < AC_QUANTITY; index++)
  6604. {
  6605. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6606. {
  6607. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6608. {
  6609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6610. goto end;
  6611. }
  6612. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6613. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6614. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6616. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6617. {
  6618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6619. goto end;
  6620. }
  6621. else
  6622. {
  6623. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6625. goto end;
  6626. }
  6627. }
  6628. }//END FOR AC_QUANTITY
  6629. }//END FOR AvailabilityTypeStr[Inoperative]
  6630. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6631. {
  6632. //----------------------gunIndex is 0 ------------------------------------------------//
  6633. if(gunIndex == 0)
  6634. {
  6635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6636. {
  6637. for(int i=0; i < gunTotalNumber; i++)
  6638. {
  6639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6640. {
  6641. 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
  6642. {
  6643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6644. goto end;
  6645. }
  6646. }//END FOR CHAdeMO_QUANTITY
  6647. for (int index = 0; index < CCS_QUANTITY; index++)
  6648. {
  6649. 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
  6650. {
  6651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6652. goto end;
  6653. }
  6654. }//END FOR CCS_QUANTITY
  6655. for (int index = 0; index < GB_QUANTITY; index++)
  6656. {
  6657. 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
  6658. {
  6659. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6661. goto end;
  6662. }
  6663. }// END FOR GB_QUANTITY
  6664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6665. {
  6666. 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
  6667. {
  6668. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6670. goto end;
  6671. }
  6672. }// END FOR GENERAL_GUN_QUANTITY
  6673. for (int index = 0; index < AC_QUANTITY; index++)
  6674. {
  6675. 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
  6676. {
  6677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6678. goto end;
  6679. }
  6680. }//END FOR CHAdeMO_QUANTITY
  6681. }// END FOR gunTotalNumber
  6682. }
  6683. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6684. {
  6685. for(int i=0; i < gunTotalNumber; i++)
  6686. {
  6687. for (int index = 0; index < AC_QUANTITY; index++)
  6688. {
  6689. 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
  6690. {
  6691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6692. goto end;
  6693. }
  6694. }//END FOR CHAdeMO_QUANTITY
  6695. } // END FOR gunTotalNumber
  6696. }
  6697. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6698. goto end;
  6699. }
  6700. //----------------------gunIndex is not 0 ------------------------------------------------//
  6701. //check Transaction active
  6702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6703. {
  6704. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6705. {
  6706. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6707. goto end;
  6708. }
  6709. }//END FOR CHAdeMO_QUANTITY
  6710. for (int index = 0; index < CCS_QUANTITY; index++)
  6711. {
  6712. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6713. {
  6714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6715. goto end;
  6716. }
  6717. }//END FOR CCS_QUANTITY
  6718. for (int index = 0; index < GB_QUANTITY; index++)
  6719. {
  6720. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6721. {
  6722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6723. goto end;
  6724. }
  6725. }// END FOR GB_QUANTITY
  6726. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6727. {
  6728. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6729. {
  6730. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6731. goto end;
  6732. }
  6733. }// END FOR GENERAL_GUN_QUANTITY
  6734. for (int index = 0; index < AC_QUANTITY; index++)
  6735. {
  6736. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6737. {
  6738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6739. goto end;
  6740. }
  6741. }//END FOR AC_QUANTITY
  6742. }//END FOR AvailabilityTypeStr[Operative]
  6743. end:
  6744. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6745. {
  6746. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6747. }
  6748. else
  6749. {
  6750. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6751. }
  6752. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6753. {
  6754. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6755. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6756. }
  6757. else if(gunIndex == 0)
  6758. {
  6759. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6760. {
  6761. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6762. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6763. }
  6764. }
  6765. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6766. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6767. return result;
  6768. }
  6769. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6770. {
  6771. mtrace();
  6772. int result = FAIL;
  6773. char keystr[40]={0};
  6774. char valuestr[256]={0};
  6775. char comfirmstr[20]={0};
  6776. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6777. json_object *ChangeConfiguration;
  6778. ChangeConfiguration = json_tokener_parse(payload);
  6779. if(!is_error(ChangeConfiguration))
  6780. {
  6781. // Required data
  6782. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6783. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6784. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6785. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6786. }
  6787. json_object_put(ChangeConfiguration);
  6788. if((uuid==NULL) || (payload ==NULL) )
  6789. {
  6790. DEBUG_ERROR("Payload is null\n");
  6791. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6792. }
  6793. else
  6794. {
  6795. int status = setKeyValue(keystr, valuestr);
  6796. switch(status)
  6797. {
  6798. case ConfigurationStatus_Accepted:
  6799. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6800. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6801. StoreConfigurationTable();
  6802. break;
  6803. case RebootRequired:
  6804. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6805. StoreConfigurationTable();
  6806. break;
  6807. case NotSupported:
  6808. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6809. break;
  6810. case ConfigurationStatus_Rejected:
  6811. default:
  6812. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6813. break;
  6814. }
  6815. }
  6816. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6817. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6818. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6819. {
  6820. ChageWebSocketPingInterval(atoi(valuestr));
  6821. }
  6822. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6823. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6824. {
  6825. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6826. SetOcppConnStatus(FALSE);
  6827. }
  6828. return result;
  6829. }
  6830. int handleClearCacheRequest(char *uuid, char *payload)
  6831. {
  6832. mtrace();
  6833. int result = FAIL;
  6834. char comfirmstr[20];
  6835. char rmFileCmd[100]={0};
  6836. struct stat stats;
  6837. DEBUG_INFO("handleClearCacheRequest...\n");
  6838. stat("/Storage/OCPP", &stats);
  6839. // Check for directory existence
  6840. if (S_ISDIR(stats.st_mode) == 1)
  6841. {}
  6842. else
  6843. {
  6844. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6845. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6846. system(rmFileCmd);
  6847. }
  6848. if(OCPP_cleanLocalCache())
  6849. {
  6850. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6851. }
  6852. else
  6853. {
  6854. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6855. }
  6856. sendClearCacheConfirmation(uuid, comfirmstr);
  6857. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6858. return result;
  6859. }
  6860. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6861. {
  6862. mtrace();
  6863. int result = FAIL;
  6864. int resultRename;
  6865. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6866. char chargingProfilePurposeStr[26]={0};
  6867. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6868. char tempchargingProfilePurposeStr[26]={0};
  6869. char str[100]={0};
  6870. char fname[200]={0};
  6871. char comfirmstr[20]={0};
  6872. char word[1600]={0};
  6873. int clearflag = FALSE;
  6874. int chargingProfileIdIsNULL = FALSE;
  6875. int connectorIsNULL = FALSE;
  6876. int chargingProfilePurposeIsNULL = FALSE;
  6877. int stackLevelIsNULL = FALSE;
  6878. //int GotoEnd = FALSE;
  6879. FILE *fptr1, *fptr2;
  6880. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6881. int n_chargingProfile=0;
  6882. int isEmptyFile = FALSE;
  6883. char sLineWord[1600]={0};
  6884. char chargingProfiles[10][100]={0};
  6885. int ChargeProfileCount = 0;
  6886. int ch;
  6887. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6888. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6889. json_object *ClearChargingProfile;
  6890. ClearChargingProfile = json_tokener_parse(payload);
  6891. if(!is_error(ClearChargingProfile))
  6892. {
  6893. // Optional data
  6894. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6895. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6896. else
  6897. chargingProfileIdIsNULL = TRUE;
  6898. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6899. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6900. else
  6901. connectorIsNULL = TRUE;
  6902. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6903. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6904. else
  6905. chargingProfilePurposeIsNULL = TRUE;
  6906. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6907. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6908. else
  6909. stackLevelIsNULL = TRUE;
  6910. }
  6911. json_object_put(ClearChargingProfile);
  6912. if(connectorIsNULL == FALSE)
  6913. {
  6914. switch(connectorIdInt)
  6915. {
  6916. case 0:
  6917. if(chargingProfilePurposeIsNULL == TRUE)
  6918. {
  6919. int l = 0;
  6920. strcpy(fname, ChargePointMaxProfile_JSON);
  6921. if((access(fname,F_OK))!=-1)
  6922. {
  6923. strcpy(chargingProfiles[l], fname);
  6924. l = l + 1;
  6925. }
  6926. strcpy(fname, TxDefaultProfile_0_JSON);
  6927. if((access(fname,F_OK))!=-1)
  6928. {
  6929. strcpy(chargingProfiles[l], fname);
  6930. l = l + 1;
  6931. }
  6932. ChargeProfileCount = l;
  6933. }
  6934. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6935. {
  6936. strcpy(fname, ChargePointMaxProfile_JSON);
  6937. if((access(fname,F_OK))!=-1)
  6938. {
  6939. strcpy(chargingProfiles[0], fname);
  6940. ChargeProfileCount = 1;
  6941. }
  6942. }
  6943. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6944. {
  6945. strcpy(fname, TxDefaultProfile_0_JSON);
  6946. if((access(fname,F_OK))!=-1)
  6947. {
  6948. strcpy(chargingProfiles[0], fname);
  6949. ChargeProfileCount = 1;
  6950. }
  6951. }
  6952. break;
  6953. default:
  6954. if(chargingProfilePurposeIsNULL == TRUE)
  6955. {
  6956. int m = 0;
  6957. memset(fname, 0, ARRAY_SIZE(fname));
  6958. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6959. if((access(fname,F_OK))!=-1)
  6960. {
  6961. strcpy(chargingProfiles[m], fname);
  6962. m = m + 1;
  6963. }
  6964. memset(fname, 0, ARRAY_SIZE(fname));
  6965. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6966. if((access(fname,F_OK))!=-1)
  6967. {
  6968. strcpy(chargingProfiles[m], fname);
  6969. m = m + 1;
  6970. }
  6971. ChargeProfileCount = m;
  6972. }
  6973. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6974. {
  6975. //strcpy(fname, TxDefaultProfile_1_JSON);
  6976. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6977. if((access(fname,F_OK))!=-1)
  6978. {
  6979. strcpy(chargingProfiles[0], fname);
  6980. ChargeProfileCount = 1;
  6981. }
  6982. }
  6983. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6984. {
  6985. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6986. if((access(fname,F_OK))!=-1)
  6987. {
  6988. strcpy(chargingProfiles[0], fname);
  6989. ChargeProfileCount = 1;
  6990. }
  6991. //strcpy(fname, TxProfile_1_JSON);
  6992. }
  6993. //strcpy(fname, ChargePointMaxProfile_JSON );
  6994. break;
  6995. }
  6996. }
  6997. else // Check all Charging Profiles
  6998. {
  6999. int i = 0;
  7000. char fnametemp[200]={0};
  7001. ChargeProfileCount = 0;
  7002. //Check ChargePointMaxProfile.json exit
  7003. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7004. {
  7005. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7006. i = i + 1;
  7007. }
  7008. //Check TxDefaultProfile_0.json exit
  7009. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7010. {
  7011. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7012. i = i + 1;
  7013. }
  7014. //Check TxDefaultProfile_%d.json
  7015. for(int j=1; j <= gunTotalNumber; j++)
  7016. {
  7017. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7018. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7019. if((access(fnametemp,F_OK))!=-1)
  7020. {
  7021. strcpy(chargingProfiles[i], fnametemp);
  7022. i = i + 1;
  7023. }
  7024. }
  7025. //Check TxProfile_%d.json
  7026. for(int j=1; j <= gunTotalNumber; j++)
  7027. {
  7028. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7029. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7030. if((access(fnametemp,F_OK))!=-1)
  7031. {
  7032. strcpy(chargingProfiles[i], fnametemp);
  7033. i = i + 1;
  7034. }
  7035. }
  7036. ChargeProfileCount = i;
  7037. }// End connectorIsNULL is TRUE
  7038. if(ChargeProfileCount == 0)
  7039. {
  7040. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7041. goto end;
  7042. }
  7043. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7044. {
  7045. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7046. goto end;
  7047. }
  7048. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7049. {
  7050. memset(str, 0, ARRAY_SIZE(str));
  7051. // clear temp file
  7052. sprintf(str,"rm -f %s",temp);
  7053. system(str);
  7054. for(int k=0; k < ChargeProfileCount; k++)
  7055. {
  7056. memset(str, 0, ARRAY_SIZE(str));
  7057. //clear file in C
  7058. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7059. system(str);
  7060. }
  7061. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7062. goto end;
  7063. }
  7064. else if(connectorIsNULL == TRUE)
  7065. {
  7066. for(int k=0; k < ChargeProfileCount; k++)
  7067. {
  7068. fptr1 = fopen(chargingProfiles[k], "r");
  7069. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7070. //Check Charging Profile Count
  7071. while(fscanf(fptr1, "%s", word) != EOF)
  7072. {
  7073. //DEBUG_INFO("word=%s\n",word);
  7074. if(strstr(word, "chargingProfileId")!= NULL)
  7075. {
  7076. //DEBUG_INFO("test chargingProfileId \n");
  7077. n_chargingProfile = n_chargingProfile + 1;
  7078. //DEBUG_INFO("chargingProfileId Found\n");
  7079. }
  7080. }
  7081. rewind(fptr1);
  7082. //search Charging Profile Element
  7083. //int i= 0;
  7084. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7085. {
  7086. json_object *tmpProfilee;
  7087. tmpProfilee = json_tokener_parse(sLineWord);
  7088. if(!is_error(tmpProfilee))
  7089. {
  7090. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7091. {
  7092. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7093. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7094. }
  7095. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7096. {
  7097. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7098. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7099. }
  7100. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7101. {
  7102. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7103. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7104. }
  7105. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7106. {
  7107. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7108. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7109. }
  7110. }
  7111. json_object_put(tmpProfilee);
  7112. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7113. {
  7114. //------- not write to fptr2-------//
  7115. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7116. //clearflag = TRUE;
  7117. }
  7118. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7119. {
  7120. //------- not write to fptr2-------//
  7121. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7122. }
  7123. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7124. {
  7125. //------- not write to fptr2-------//
  7126. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7127. }
  7128. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7129. {
  7130. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7131. }
  7132. else
  7133. {
  7134. fprintf(fptr2, sLineWord);//writing data into file
  7135. }
  7136. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7137. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7138. if(clearflag == TRUE)
  7139. {
  7140. fclose(fptr1);
  7141. fclose(fptr2);
  7142. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7143. system(str);
  7144. // clear temp file
  7145. sprintf(str,"rm -f %s",temp);
  7146. system(str);
  7147. }
  7148. else
  7149. {
  7150. fclose(fptr1);
  7151. fclose(fptr2);
  7152. memset(str, 0, ARRAY_SIZE(str));
  7153. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7154. system(str);
  7155. resultRename = rename(temp, chargingProfiles[k]);
  7156. if(resultRename == 0)
  7157. {
  7158. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7159. }
  7160. else
  7161. {
  7162. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7163. }
  7164. if(comfirmstr[0]== 0)
  7165. {
  7166. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7167. }
  7168. //Check chargingProfile is empty file
  7169. /*------ Read the file ----------------*/
  7170. fptr1=fopen(chargingProfiles[k],"r");
  7171. ch=fgetc(fptr1);
  7172. rewind(fptr1);
  7173. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7174. if(ch!=EOF)
  7175. {
  7176. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7177. {
  7178. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7179. if(sLineWord[0]=='\0')
  7180. {
  7181. isEmptyFile = TRUE;
  7182. break;
  7183. }
  7184. else
  7185. {
  7186. isEmptyFile = FALSE;
  7187. break;
  7188. }
  7189. }
  7190. }
  7191. else
  7192. isEmptyFile = TRUE;
  7193. fclose(fptr1);
  7194. if(isEmptyFile == TRUE)
  7195. {
  7196. memset(str, 0, ARRAY_SIZE(str));
  7197. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7198. system(str);
  7199. }
  7200. }
  7201. }// End of while(int k=0; k < ChargePointCount; k++)
  7202. }
  7203. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7204. {
  7205. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7206. for(int k=0; k < ChargeProfileCount; k++)
  7207. {
  7208. fptr1 = fopen(chargingProfiles[k], "r");
  7209. fptr2 = fopen(temp, "w+");
  7210. //Check Charging Profile Count
  7211. while(fscanf(fptr1, "%s", word) != EOF)
  7212. {
  7213. //DEBUG_INFO("word=%s\n",word);
  7214. if(strstr(word, "chargingProfileId")!= NULL)
  7215. {
  7216. n_chargingProfile = n_chargingProfile + 1;
  7217. }
  7218. }
  7219. rewind(fptr1);
  7220. //search Charging Profile Element
  7221. //int i= 0;
  7222. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7223. {
  7224. json_object *tmpProfilee;
  7225. tmpProfilee = json_tokener_parse(sLineWord);
  7226. if(!is_error(tmpProfilee))
  7227. {
  7228. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7229. {
  7230. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7231. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7232. }
  7233. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7234. {
  7235. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7236. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7237. }
  7238. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7239. {
  7240. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7241. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7242. }
  7243. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7244. {
  7245. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7246. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7247. }
  7248. }
  7249. json_object_put(tmpProfilee);
  7250. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7251. {
  7252. //------- not write to fptr2-------//
  7253. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7254. //clearflag = TRUE;
  7255. }
  7256. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7257. {
  7258. //------- not write to fptr2-------//
  7259. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7260. }
  7261. else if(stackLevelIsNULL == TRUE)
  7262. {
  7263. //Clear Whole File
  7264. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7265. clearflag = TRUE;
  7266. break;
  7267. }
  7268. else
  7269. {
  7270. fprintf(fptr2, sLineWord);//writing data into file
  7271. }
  7272. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7273. }
  7274. if(clearflag == TRUE)
  7275. {
  7276. fclose(fptr1);
  7277. fclose(fptr2);
  7278. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7279. system(str);
  7280. // clear temp file
  7281. sprintf(str,"rm -f %s",temp);
  7282. system(str);
  7283. }
  7284. else
  7285. {
  7286. fclose(fptr1);
  7287. fclose(fptr2);
  7288. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7289. system(str);
  7290. resultRename = rename(temp, chargingProfiles[k]);
  7291. if(resultRename == 0)
  7292. {
  7293. DEBUG_INFO("File ChargingProfile renamed successfully");
  7294. }
  7295. else
  7296. {
  7297. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7298. }
  7299. if(comfirmstr[0]== 0)
  7300. {
  7301. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7302. }
  7303. //Check chargingProfile is empty file
  7304. /*------ Read the file ----------------*/
  7305. fptr1=fopen(chargingProfiles[k],"r");
  7306. ch=fgetc(fptr1);
  7307. rewind(fptr1);
  7308. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7309. if(ch!=EOF)
  7310. {
  7311. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7312. {
  7313. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7314. if(sLineWord[0]=='\0')
  7315. {
  7316. isEmptyFile = TRUE;
  7317. break;
  7318. }
  7319. else
  7320. {
  7321. isEmptyFile = FALSE;
  7322. break;
  7323. }
  7324. }
  7325. }
  7326. else
  7327. isEmptyFile = TRUE;
  7328. fclose(fptr1);
  7329. if(isEmptyFile == TRUE)
  7330. {
  7331. memset(str, 0, ARRAY_SIZE(str));
  7332. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7333. system(str);
  7334. }
  7335. /*------- End of reading ---------------*/
  7336. }
  7337. } // while(int k=0; k < ChargeProfileCount; k++)
  7338. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7339. end:
  7340. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7341. {
  7342. if(connectorIdInt == 0)
  7343. {
  7344. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7345. {
  7346. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7347. }
  7348. }
  7349. else
  7350. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7351. }
  7352. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7353. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7354. return result;
  7355. }
  7356. void createFirmwareVersionByDataTransfer(void)
  7357. {
  7358. json_object *FirmwareDataTransfer = json_object_new_object();
  7359. // AC & DC model
  7360. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7361. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7362. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7363. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7364. // DC model
  7365. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7366. {
  7367. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7368. {
  7369. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7370. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7371. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7372. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7373. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7374. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7375. }
  7376. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7377. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7378. {
  7379. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7380. }
  7381. }
  7382. else
  7383. {
  7384. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7393. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7394. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7396. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7397. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7398. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7399. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7400. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7401. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7402. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7403. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7404. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7405. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7406. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7407. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7408. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7409. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7410. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7415. }
  7416. // 4G model
  7417. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7418. {
  7419. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7420. }
  7421. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7422. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7423. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7424. json_object_put(FirmwareDataTransfer);
  7425. }
  7426. int handleDataTransferRequest(char *uuid, char *payload)
  7427. {
  7428. mtrace();
  7429. json_object *response = json_object_new_object();
  7430. int result = FAIL;
  7431. char tempvendorId[255]={0};
  7432. char tempmessageId[50]={0};
  7433. char tempdata[512]={0};
  7434. char message[2048]={0};
  7435. DEBUG_INFO("handleDataTransferRequest...\n");
  7436. if((uuid != NULL) && (payload != NULL))
  7437. {
  7438. json_object *DataTransfer;
  7439. DataTransfer = json_tokener_parse(payload);
  7440. if(!is_error(DataTransfer))
  7441. {
  7442. // Required data
  7443. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7444. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7445. // Optional data
  7446. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7447. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7448. if(json_object_object_get(DataTransfer, "data") != NULL)
  7449. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7450. result = PASS;
  7451. }
  7452. json_object_put(DataTransfer);
  7453. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7454. {
  7455. // Send all moudle firmware version on EVSE
  7456. createFirmwareVersionByDataTransfer();
  7457. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7458. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  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, "ID_Tmate") != NULL)
  7463. {
  7464. system("/usr/bin/run_tmate_restart.sh &");
  7465. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7466. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7467. json_object_put(response);
  7468. }
  7469. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7470. {
  7471. json_object *data;
  7472. data = json_tokener_parse(tempdata);
  7473. if(!is_error(data))
  7474. {
  7475. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7478. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7479. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7480. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7481. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7482. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7483. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7484. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7485. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7486. }
  7487. else
  7488. {
  7489. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7490. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7491. }
  7492. json_object_put(data);
  7493. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7494. json_object_put(response);
  7495. }
  7496. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7497. {
  7498. json_object *data;
  7499. data = json_tokener_parse(tempdata);
  7500. if(!is_error(data))
  7501. {
  7502. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7503. if(json_object_object_get(data, "idToken") != NULL)
  7504. {
  7505. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7506. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7507. }
  7508. if(json_object_object_get(data, "price") != NULL)
  7509. {
  7510. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7511. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7512. }
  7513. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7514. }
  7515. else
  7516. {
  7517. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7518. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7519. }
  7520. json_object_put(data);
  7521. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7522. json_object_put(response);
  7523. }
  7524. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7525. {
  7526. json_object *data;
  7527. data = json_tokener_parse(tempdata);
  7528. if(!is_error(data))
  7529. {
  7530. if(json_object_object_get(data, "txId") != NULL)
  7531. {
  7532. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7533. for(int idx = 0;idx<gunTotalNumber;idx++)
  7534. {
  7535. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7536. {
  7537. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7538. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7539. if(json_object_object_get(data, "description") != NULL)
  7540. {
  7541. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7542. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7543. }
  7544. }
  7545. }
  7546. }
  7547. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7548. }
  7549. else
  7550. {
  7551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7552. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7553. }
  7554. json_object_put(data);
  7555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7556. json_object_put(response);
  7557. }
  7558. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7559. {
  7560. json_object *data;
  7561. data = json_tokener_parse(tempdata);
  7562. if(!is_error(data))
  7563. {
  7564. if(json_object_object_get(data, "txId") != NULL)
  7565. {
  7566. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7567. for(int idx = 0;idx<gunTotalNumber;idx++)
  7568. {
  7569. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7570. {
  7571. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7572. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7573. if(json_object_object_get(data, "description") != NULL)
  7574. {
  7575. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7576. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7577. }
  7578. }
  7579. }
  7580. }
  7581. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7582. }
  7583. else
  7584. {
  7585. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7586. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7587. }
  7588. json_object_put(data);
  7589. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7590. json_object_put(response);
  7591. }
  7592. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7593. {
  7594. json_object *data;
  7595. data = json_tokener_parse(tempdata);
  7596. if(!is_error(data))
  7597. {
  7598. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7599. if(json_object_object_get(data, "Content_Type") != NULL)
  7600. {
  7601. 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))
  7602. {
  7603. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7604. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7605. {
  7606. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7607. }
  7608. }
  7609. else
  7610. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7611. }
  7612. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7613. }
  7614. else
  7615. {
  7616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7617. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7618. }
  7619. json_object_put(data);
  7620. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7621. json_object_put(response);
  7622. }
  7623. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7624. {
  7625. json_object *data;
  7626. data = json_tokener_parse(tempdata);
  7627. if(!is_error(data))
  7628. {
  7629. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7630. if(json_object_object_get(data, "Page_Index") != NULL)
  7631. {
  7632. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7633. }
  7634. if(json_object_object_get(data, "Duration") != NULL)
  7635. {
  7636. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7637. }
  7638. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7639. }
  7640. else
  7641. {
  7642. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7643. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7644. }
  7645. json_object_put(data);
  7646. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7647. json_object_put(response);
  7648. }
  7649. else
  7650. {
  7651. // Can not find valid message id
  7652. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7653. }
  7654. }
  7655. else
  7656. {
  7657. // Payload is null
  7658. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7659. }
  7660. LWS_Send(message);
  7661. return result;
  7662. }
  7663. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7664. {
  7665. mtrace();
  7666. int result = FAIL;
  7667. int connectorIdInt, durationInt;
  7668. char chargingRateUnitStr[4]={0};
  7669. char comfirmstr[20];
  7670. int confirmPeriods = 0;
  7671. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7672. json_object *GetCompositeSchedule;
  7673. GetCompositeSchedule = json_tokener_parse(payload);
  7674. if(!is_error(GetCompositeSchedule))
  7675. {
  7676. // Required data
  7677. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7678. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7679. else
  7680. connectorIdInt = -1;
  7681. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7682. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7683. else
  7684. durationInt = 86400;
  7685. // Optional data
  7686. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7687. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7688. }
  7689. json_object_put(GetCompositeSchedule);
  7690. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7691. if((connectorIdInt == 0) ||
  7692. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7693. {
  7694. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7695. struct StructChargingProfile tmpProfile[1];
  7696. if(strstr(chargingRateUnitStr, "W") != NULL)
  7697. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7698. else
  7699. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7700. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7701. {
  7702. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7703. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7704. }
  7705. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7706. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7707. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7708. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7709. {
  7710. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7711. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7712. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7713. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7714. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7715. {
  7716. confirmPeriods = idx;
  7717. break;
  7718. }
  7719. }
  7720. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7721. {
  7722. confirmPeriods += 1;
  7723. }
  7724. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7725. }
  7726. else
  7727. {
  7728. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7729. }
  7730. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7731. return result;
  7732. }
  7733. int handleGetConfigurationRequest(char *uuid, char *payload)
  7734. {
  7735. mtrace();
  7736. int result = FAIL;
  7737. int MaxKeySupported = 0;
  7738. int n_keys = 0;
  7739. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7740. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7741. json_object *GetConfiguration;
  7742. GetConfiguration = json_tokener_parse(payload);
  7743. if(!is_error(GetConfiguration))
  7744. {
  7745. // Optional data
  7746. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7747. {
  7748. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7749. {
  7750. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7751. n_keys = idx + 1;
  7752. }
  7753. }
  7754. }
  7755. json_object_put(GetConfiguration);
  7756. UnknownKeynum = 0;
  7757. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7758. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7759. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7760. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7761. if(n_keys != 0)
  7762. {
  7763. for(int i=0;i<n_keys;i++)
  7764. {
  7765. getKeyValue(requestKey[i]);
  7766. }
  7767. }
  7768. else
  7769. {
  7770. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7771. getKeyValue("");
  7772. }
  7773. processUnkownKey();
  7774. sendGetConfigurationConfirmation(uuid);
  7775. return result;
  7776. }
  7777. static char fnamePlusPath[100]={0};
  7778. static char fnamePWithNoPath[60]={0};
  7779. void checkUploadLog(void)
  7780. {
  7781. FILE *fp;
  7782. /* Open the command for reading. */
  7783. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7784. if (fp == NULL) {
  7785. printf("Failed to run command\n" );
  7786. exit(1);
  7787. }
  7788. int ftppathlen = 0;
  7789. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7790. int i = 0;
  7791. /* Read the output a line at a time - output it. */
  7792. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7793. if(i==0)
  7794. {
  7795. ftppathlen = strlen(fnamePlusPath);
  7796. printf("%s\n", fnamePlusPath);
  7797. fnamePlusPath[ftppathlen]='\0';
  7798. break;
  7799. }
  7800. i= i+1;
  7801. }
  7802. /* close */
  7803. pclose(fp);
  7804. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7805. {
  7806. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7807. {
  7808. fnamePlusPath[k]='\0';
  7809. }
  7810. }
  7811. i=1;
  7812. //char fname[60]={0};
  7813. while(i < ftppathlen)
  7814. {
  7815. int len=ftppathlen-i;
  7816. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7817. {
  7818. printf("compare '/' all right\n");
  7819. break;
  7820. }
  7821. i=i+1;
  7822. }
  7823. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7824. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7825. fnamePWithNoPath[i+1] = '\0';
  7826. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7827. {
  7828. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7829. {
  7830. fnamePWithNoPath[j]='\0';
  7831. }
  7832. }
  7833. FILE* fp1 = fopen(fnamePlusPath, "r");
  7834. if (fp1)
  7835. {
  7836. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7837. // file exists
  7838. fclose(fp1);
  7839. }
  7840. else
  7841. {
  7842. // file doesn't exist
  7843. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7844. }
  7845. }
  7846. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7847. {
  7848. mtrace();
  7849. int result = FAIL;
  7850. time_t CurrentTime;
  7851. struct tm *tm;
  7852. pthread_t th_Status;
  7853. CurrentTime = time(NULL);
  7854. tm = localtime(&CurrentTime);
  7855. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7856. 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);
  7857. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7858. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7859. return result;
  7860. }
  7861. void* GetDiagnosticsProcess(void* data)
  7862. {
  7863. pthread_detach(pthread_self());
  7864. mtrace();
  7865. int retriesInt=0, retryIntervalInt=0;
  7866. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7867. 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};
  7868. int port=0;
  7869. int isSuccess = FALSE;
  7870. char cmdBuf[2048];
  7871. struct tm *tmNow;
  7872. time_t CurrentTime;
  7873. struct tm tmStart;
  7874. struct tm tmStop;
  7875. CurrentTime = time(NULL);
  7876. tmNow=localtime(&CurrentTime);
  7877. uint16_t targetYear, targetMonth;
  7878. json_object *GetDiagnostics;
  7879. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7880. GetDiagnostics = json_tokener_parse(data);
  7881. if(!is_error(GetDiagnostics))
  7882. {
  7883. // Required data
  7884. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7885. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7886. // Optional data
  7887. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7888. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7889. else
  7890. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7891. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7892. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7893. else
  7894. retryIntervalInt = 30;
  7895. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7896. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7897. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7898. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7899. }
  7900. json_object_put(GetDiagnostics);
  7901. // Pack log to compress file
  7902. 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) &&
  7903. (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))
  7904. {
  7905. // Pack system log
  7906. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7907. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7908. targetYear = tmStart.tm_year;
  7909. targetMonth = tmStart.tm_mon;
  7910. do
  7911. {
  7912. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7913. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7914. if(targetMonth+1>=13)
  7915. {
  7916. targetYear += 1;
  7917. targetMonth = 1;
  7918. }
  7919. else
  7920. {
  7921. targetMonth += 1;
  7922. }
  7923. }while((targetYear < (tmNow->tm_year+1900)) ||
  7924. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7925. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7926. system(cmdBuf);
  7927. // Pack charging & event log
  7928. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7929. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7930. targetYear = tmStart.tm_year;
  7931. targetMonth = tmStart.tm_mon;
  7932. do
  7933. {
  7934. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7935. if(targetMonth+1>=13)
  7936. {
  7937. targetYear += 1;
  7938. targetMonth = 1;
  7939. }
  7940. else
  7941. {
  7942. targetMonth += 1;
  7943. }
  7944. }while((targetYear < (tmNow->tm_year+1900)) ||
  7945. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7946. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7947. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7948. system(cmdBuf);
  7949. // Combine log file
  7950. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7951. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7952. }
  7953. else
  7954. {
  7955. system("exec /root/logPackTools 'log' 6");
  7956. }
  7957. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7958. system(cmdBuf);
  7959. checkUploadLog();
  7960. //****************location*******************/
  7961. if(strcmp(locationstr,"")==0)
  7962. {
  7963. DEBUG_INFO("location is <Empty>!\n");
  7964. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7965. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7966. goto end;
  7967. }
  7968. memset(protocol, 0, ARRAY_SIZE(protocol));
  7969. memset(user, 0, ARRAY_SIZE(user) );
  7970. memset(password, 0, ARRAY_SIZE(password));
  7971. memset(host, 0, ARRAY_SIZE(host));
  7972. memset(path, 0, ARRAY_SIZE(path));
  7973. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7974. memset(host1, 0, ARRAY_SIZE(host1));
  7975. memset(path1, 0, ARRAY_SIZE(path1));
  7976. /*location: ftp://user:password@host:port/path*/
  7977. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7978. if((access(fnamePlusPath,F_OK))!=-1)
  7979. {
  7980. DEBUG_INFO("fnamePlusPath exist.\n");
  7981. }
  7982. else
  7983. {
  7984. DEBUG_INFO("fnamePlusPath not exist!\n");
  7985. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7986. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7987. goto end;
  7988. }
  7989. if(strchr(locationstr,'@')==NULL)
  7990. {
  7991. sscanf(locationstr,
  7992. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7993. protocol, host, &port, path);
  7994. strcpy(user,"anonymous");
  7995. strcpy(password,"");
  7996. }
  7997. else
  7998. {
  7999. //DEBUG_INFO("pch=%s\n", pch);
  8000. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8001. protocol, user, password, host, &port, path);
  8002. }
  8003. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8004. {
  8005. DEBUG_INFO("protocol is not ftp/http ! \n");
  8006. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8007. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8008. goto end;
  8009. }
  8010. if(strncmp(locationstr,"http", 4) == 0)
  8011. {
  8012. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8013. sprintf(ftppath,"/%s", path);
  8014. do
  8015. {
  8016. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8017. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8018. sleep(3);
  8019. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8020. if(!isSuccess)
  8021. {
  8022. DEBUG_INFO("Diagnostics fail.\n");
  8023. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8024. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8025. sleep(retryIntervalInt);
  8026. }
  8027. else
  8028. {
  8029. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8030. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8031. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8032. }
  8033. retriesInt--;
  8034. }while((isSuccess == 0)&&(retriesInt >= 0));
  8035. }
  8036. else
  8037. {
  8038. sscanf(host,"%[^/]%s",host1, path1);
  8039. if(strlen(path) > 0)
  8040. sprintf(ftppath,"/%s", path);
  8041. else
  8042. sprintf(ftppath,"/%s", path1);
  8043. int ftppathlen=strlen(ftppath);
  8044. int i=1;
  8045. char filenametemp[50];
  8046. while(i < ftppathlen)
  8047. {
  8048. int len=ftppathlen-i;
  8049. if(ftppath[len]== 47) // '/' ascll code: 47
  8050. {
  8051. DEBUG_INFO("find '/' all right\n");
  8052. break;
  8053. }
  8054. i=i+1;
  8055. }
  8056. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8057. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8058. filenametemp[i+1] = 0;
  8059. if(port == 0)
  8060. port = 21;
  8061. do
  8062. {
  8063. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8064. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8065. sleep(3);
  8066. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8067. if(!isSuccess)
  8068. {
  8069. DEBUG_INFO("Diagnostics fail.\n");
  8070. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8071. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8072. sleep(retryIntervalInt);
  8073. }
  8074. else
  8075. {
  8076. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8077. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8078. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8079. }
  8080. retriesInt--;
  8081. }while((!isSuccess)&&(retriesInt >= 0));
  8082. }
  8083. end:
  8084. system("rm -f /mnt/*");
  8085. sleep(5);
  8086. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8087. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8088. pthread_exit(NULL);
  8089. }
  8090. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8091. {
  8092. mtrace();
  8093. int result = FAIL;
  8094. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8095. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8096. {
  8097. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8098. localversion = -1;
  8099. }
  8100. else
  8101. {
  8102. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8103. OCPP_getListVerion();
  8104. }
  8105. //from db.OCPP_getListVerion
  8106. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  8107. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8108. sendGetLocalListVersionConfirmation(uuid,"");
  8109. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8110. return result;
  8111. }
  8112. int handleRemoteStartRequest(char *uuid, char *payload)
  8113. {
  8114. mtrace();
  8115. int result = FAIL;
  8116. int connectorIdInt=0;
  8117. int tempIndex = 0;
  8118. int connectorIdIsNULL, chargingProfileIsNULL;
  8119. char comfirmstr[20]={0};
  8120. char cmdBuf[512];
  8121. json_object *RemoteStartTransaction;
  8122. FILE *fp;
  8123. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8124. if(server_pending == TRUE)
  8125. {
  8126. return 0;
  8127. }
  8128. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8129. RemoteStartTransaction = json_tokener_parse(payload);
  8130. if(!is_error(RemoteStartTransaction))
  8131. {
  8132. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8133. {
  8134. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8135. if(connectorIdInt <= gunTotalNumber)
  8136. {
  8137. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8138. // Required data
  8139. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8140. // Optional data
  8141. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8142. {
  8143. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8144. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8145. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8146. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8147. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8148. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8149. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8150. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8151. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8152. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8153. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8154. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8155. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8156. {
  8157. 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")));
  8158. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8159. 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"));
  8160. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8161. 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"));
  8162. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8163. 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")));
  8164. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8165. {
  8166. 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++)
  8167. {
  8168. 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"));
  8169. 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"));
  8170. 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)
  8171. 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"));
  8172. }
  8173. }
  8174. }
  8175. }
  8176. else
  8177. chargingProfileIsNULL = TRUE;
  8178. }
  8179. }
  8180. else
  8181. connectorIdIsNULL = TRUE;
  8182. }
  8183. else
  8184. connectorIdIsNULL = TRUE;
  8185. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8186. {
  8187. DEBUG_WARN("Connector id is NULL\n.");
  8188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8189. goto end;
  8190. }
  8191. /*
  8192. enum _SYSTEM_STATUS
  8193. {
  8194. S_BOOTING = 0,
  8195. S_IDLE, = 1
  8196. S_AUTHORIZING, = 2
  8197. S_REASSIGN_CHECK, = 3
  8198. S_REASSIGN, = 4
  8199. S_PRECHARGE, = 5
  8200. S_PREPARING_FOR_EV, = 6
  8201. S_PREPARING_FOR_EVSE, = 7
  8202. S_CHARGING, = 8
  8203. S_TERMINATING, = 9
  8204. S_COMPLETE, = 10
  8205. S_ALARM, = 11
  8206. S_FAULT = 12
  8207. }
  8208. */
  8209. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8210. {
  8211. //check Transaction active
  8212. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8213. {
  8214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8215. {
  8216. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8217. }
  8218. else
  8219. {
  8220. tempIndex = connectorIdInt -1;
  8221. }
  8222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8223. {
  8224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8225. {
  8226. 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))
  8227. {
  8228. //Reserved
  8229. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8230. }
  8231. 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))
  8232. {
  8233. //Reserved
  8234. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8236. goto end;
  8237. }
  8238. else
  8239. {
  8240. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8241. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8242. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8243. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8244. {
  8245. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8246. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8247. goto end;
  8248. }
  8249. }//END FOR ELSE
  8250. }
  8251. }// END FOR CHAdeMO_QUANTITY
  8252. }
  8253. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8254. {
  8255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8256. {
  8257. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8258. }
  8259. else
  8260. {
  8261. tempIndex = connectorIdInt -1;
  8262. }
  8263. for (int index = 0; index < CCS_QUANTITY; index++)
  8264. {
  8265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8266. {
  8267. 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))
  8268. {
  8269. //Reserved
  8270. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8271. }
  8272. 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))
  8273. {
  8274. //Reserved
  8275. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8277. goto end;
  8278. }
  8279. else
  8280. {
  8281. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8282. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8283. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8284. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8285. {
  8286. DEBUG_WARN("CCS connector not allow start\n.");
  8287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8288. goto end;
  8289. }
  8290. }// END FOR ELSE
  8291. }
  8292. }// END FOR CCS_QUANTITY
  8293. }
  8294. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8295. {
  8296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8297. {
  8298. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8299. }
  8300. else
  8301. {
  8302. tempIndex = connectorIdInt -1;
  8303. }
  8304. for (int index = 0; index < GB_QUANTITY; index++)
  8305. {
  8306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8307. {
  8308. 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))
  8309. {
  8310. //Reserved
  8311. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8312. }
  8313. 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))
  8314. {
  8315. //Reserved
  8316. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8318. goto end;
  8319. }
  8320. else
  8321. {
  8322. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8323. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8324. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8325. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8326. {
  8327. DEBUG_WARN("GB connector not allow start\n.");
  8328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8329. goto end;
  8330. }
  8331. }// END FOR ELSE
  8332. }
  8333. } // END FOR GB_QUANTITY
  8334. }
  8335. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8336. {
  8337. tempIndex = connectorIdInt -1;
  8338. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8339. {
  8340. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8341. {
  8342. 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))
  8343. {
  8344. //Reserved
  8345. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8346. }
  8347. 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))
  8348. {
  8349. //Reserved
  8350. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8352. goto end;
  8353. }
  8354. else
  8355. {
  8356. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8357. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8358. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8359. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8360. {
  8361. DEBUG_WARN("GB connector not allow start\n.");
  8362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8363. goto end;
  8364. }
  8365. }// END FOR ELSE
  8366. }
  8367. } // END FOR GB_QUANTITY
  8368. }
  8369. else
  8370. {
  8371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8372. {
  8373. tempIndex = 2;
  8374. }
  8375. else
  8376. {
  8377. tempIndex = connectorIdInt -1;
  8378. }
  8379. for (int index = 0; index < AC_QUANTITY; index++)
  8380. {
  8381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8382. {
  8383. 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))
  8384. {
  8385. //Reserved
  8386. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8387. }
  8388. 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))
  8389. {
  8390. //Reserved
  8391. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8392. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8393. goto end;
  8394. }
  8395. else
  8396. {
  8397. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8398. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8399. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8400. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8401. {
  8402. DEBUG_WARN("AC connector not allow start\n.");
  8403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8404. goto end;
  8405. }
  8406. }//END FOR ELSE
  8407. }
  8408. }// END FOR AC_QUANTITY
  8409. }
  8410. if(chargingProfileIsNULL == FALSE)
  8411. {
  8412. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8413. {
  8414. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8415. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8416. //memset idTag
  8417. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8418. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8419. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8420. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8421. // Save profile to file
  8422. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8423. system(cmdBuf);
  8424. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8425. fp = fopen(cmdBuf, "w");
  8426. 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));
  8427. fclose(fp);
  8428. }
  8429. else
  8430. {
  8431. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8433. }
  8434. }
  8435. else
  8436. {
  8437. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8439. //memset idTag
  8440. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8441. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8442. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8443. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8444. }
  8445. }
  8446. else
  8447. {
  8448. DEBUG_WARN("Connector id over\n.");
  8449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8450. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8451. }
  8452. end:
  8453. json_object_put(RemoteStartTransaction);
  8454. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8455. {
  8456. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8457. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8458. }
  8459. //OCPP send RemoteStartConfirmation by first.
  8460. sendRemoteStartConfirmation(uuid, comfirmstr);
  8461. return result;
  8462. }
  8463. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8464. {
  8465. mtrace();
  8466. int result = FAIL;
  8467. int match = FALSE;
  8468. int GunNO = 0;
  8469. int tempIndex = 0;
  8470. int transactionIdInt=0;
  8471. int transactionIdIsNULL= TRUE;
  8472. char comfirmstr[20];
  8473. json_object *RemoteStopTransaction;
  8474. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8475. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8476. if(server_pending == TRUE)
  8477. {
  8478. return 0;
  8479. }
  8480. RemoteStopTransaction = json_tokener_parse(payload);
  8481. if(!is_error(RemoteStopTransaction))
  8482. {
  8483. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8484. {
  8485. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8486. transactionIdIsNULL = FALSE;
  8487. }
  8488. }
  8489. json_object_put(RemoteStopTransaction);
  8490. if(transactionIdIsNULL == FALSE)
  8491. {
  8492. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8493. {
  8494. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8495. {
  8496. //check Transaction active
  8497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8498. {
  8499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8500. {
  8501. tempIndex = ((gun_index==2) ? 1: 0);
  8502. }
  8503. else
  8504. {
  8505. tempIndex = gun_index;
  8506. }
  8507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8508. {
  8509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8510. {
  8511. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8512. {
  8513. match = TRUE;
  8514. GunNO = gun_index;
  8515. }
  8516. }
  8517. }// END FOR CHAdeMO_QUANTITY
  8518. }
  8519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8520. {
  8521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8522. {
  8523. tempIndex = ((gun_index==2) ? 1: 0);
  8524. }
  8525. else
  8526. {
  8527. tempIndex = gun_index;
  8528. }
  8529. for (int index = 0; index < CCS_QUANTITY; index++)
  8530. {
  8531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8532. {
  8533. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8534. {
  8535. match = TRUE;
  8536. GunNO = gun_index;
  8537. }
  8538. }
  8539. }// END FOR CCS_QUANTITY
  8540. }
  8541. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8542. {
  8543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8544. {
  8545. tempIndex = ((gun_index==2) ? 1: 0);
  8546. }
  8547. else
  8548. {
  8549. tempIndex = gun_index;
  8550. }
  8551. for (int index = 0; index < GB_QUANTITY; index++)
  8552. {
  8553. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8554. {
  8555. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8556. {
  8557. match = TRUE;
  8558. GunNO = gun_index;
  8559. }
  8560. }
  8561. }// END FOR GB_QUANTITY
  8562. }
  8563. else if(gunType[gun_index] == GUN_TYPE_DO)
  8564. {
  8565. tempIndex = gun_index;
  8566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8567. {
  8568. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8569. {
  8570. 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
  8571. {
  8572. match = TRUE;
  8573. GunNO = gun_index;
  8574. }
  8575. }
  8576. }// END FOR GB_QUANTITY
  8577. }
  8578. else
  8579. {
  8580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8581. {
  8582. tempIndex = 2;
  8583. }
  8584. else
  8585. {
  8586. tempIndex = gun_index;
  8587. }
  8588. for (int index = 0; index < AC_QUANTITY; index++)
  8589. {
  8590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8591. {
  8592. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8593. {
  8594. match = TRUE;
  8595. GunNO = gun_index;
  8596. }
  8597. }
  8598. }// END FOR CHAdeMO_QUANTITY
  8599. } // END FOR AC ELSE
  8600. }// CHECK IF ResponseTransactionId == transactionIdInt
  8601. }//END FOR
  8602. if( match == TRUE)
  8603. {
  8604. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8605. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8606. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8607. }
  8608. else
  8609. {
  8610. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8611. }
  8612. }
  8613. else
  8614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8615. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8616. return result;
  8617. }
  8618. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8619. {
  8620. mtrace();
  8621. int result = FAIL;
  8622. int connectorIdInt=0, reservationIdInt=0;
  8623. int tempIndex = 0;
  8624. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8625. char comfirmstr[20]={0};
  8626. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8627. int c = 0;
  8628. char *loc;
  8629. //char *ptr;
  8630. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8631. strcpy(sstrtemp, stringtrimspace(payload));
  8632. //***(1)connectorId ****/
  8633. c=0;
  8634. loc = strstr(sstrtemp, "connectorId");
  8635. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8636. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8637. {
  8638. sstr[c] = loc[strlen("connectorId")+2+c];
  8639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8640. c++;
  8641. }
  8642. sstr[c] = '\0';
  8643. connectorIdInt = atoi(sstr);
  8644. //***(2)expiryDate ****/
  8645. loc = strstr(sstrtemp, "expiryDate");
  8646. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8647. c = 0;
  8648. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8649. {
  8650. sstr[c] = loc[3+strlen("expiryDate")+c];
  8651. c++;
  8652. }
  8653. sstr[c] = '\0';
  8654. strcpy(expiryDatestr, sstr);
  8655. //***(3)idTag ****/
  8656. loc = strstr(sstrtemp, "idTag");
  8657. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8658. c = 0;
  8659. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8660. {
  8661. sstr[c] = loc[3+strlen("idTag")+c];
  8662. c++;
  8663. }
  8664. sstr[c] = '\0';
  8665. strcpy(idTagstr, sstr);
  8666. //***(4)parentIdTag ****/
  8667. loc = strstr(sstrtemp, "parentIdTag");
  8668. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8669. c = 0;
  8670. if(loc == NULL)
  8671. {
  8672. strcpy(parentIdTagstr, "");
  8673. }
  8674. else
  8675. {
  8676. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8677. {
  8678. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8679. c++;
  8680. }
  8681. sstr[c] = '\0';
  8682. strcpy(parentIdTagstr, sstr);
  8683. }
  8684. //***(5)reservationId ****/
  8685. c=0;
  8686. loc = strstr(sstrtemp, "reservationId");
  8687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8688. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8689. {
  8690. sstr[c] = loc[strlen("reservationId")+2+c];
  8691. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8692. c++;
  8693. }
  8694. sstr[c] = '\0';
  8695. reservationIdInt = atoi(sstr);
  8696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8697. /*
  8698. enum SYSTEM_STATUS
  8699. {
  8700. SYS_MODE_BOOTING = 0,
  8701. SYS_MODE_IDLE = 1,
  8702. SYS_MODE_AUTHORIZING = 2,
  8703. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8704. SYS_MODE_REASSIGN = 4,
  8705. SYS_MODE_PREPARING = 5,
  8706. SYS_MODE_PREPARE_FOR_EV = 6,
  8707. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8708. SYS_MODE_CHARGING = 8,
  8709. SYS_MODE_TERMINATING = 9,
  8710. SYS_MODE_COMPLETE = 10,
  8711. SYS_MODE_ALARM = 11,
  8712. SYS_MODE_FAULT = 12,
  8713. SYS_MODE_RESERVATION = 13,
  8714. SYS_MODE_BOOKING = 14,
  8715. SYS_MODE_MAINTAIN = 15,
  8716. SYS_MODE_DEBUG = 16,
  8717. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8718. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8719. SYS_MODE_UPDATE = 19
  8720. };
  8721. */
  8722. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8723. {
  8724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8725. goto end;
  8726. }
  8727. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8728. {
  8729. //check Transaction active
  8730. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8731. {
  8732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8733. {
  8734. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8735. }
  8736. else
  8737. {
  8738. tempIndex = connectorIdInt -1;
  8739. }
  8740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8741. {
  8742. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8743. {
  8744. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8745. {
  8746. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8747. {
  8748. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8749. {
  8750. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8752. }
  8753. 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'))
  8754. {
  8755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8756. }
  8757. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8758. {
  8759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8760. }
  8761. else
  8762. {
  8763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8764. }
  8765. }
  8766. 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
  8767. {
  8768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8769. }
  8770. }
  8771. else
  8772. {
  8773. //replace reservation
  8774. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8776. }
  8777. }
  8778. } // END FOR CHAdeMO_QUANTITY
  8779. }
  8780. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8781. {
  8782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8783. {
  8784. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8785. }
  8786. else
  8787. {
  8788. tempIndex = connectorIdInt -1;
  8789. }
  8790. for (int index = 0; index < CCS_QUANTITY; index++)
  8791. {
  8792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8793. {
  8794. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8795. {
  8796. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8797. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8798. {
  8799. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8800. {
  8801. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8803. }
  8804. 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'))
  8805. {
  8806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8807. }
  8808. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8809. {
  8810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8811. }
  8812. else
  8813. {
  8814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8815. }
  8816. }
  8817. 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
  8818. {
  8819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8820. }
  8821. }
  8822. else
  8823. {
  8824. //replace reservation
  8825. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8827. }
  8828. }
  8829. } // END FOR CCS_QUANTITY
  8830. }
  8831. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8832. {
  8833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8834. {
  8835. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8836. }
  8837. else
  8838. {
  8839. tempIndex = connectorIdInt -1;
  8840. }
  8841. for (int index = 0; index < GB_QUANTITY; index++)
  8842. {
  8843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8844. {
  8845. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8846. {
  8847. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8848. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8849. {
  8850. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8851. {
  8852. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8854. }
  8855. 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'))
  8856. {
  8857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8858. }
  8859. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8860. {
  8861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8862. }
  8863. else
  8864. {
  8865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8866. }
  8867. }
  8868. 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
  8869. {
  8870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8871. }
  8872. }
  8873. else
  8874. {
  8875. //replace reservation
  8876. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8878. }
  8879. }
  8880. }// END FOR GB_QUANTITY
  8881. }
  8882. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8883. {
  8884. tempIndex = connectorIdInt -1;
  8885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8886. {
  8887. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8888. {
  8889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8890. {
  8891. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8892. 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
  8893. {
  8894. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8895. {
  8896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8898. }
  8899. 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'))
  8900. {
  8901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8902. }
  8903. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8904. {
  8905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8906. }
  8907. else
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8910. }
  8911. }
  8912. 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
  8913. {
  8914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8915. }
  8916. }
  8917. else
  8918. {
  8919. //replace reservation
  8920. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8922. }
  8923. }
  8924. }// END FOR GB_QUANTITY
  8925. }
  8926. else
  8927. {
  8928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8929. {
  8930. tempIndex = 2;
  8931. }
  8932. else
  8933. {
  8934. tempIndex = (connectorIdInt -1);
  8935. }
  8936. for (int index = 0; index < AC_QUANTITY; index++)
  8937. {
  8938. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8939. {
  8940. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8941. {
  8942. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8943. {
  8944. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8945. {
  8946. 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))
  8947. {
  8948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8949. }
  8950. else
  8951. {
  8952. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8954. }
  8955. }
  8956. 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'))
  8957. {
  8958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8959. }
  8960. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8961. {
  8962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8963. }
  8964. else
  8965. {
  8966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8967. }
  8968. }
  8969. 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
  8970. {
  8971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8972. }
  8973. }
  8974. else
  8975. {
  8976. //replace reservation
  8977. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8979. }
  8980. }
  8981. } // END FOR AC_QUANTITY
  8982. }
  8983. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8984. }
  8985. else if(connectorIdInt == 0)
  8986. {
  8987. //check Transaction active
  8988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8989. {
  8990. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8991. {
  8992. 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'))
  8993. {
  8994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8995. goto end;
  8996. }
  8997. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8998. {
  8999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9000. goto end;
  9001. }
  9002. 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
  9003. {
  9004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9005. goto end;
  9006. }
  9007. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9008. {
  9009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9010. goto end;
  9011. }
  9012. }
  9013. }// END FOR CHAdeMO_QUANTITY
  9014. for (int index = 0; index < CCS_QUANTITY; index++)
  9015. {
  9016. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9017. {
  9018. 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'))
  9019. {
  9020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9021. goto end;
  9022. }
  9023. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9024. {
  9025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9026. goto end;
  9027. }
  9028. 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
  9029. {
  9030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9031. goto end;
  9032. }
  9033. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9034. {
  9035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9036. goto end;
  9037. }
  9038. }
  9039. } // END FOR CCS_QUANTITY
  9040. for (int index = 0; index < GB_QUANTITY; index++)
  9041. {
  9042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9043. {
  9044. 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'))
  9045. {
  9046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9047. goto end;
  9048. }
  9049. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9050. {
  9051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9052. goto end;
  9053. }
  9054. 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
  9055. {
  9056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9057. goto end;
  9058. }
  9059. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9060. {
  9061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9062. goto end;
  9063. }
  9064. }
  9065. } // END FOR GB_QUANTITY
  9066. for (int index = 0; index < AC_QUANTITY; index++)
  9067. {
  9068. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9069. {
  9070. 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'))
  9071. {
  9072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9073. goto end;
  9074. }
  9075. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9076. {
  9077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9078. goto end;
  9079. }
  9080. 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
  9081. {
  9082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9083. goto end;
  9084. }
  9085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9086. {
  9087. 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))
  9088. {
  9089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9090. goto end;
  9091. }
  9092. }
  9093. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9094. {
  9095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9096. goto end;
  9097. }
  9098. }
  9099. }// END FOR AC_QUANTITY
  9100. //The connectorId is 0
  9101. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9103. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9104. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9105. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9106. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9107. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9108. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9109. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9110. result = TRUE;
  9111. return result;
  9112. }
  9113. else
  9114. {
  9115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9116. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9117. }
  9118. if(strcmp(comfirmstr,"Accepted") == 0)
  9119. {
  9120. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9121. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9122. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9123. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9124. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9125. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9126. result = TRUE;
  9127. return result;
  9128. }
  9129. end:
  9130. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9131. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9132. return result;
  9133. }
  9134. int handleResetRequest(char *uuid, char *payload)
  9135. {
  9136. mtrace();
  9137. int result = FAIL;
  9138. char sstr[10]={0},sstrtemp[30]={ 0 };
  9139. char typestr[10]={0};
  9140. char comfirmstr[20]={0};
  9141. int c = 0;
  9142. char *loc;
  9143. DEBUG_INFO("handleResetRequest...\n");
  9144. strcpy(sstrtemp, stringtrimspace(payload));
  9145. loc = strstr(sstrtemp, "type");
  9146. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9147. c = 0;
  9148. while (loc[3+strlen("type")+c] != '\"')
  9149. {
  9150. sstr[c] = loc[3+strlen("type")+c];
  9151. c++;
  9152. }
  9153. sstr[c] = '\0';
  9154. strcpy(typestr,sstr);
  9155. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9156. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9157. {
  9158. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9159. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9160. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9161. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9162. }
  9163. else
  9164. {
  9165. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9166. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9167. result = PASS;
  9168. }
  9169. sendResetConfirmation(uuid, comfirmstr);
  9170. return result;
  9171. }
  9172. int handleSendLocalListRequest(char *uuid, char *payload)
  9173. {
  9174. mtrace();
  9175. int result = FAIL;
  9176. int listVersionInt;
  9177. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9178. char listsearch[]="listVersion";
  9179. char updateTypesearch[]="updateType";
  9180. char localAuthorizationListsearch[]="localAuthorizationList";
  9181. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9182. char CardList[500][160]={0};
  9183. char updateTypestr[15]={0};
  9184. char idTagstr[20]={0};
  9185. char parentIdTag[20]={0};
  9186. char expiryDate[30]={0};
  9187. char idTagstatus[16]={0};
  9188. int c = 0;
  9189. int i = 0;
  9190. char *delim1 = "}";
  9191. char * pch;
  9192. char *loc;
  9193. //char *ptr;
  9194. char comfirmstr[20];
  9195. //int n_localAuthorizations = 0;
  9196. int checkState_Faulted = FALSE;
  9197. DEBUG_INFO("handleSendLocalListRequest...\n");
  9198. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9199. {
  9200. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9201. goto end;
  9202. }
  9203. //check Charge Point state
  9204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9205. {
  9206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9207. {
  9208. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9209. }
  9210. }
  9211. for (int index = 0; index < CCS_QUANTITY; index++)
  9212. {
  9213. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9214. {
  9215. checkState_Faulted = TRUE; //OCPP Status
  9216. }
  9217. }
  9218. for (int index = 0; index < GB_QUANTITY; index++)
  9219. {
  9220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9221. {
  9222. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9223. }
  9224. }
  9225. //check Charge Point state
  9226. for (int index = 0; index < AC_QUANTITY; index++)
  9227. {
  9228. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9229. {
  9230. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9231. }
  9232. }
  9233. if(checkState_Faulted == TRUE)
  9234. {
  9235. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9236. goto end;
  9237. }
  9238. //Filter payload space
  9239. strcpy(sstrtemp, stringtrimspace(payload));
  9240. //listVersion
  9241. c = 0;
  9242. loc = strstr(sstrtemp, listsearch);
  9243. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9244. {
  9245. sstr[c] = loc[strlen("listVersion")+2+c];
  9246. c++;
  9247. }
  9248. sstr[c] = '\0';
  9249. listVersionInt = atoi(sstr);
  9250. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9251. //updateType
  9252. loc = strstr(sstrtemp, updateTypesearch);
  9253. c = 0;
  9254. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9255. {
  9256. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9257. c++;
  9258. }
  9259. sstr[c] = '\0';
  9260. strcpy(updateTypestr, sstr);
  9261. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9262. //localAuthorizationList
  9263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9264. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9265. if(loc != NULL) // localAuthorizationList is not NULL
  9266. {
  9267. //Check UpdateType
  9268. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9269. {
  9270. //Local list full update
  9271. printf("Local list full update.\n");
  9272. OCPP_getListVerion();
  9273. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9274. {
  9275. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9276. goto end;
  9277. }
  9278. OCPP_cleanLocalList();
  9279. }
  9280. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9281. {
  9282. //Local list different update
  9283. printf("Local list different update.\n");
  9284. OCPP_getListVerion();
  9285. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9286. {
  9287. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9288. goto end;
  9289. }
  9290. }
  9291. else
  9292. {
  9293. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9294. goto end;
  9295. }
  9296. c = 0;
  9297. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9298. {
  9299. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9301. c++;
  9302. }
  9303. sstr[c] = '\0';
  9304. //DEBUG_INFO("sstr=%s\n", sstr);
  9305. //parsing strings to words
  9306. i = 0;
  9307. pch = strtok(sstr,delim1);
  9308. while (pch != NULL)
  9309. {
  9310. strcpy(CardList[i], pch);
  9311. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9312. pch = strtok (NULL, delim1);
  9313. i = i + 1;
  9314. }
  9315. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9316. //local Authorizations List Numbers
  9317. //n_localAuthorizations = i;
  9318. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9319. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9320. c= 0;
  9321. while(c < i) // i is CardList Number
  9322. {
  9323. //Search "IdToken"
  9324. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9325. loc = strstr(CardList[c], "idTag");
  9326. int j = 0;
  9327. while (loc[3+strlen("idTag")+j] != '\"')
  9328. {
  9329. sstr[j] = loc[3+strlen("idTag")+j];
  9330. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9331. j++;
  9332. }
  9333. sstr[j] = '\0';
  9334. strcpy(idTagstr, sstr);
  9335. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9336. //Search "expiryDate"
  9337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9338. loc = strstr(CardList[c], "expiryDate");
  9339. j = 0;
  9340. if(loc != NULL)
  9341. {
  9342. while (loc[3+strlen("expiryDate")+j] != '\"')
  9343. {
  9344. sstr[j] = loc[3+strlen("expiryDate")+j];
  9345. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9346. j++;
  9347. }
  9348. sstr[j] = '\0';
  9349. strcpy(expiryDate, sstr);
  9350. }
  9351. else
  9352. {
  9353. strcpy(expiryDate, "");
  9354. }
  9355. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9356. //Search "parentIdTag"
  9357. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9358. loc = strstr(CardList[c], "parentIdTag");
  9359. j = 0;
  9360. if(loc != NULL)
  9361. {
  9362. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9363. {
  9364. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9365. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9366. j++;
  9367. }
  9368. sstr[j] = '\0';
  9369. strcpy(parentIdTag, sstr);
  9370. }
  9371. else
  9372. {
  9373. strcpy(parentIdTag, "");
  9374. }
  9375. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9376. //Search "status"
  9377. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9378. loc = strstr(CardList[c], "status");
  9379. j = 0;
  9380. while (loc[3+strlen("status")+j] != '\"')
  9381. {
  9382. sstr[j] = loc[3+strlen("status")+j];
  9383. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9384. j++;
  9385. }
  9386. sstr[j] = '\0';
  9387. strcpy(idTagstatus, sstr);
  9388. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9389. OCPP_getIdTagFromLocalList(idTagstr);
  9390. //OCPP_getIdTagFromLocalList("test"); For Test
  9391. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9392. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9393. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9394. {
  9395. //Local list full update
  9396. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9397. // update list
  9398. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9399. //DEBUG_INFO("Local list full update. 1\n");
  9400. //OCPP_get_TableAuthlocalAllData();
  9401. //DEBUG_INFO("Local list full update. 2\n");
  9402. }
  9403. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9404. {
  9405. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9406. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9407. }
  9408. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9409. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9410. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9411. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9412. c++;
  9413. }
  9414. }
  9415. else
  9416. {
  9417. //Check UpdateType
  9418. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9419. {
  9420. //Local list full update
  9421. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9422. OCPP_cleanLocalList();
  9423. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9424. goto end;
  9425. }
  9426. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9427. {
  9428. //Local list different update
  9429. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9430. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9431. goto end;
  9432. }
  9433. }
  9434. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9435. end:
  9436. sendSendLocalListConfirmation(uuid, comfirmstr);
  9437. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9438. return result;
  9439. }
  9440. #define MAX 200
  9441. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9442. {
  9443. mtrace();
  9444. int result = FAIL;
  9445. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9446. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9447. char chargingProfilePurposeStr[30]={0};
  9448. char chargingProfileKindStr[16]={0};
  9449. char recurrencyKindStr[10]={0};
  9450. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9451. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9452. int chargingSchedulePeriodCount = 0;
  9453. char comfirmstr[20]={0};
  9454. int meet= FALSE;
  9455. FILE *fptr1;
  9456. char filename[MAX]={0};
  9457. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9458. char rmFileCmd[50]={0};
  9459. char tempchargingProfilePurposeStr[30]={0};
  9460. char word[1600]={0};
  9461. int n_chargingProfile = 0;
  9462. json_object *SetChargingProfile;
  9463. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9464. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9465. SetChargingProfile = json_tokener_parse(payload);
  9466. if(!is_error(SetChargingProfile))
  9467. {
  9468. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9469. {
  9470. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9471. if(connectorIdInt == 0)
  9472. {
  9473. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9474. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9475. }
  9476. else
  9477. {
  9478. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9479. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9480. }
  9481. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9482. }
  9483. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9484. {
  9485. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9486. {
  9487. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9489. {
  9490. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9491. }
  9492. else
  9493. {
  9494. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9495. }
  9496. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9497. }
  9498. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9499. {
  9500. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9501. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9502. {
  9503. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9504. }
  9505. else
  9506. {
  9507. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9508. }
  9509. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9510. }
  9511. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9512. {
  9513. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9514. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9515. {
  9516. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9517. }
  9518. else
  9519. {
  9520. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9521. }
  9522. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9523. }
  9524. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9525. {
  9526. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9527. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9528. {
  9529. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9530. }
  9531. else
  9532. {
  9533. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9534. }
  9535. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9536. }
  9537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9538. {
  9539. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9541. {
  9542. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9543. }
  9544. else
  9545. {
  9546. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9547. }
  9548. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9549. }
  9550. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9551. {
  9552. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9554. {
  9555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9556. }
  9557. else
  9558. {
  9559. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9560. }
  9561. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9562. }
  9563. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9564. {
  9565. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9566. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9567. {
  9568. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9569. }
  9570. else
  9571. {
  9572. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9573. }
  9574. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9575. }
  9576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9577. {
  9578. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9580. {
  9581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9582. }
  9583. else
  9584. {
  9585. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9586. }
  9587. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9588. }
  9589. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9590. {
  9591. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9592. {
  9593. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9595. {
  9596. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9597. }
  9598. else
  9599. {
  9600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9601. }
  9602. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9603. }
  9604. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9605. {
  9606. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9607. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9608. {
  9609. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9610. }
  9611. else
  9612. {
  9613. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9614. }
  9615. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9616. }
  9617. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9618. {
  9619. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9620. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9621. {
  9622. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9623. }
  9624. else
  9625. {
  9626. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9627. }
  9628. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9629. }
  9630. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9631. {
  9632. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9633. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9634. {
  9635. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9636. }
  9637. else
  9638. {
  9639. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9640. }
  9641. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9642. }
  9643. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9644. {
  9645. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9646. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9647. if(chargingSchedulePeriodCount <= 10)
  9648. {
  9649. 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++)
  9650. {
  9651. 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)
  9652. {
  9653. 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"));
  9654. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9655. {
  9656. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9657. }
  9658. else
  9659. {
  9660. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9661. }
  9662. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9663. }
  9664. 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)
  9665. {
  9666. 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"));
  9667. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9668. {
  9669. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9670. }
  9671. else
  9672. {
  9673. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9674. }
  9675. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9676. }
  9677. 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)
  9678. {
  9679. 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"));
  9680. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9681. {
  9682. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9683. }
  9684. else
  9685. {
  9686. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9687. }
  9688. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9689. }
  9690. }
  9691. }
  9692. }
  9693. }
  9694. }
  9695. }
  9696. json_object_put(SetChargingProfile);
  9697. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9698. {
  9699. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9700. goto end;
  9701. }
  9702. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9703. {
  9704. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9705. if(connectorIdInt != 0)
  9706. {
  9707. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9708. goto end;
  9709. }
  9710. strcpy(filename, ChargePointMaxProfile_JSON );
  9711. fptr1 = fopen(filename, "r");
  9712. if (!fptr1)
  9713. {
  9714. //file not exist
  9715. DEBUG_INFO("Unable to open the input file!!\n");
  9716. fptr1 = fopen(filename, "w+");
  9717. }
  9718. else
  9719. {
  9720. //Check Charging Profile Count
  9721. while(fscanf(fptr1, "%s", word) != EOF)
  9722. {
  9723. //DEBUG_INFO("word=%s\n",word);
  9724. if(strstr(word, "chargingProfileId")!= NULL)
  9725. {
  9726. //DEBUG_INFO("test chargingProfileId \n");
  9727. n_chargingProfile = n_chargingProfile + 1;
  9728. //DEBUG_INFO("chargingProfileId Found\n");
  9729. }
  9730. }
  9731. }
  9732. fclose(fptr1);
  9733. }
  9734. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9735. {
  9736. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9737. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9738. {
  9739. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9740. goto end;
  9741. }
  9742. memset(filename, 0, ARRAY_SIZE(filename));
  9743. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9744. fptr1 = fopen(filename, "r");
  9745. if (!fptr1)
  9746. {
  9747. //file not exist
  9748. //DEBUG_INFO("Unable to open the input file!!\n");
  9749. fptr1 = fopen(filename, "w+");
  9750. }
  9751. else
  9752. {
  9753. //Check Charging Profile Count
  9754. while(fscanf(fptr1, "%s", word) != EOF)
  9755. {
  9756. //DEBUG_INFO("word=%s\n",word);
  9757. if(strstr(word, "chargingProfileId")!= NULL)
  9758. {
  9759. //DEBUG_INFO("test chargingProfileId \n");
  9760. n_chargingProfile = n_chargingProfile + 1;
  9761. //DEBUG_INFO("chargingProfileId Found\n");
  9762. }
  9763. }
  9764. }
  9765. fclose(fptr1);
  9766. }
  9767. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9768. {
  9769. //printf("set chargingProfile 1-4\n");
  9770. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9771. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9772. if(connectorIdInt == 0)
  9773. {
  9774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9775. goto end;
  9776. }
  9777. int tempIndex = 0;
  9778. //check Transaction active
  9779. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9780. {
  9781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9782. {
  9783. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9784. }
  9785. else
  9786. {
  9787. tempIndex = connectorIdInt -1;
  9788. }
  9789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9790. {
  9791. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9792. {
  9793. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9794. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9795. {
  9796. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9797. {
  9798. meet = TRUE;
  9799. break;
  9800. }
  9801. }
  9802. }
  9803. }
  9804. }
  9805. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9806. {
  9807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9808. {
  9809. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9810. }
  9811. else
  9812. {
  9813. tempIndex = connectorIdInt -1;
  9814. }
  9815. for (int index = 0; index < CCS_QUANTITY; index++)
  9816. {
  9817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9818. {
  9819. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9820. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9821. {
  9822. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9823. {
  9824. meet = TRUE;
  9825. break;
  9826. }
  9827. }
  9828. }
  9829. }
  9830. }
  9831. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9832. {
  9833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9834. {
  9835. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9836. }
  9837. else
  9838. {
  9839. tempIndex = connectorIdInt -1;
  9840. }
  9841. for (int index = 0; index < GB_QUANTITY; index++)
  9842. {
  9843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9844. {
  9845. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9846. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9847. {
  9848. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9849. {
  9850. meet = TRUE;
  9851. break;
  9852. }
  9853. }
  9854. }
  9855. }
  9856. }
  9857. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9858. {
  9859. tempIndex = connectorIdInt -1;
  9860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9861. {
  9862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9863. {
  9864. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9865. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9866. {
  9867. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9868. {
  9869. meet = TRUE;
  9870. break;
  9871. }
  9872. }
  9873. }
  9874. }
  9875. }
  9876. else
  9877. {
  9878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9879. {
  9880. tempIndex = 2;
  9881. }
  9882. else
  9883. {
  9884. tempIndex = (connectorIdInt -1);
  9885. }
  9886. for (int index = 0; index < AC_QUANTITY; index++)
  9887. {
  9888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9889. {
  9890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9891. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9892. {
  9893. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9894. {
  9895. meet = TRUE;
  9896. break;
  9897. }
  9898. }
  9899. }
  9900. }
  9901. }
  9902. //check Transaction active
  9903. if(meet == FALSE)
  9904. {
  9905. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9906. goto end;
  9907. }
  9908. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9909. {
  9910. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9911. goto end;
  9912. }
  9913. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9914. fptr1 = fopen(filename, "r");
  9915. if (!fptr1)
  9916. {
  9917. //file not exist
  9918. DEBUG_INFO("Unable to open the input file!!\n");
  9919. fptr1 = fopen(filename, "w+");
  9920. }
  9921. else
  9922. {
  9923. //Check Charging Profile Count
  9924. while(fscanf(fptr1, "%s", word) != EOF)
  9925. {
  9926. //DEBUG_INFO("word=%s\n",word);
  9927. if(strstr(word, "chargingProfileId")!= NULL)
  9928. {
  9929. //DEBUG_INFO("test chargingProfileId \n");
  9930. n_chargingProfile = n_chargingProfile + 1;
  9931. //DEBUG_INFO("chargingProfileId Found\n");
  9932. }
  9933. }
  9934. }
  9935. fclose(fptr1);
  9936. }
  9937. // Check ChargeProfileMaxStackLevel
  9938. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9939. {
  9940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9941. goto end;
  9942. }
  9943. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9944. {
  9945. int i = 0;
  9946. char fnametemp[200]={0};
  9947. n_chargingProfile = 0;
  9948. //Check ChargePointMaxProfile.json exit
  9949. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9950. {
  9951. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9952. //Check Charging Profile Count
  9953. while(fscanf(fptr1, "%s", word) != EOF)
  9954. {
  9955. //DEBUG_INFO("word=%s\n",word);
  9956. if(strstr(word, "chargingProfileId")!= NULL)
  9957. {
  9958. //DEBUG_INFO("test chargingProfileId \n");
  9959. n_chargingProfile = n_chargingProfile + 1;
  9960. i = i + 1;
  9961. //DEBUG_INFO("chargingProfileId Found\n");
  9962. }
  9963. memset(word, 0, ARRAY_SIZE(word));
  9964. }
  9965. fclose(fptr1);
  9966. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9967. }
  9968. //Check TxDefaultProfile_0.json exit
  9969. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9970. {
  9971. i = 0;
  9972. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9973. //Check Charging Profile Count
  9974. while(fscanf(fptr1, "%s", word) != EOF)
  9975. {
  9976. //DEBUG_INFO("word=%s\n",word);
  9977. if(strstr(word, "chargingProfileId")!= NULL)
  9978. {
  9979. //DEBUG_INFO("test chargingProfileId \n");
  9980. n_chargingProfile = n_chargingProfile + 1;
  9981. i = i + 1;
  9982. //DEBUG_INFO("chargingProfileId Found\n");
  9983. }
  9984. memset(word, 0, ARRAY_SIZE(word));
  9985. }
  9986. fclose(fptr1);
  9987. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9988. }
  9989. //Check TxDefaultProfile_%d.json
  9990. for(int j=1; j <= gunTotalNumber; j++)
  9991. {
  9992. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9993. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9994. if((access(fnametemp,F_OK))!=-1)
  9995. {
  9996. i = 0;
  9997. fptr1 = fopen(fnametemp, "r");
  9998. //Check Charging Profile Count
  9999. while(fscanf(fptr1, "%s", word) != EOF)
  10000. {
  10001. //DEBUG_INFO("word=%s\n",word);
  10002. if(strstr(word, "chargingProfileId")!= NULL)
  10003. {
  10004. //DEBUG_INFO("test chargingProfileId \n");
  10005. n_chargingProfile = n_chargingProfile + 1;
  10006. i = i + 1;
  10007. //DEBUG_INFO("chargingProfileId Found\n");
  10008. }
  10009. memset(word, 0, ARRAY_SIZE(word));
  10010. }
  10011. fclose(fptr1);
  10012. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10013. }
  10014. }
  10015. //Check TxProfile_%d.json
  10016. for(int j=1; j <= gunTotalNumber; j++)
  10017. {
  10018. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10019. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10020. if((access(fnametemp,F_OK))!=-1)
  10021. {
  10022. i = 0;
  10023. fptr1 = fopen(fnametemp, "r");
  10024. //Check Charging Profile Count
  10025. while(fscanf(fptr1, "%s", word) != EOF)
  10026. {
  10027. //DEBUG_INFO("word=%s\n",word);
  10028. if(strstr(word, "chargingProfileId")!= NULL)
  10029. {
  10030. //DEBUG_INFO("test chargingProfileId \n");
  10031. n_chargingProfile = n_chargingProfile + 1;
  10032. i = i + 1;
  10033. //DEBUG_INFO("chargingProfileId Found\n");
  10034. }
  10035. memset(word, 0, ARRAY_SIZE(word));
  10036. }
  10037. fclose(fptr1);
  10038. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10039. }
  10040. }
  10041. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10042. {
  10043. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10044. goto end;
  10045. }
  10046. }
  10047. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10048. //**********************************Write to File********************************************************/
  10049. FILE *infile;
  10050. FILE *outfile;
  10051. infile = fopen (filename, "r");
  10052. outfile = fopen (tempfile, "w");
  10053. int d =0;
  10054. d = fgetc(infile);
  10055. rewind(infile);
  10056. if(d == EOF)
  10057. {
  10058. // Profile is empty
  10059. fprintf(outfile,"%s\n",payload);
  10060. fclose(infile);
  10061. fclose(outfile);
  10062. sprintf(rmFileCmd,"rm -f %s",filename);
  10063. system(rmFileCmd);
  10064. rename(tempfile, filename);
  10065. }
  10066. else
  10067. {
  10068. // Profile is not empty
  10069. char buf[2048]={0};
  10070. int ChargingProfileAdded = FALSE;
  10071. while (fgets(buf, sizeof(buf), infile) != NULL)
  10072. {
  10073. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10074. json_object *tmpChargingProfile;
  10075. tmpChargingProfile = json_tokener_parse(buf);
  10076. if(!is_error(SetChargingProfile))
  10077. {
  10078. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10079. {
  10080. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10081. }
  10082. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10083. {
  10084. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10085. {
  10086. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10087. }
  10088. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10089. {
  10090. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10091. }
  10092. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10093. {
  10094. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10095. }
  10096. }
  10097. }
  10098. json_object_put(tmpChargingProfile);
  10099. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10100. {
  10101. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10102. {
  10103. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10104. if(ChargingProfileAdded == FALSE)
  10105. {
  10106. fprintf(outfile,"%s\n",payload);
  10107. ChargingProfileAdded = TRUE;
  10108. }
  10109. }
  10110. else
  10111. {
  10112. if(tempstackLevelInt < stackLevelInt)
  10113. {
  10114. if(ChargingProfileAdded == FALSE)
  10115. {
  10116. fprintf(outfile,"%s\n",buf);
  10117. fprintf(outfile,"%s\n",payload);
  10118. ChargingProfileAdded = TRUE;
  10119. }
  10120. else
  10121. {
  10122. fprintf(outfile,"%s\n",buf);
  10123. }
  10124. }
  10125. else
  10126. {
  10127. if(ChargingProfileAdded == FALSE)
  10128. {
  10129. fprintf(outfile,"%s\n",buf);
  10130. fprintf(outfile,"%s\n",payload);
  10131. ChargingProfileAdded = TRUE;
  10132. }
  10133. else
  10134. {
  10135. fprintf(outfile,"%s\n",buf);
  10136. }
  10137. }
  10138. }
  10139. }
  10140. else
  10141. {
  10142. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10143. {
  10144. if(ChargingProfileAdded == FALSE)
  10145. {
  10146. fprintf(outfile,"%s\n",buf);
  10147. fprintf(outfile,"%s\n",payload);
  10148. ChargingProfileAdded = TRUE;
  10149. }
  10150. else
  10151. {
  10152. fprintf(outfile,"%s\n",buf);
  10153. }
  10154. }
  10155. else if(tempstackLevelInt < stackLevelInt)
  10156. {
  10157. if(ChargingProfileAdded == FALSE)
  10158. {
  10159. fprintf(outfile,"%s\n",buf);
  10160. fprintf(outfile,"%s\n",payload);
  10161. ChargingProfileAdded = TRUE;
  10162. }
  10163. else
  10164. {
  10165. fprintf(outfile,"%s\n",buf);
  10166. }
  10167. }
  10168. else
  10169. {
  10170. if(ChargingProfileAdded == FALSE)
  10171. {
  10172. fprintf(outfile,"%s\n",buf);
  10173. fprintf(outfile,"%s\n",payload);
  10174. ChargingProfileAdded = TRUE;
  10175. }
  10176. else
  10177. {
  10178. fprintf(outfile,"%s\n",buf);
  10179. }
  10180. }
  10181. }
  10182. } // end of while loop
  10183. fclose(infile);
  10184. fclose(outfile);
  10185. sprintf(rmFileCmd,"rm -f %s",filename);
  10186. system(rmFileCmd);
  10187. rename(tempfile, filename);
  10188. }
  10189. sleep(1);
  10190. result = TRUE;
  10191. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10192. end:
  10193. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10194. {
  10195. if(connectorIdInt == 0)
  10196. {
  10197. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10198. {
  10199. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10200. }
  10201. }
  10202. else
  10203. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10204. }
  10205. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10206. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10207. return result;
  10208. }
  10209. int handleTriggerMessageRequest(char *uuid, char *payload)
  10210. {
  10211. mtrace();
  10212. int result = FAIL;
  10213. int connectorIdIsNULL = FALSE;
  10214. int connectorIdInt =0;
  10215. char sstr[40]={0},sstrtemp[100]={ 0 };
  10216. char requestedMessagestr[40]={0};
  10217. char comfirmstr[20]={0};
  10218. int c = 0;
  10219. char *loc;
  10220. DEBUG_INFO("handleTriggerMessageRequest\n");
  10221. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10222. strcpy(sstrtemp, stringtrimspace(payload));
  10223. c = 0;
  10224. loc = strstr(sstrtemp, "requestedMessage");
  10225. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10226. {
  10227. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10228. c++;
  10229. }
  10230. sstr[c] = '\0';
  10231. strcpy(requestedMessagestr, sstr);
  10232. c = 0;
  10233. loc = strstr(sstrtemp, "connectorId");
  10234. if(loc == NULL)
  10235. {
  10236. connectorIdIsNULL = TRUE;
  10237. }
  10238. else
  10239. {
  10240. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10241. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10242. {
  10243. sstr[c] = loc[strlen("connectorId")+2+c];
  10244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10245. c++;
  10246. }
  10247. sstr[c] = '\0';
  10248. connectorIdInt = atoi(sstr);
  10249. }
  10250. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10251. {
  10252. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10253. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10254. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10255. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10256. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10257. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10258. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10259. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10260. {
  10261. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10262. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10263. return TRUE;
  10264. }
  10265. else
  10266. {
  10267. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10268. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10269. }
  10270. }
  10271. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10272. {
  10273. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10274. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10275. return TRUE;
  10276. }
  10277. //==========================
  10278. // Trigger message
  10279. //==========================
  10280. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10281. {
  10282. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10283. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10284. {
  10285. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10286. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10287. }
  10288. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10289. }
  10290. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10291. {
  10292. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10293. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10294. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10295. }
  10296. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10297. {
  10298. //sendBootNotificationRequest();
  10299. server_sign = FALSE;
  10300. }
  10301. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10302. {
  10303. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10304. }
  10305. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10306. {
  10307. if(connectorIdIsNULL == FALSE)
  10308. {
  10309. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10310. {
  10311. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10312. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10313. }
  10314. }
  10315. else
  10316. {
  10317. for(int idx=0;idx< gunTotalNumber;idx++)
  10318. {
  10319. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10320. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10321. }
  10322. }
  10323. }
  10324. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10325. {
  10326. if(connectorIdIsNULL == FALSE)
  10327. {
  10328. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10329. {
  10330. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10331. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10332. }
  10333. }
  10334. else
  10335. {
  10336. for(int idx=0;idx< gunTotalNumber;idx++)
  10337. {
  10338. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10339. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10340. }
  10341. }
  10342. }
  10343. return result;
  10344. }
  10345. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10346. {
  10347. mtrace();
  10348. int result = FAIL;
  10349. int connectorIdInt =0;
  10350. char comfirmstr[20]={0};
  10351. int tempIndex = 0;
  10352. json_object *UnlockConnector;
  10353. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10354. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10355. UnlockConnector = json_tokener_parse(payload);
  10356. if(!is_error(UnlockConnector))
  10357. {
  10358. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10359. {
  10360. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10361. }
  10362. }
  10363. json_object_put(UnlockConnector);
  10364. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10365. if(gunTotalNumber == 0)
  10366. {
  10367. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10368. goto end;
  10369. }
  10370. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10371. {
  10372. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10373. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10374. goto end;
  10375. }
  10376. else
  10377. {
  10378. //check Transaction active
  10379. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10380. {
  10381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10382. {
  10383. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10384. }
  10385. else
  10386. {
  10387. tempIndex = connectorIdInt -1;
  10388. }
  10389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10390. {
  10391. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10392. {
  10393. //stop Transaction
  10394. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10395. }
  10396. }
  10397. }
  10398. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10399. {
  10400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10401. {
  10402. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10403. }
  10404. else
  10405. {
  10406. tempIndex = connectorIdInt -1;
  10407. }
  10408. for (int index = 0; index < CCS_QUANTITY; index++)
  10409. {
  10410. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10411. {
  10412. //stop Transaction
  10413. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10414. }
  10415. }
  10416. }
  10417. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10418. {
  10419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10420. {
  10421. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10422. }
  10423. else
  10424. {
  10425. tempIndex = connectorIdInt -1;
  10426. }
  10427. for (int index = 0; index < GB_QUANTITY; index++)
  10428. {
  10429. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10430. {
  10431. //stop Transaction
  10432. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10433. }
  10434. }
  10435. }
  10436. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10437. {
  10438. tempIndex = connectorIdInt -1;
  10439. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10440. {
  10441. 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)))
  10442. {
  10443. //stop Transaction
  10444. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10445. }
  10446. }
  10447. }
  10448. else
  10449. {
  10450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10451. {
  10452. tempIndex = 2;
  10453. }
  10454. else
  10455. {
  10456. tempIndex = connectorIdInt-1;
  10457. }
  10458. for (int index = 0; index < AC_QUANTITY; index++)
  10459. {
  10460. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10461. {
  10462. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10463. }
  10464. }
  10465. }
  10466. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10467. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10468. result = TRUE;
  10469. return result;
  10470. }
  10471. end:
  10472. //json_object_put(obj); --- remove temporally
  10473. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10474. return result;
  10475. }
  10476. static char UpdateFirmwarepayloadData[300]={0};
  10477. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10478. {
  10479. mtrace();
  10480. int result = FAIL;
  10481. pthread_t t;
  10482. sendUpdateFirmwareConfirmation(uuid);
  10483. memset(UpdateFirmwarepayloadData, 0, 300);
  10484. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10485. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10486. ////pthread_join(t, NULL); //
  10487. //pthread_detach(t);
  10488. //sendUpdateFirmwareConfirmation(uuid);
  10489. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10490. return result;
  10491. }
  10492. void *UpdateFirmwareProcess(void *data)
  10493. {
  10494. pthread_detach(pthread_self());
  10495. mtrace();
  10496. int retriesInt =0, retryIntervalInt=0;
  10497. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10498. int port=0;
  10499. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10500. int isSuccess = 0;
  10501. char ftpbuf[1024];
  10502. char temp[1024];
  10503. char * pch;
  10504. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10505. json_object *UpdateFirmware;
  10506. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10507. if(!is_error(UpdateFirmware))
  10508. {
  10509. // Required data
  10510. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10511. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10512. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10513. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10514. // Optional data
  10515. if(json_object_object_get(UpdateFirmware, "retries"))
  10516. {
  10517. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10518. }
  10519. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10520. {
  10521. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10522. }
  10523. }
  10524. json_object_put(UpdateFirmware);
  10525. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10526. memset(path, 0, ARRAY_SIZE(path));
  10527. // Wait retrieveData
  10528. if(strlen(retrieveDatestr) > 10)
  10529. {
  10530. do
  10531. {
  10532. sleep(1);
  10533. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10534. }
  10535. // Ready to download
  10536. system("rm -f /mnt/*");
  10537. if(strncmp(locationstr,"http", 4) == 0)
  10538. {
  10539. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10540. sprintf(ftppath,"/%s", path);
  10541. DEBUG_INFO("locationstr: %s\n", locationstr);
  10542. DEBUG_INFO("protocol: %s\n",protocol);
  10543. DEBUG_INFO("host: %s\n",host);
  10544. DEBUG_INFO("path: %s\n",path);
  10545. DEBUG_INFO("ftppath: %s\n",ftppath);
  10546. int ftppathlen=strlen(ftppath);
  10547. int i=1;
  10548. char filenametemp[50];
  10549. while(i < ftppathlen)
  10550. {
  10551. int len=ftppathlen-i;
  10552. if(ftppath[len]== 47) // '/' ascll code: 47
  10553. {
  10554. DEBUG_INFO("compare '/' all right\n");
  10555. break;
  10556. }
  10557. i=i+1;
  10558. }
  10559. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10560. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10561. filenametemp[i+1] = 0;
  10562. do
  10563. {
  10564. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10565. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10566. sleep(1);
  10567. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10568. if(!isSuccess)
  10569. {
  10570. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10571. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10572. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10573. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10574. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10575. }
  10576. else
  10577. {
  10578. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10579. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10580. }
  10581. retriesInt--;
  10582. }while((isSuccess == 0)&&(retriesInt >= 0));
  10583. }
  10584. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10585. {
  10586. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10587. memset(temp, 0, ARRAY_SIZE(temp));
  10588. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10589. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10590. int ftppathlen=strlen(ftpbuf);
  10591. int i=1;
  10592. char filenametemp[50];
  10593. while(i < ftppathlen)
  10594. {
  10595. int len=ftppathlen-i;
  10596. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10597. {
  10598. DEBUG_INFO(" compare '/' all right\n");
  10599. break;
  10600. }
  10601. i=i+1;
  10602. }
  10603. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10604. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10605. filenametemp[i+1] = 0;
  10606. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10607. pch=strchr(temp,'@');
  10608. if(pch==NULL)
  10609. {
  10610. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10611. protocol, host, &port, path);
  10612. strcpy(user,"anonymous");
  10613. strcpy(password,"");
  10614. }
  10615. else
  10616. {
  10617. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10618. protocol, user, password, host, &port, path);
  10619. }
  10620. sscanf(host,"%[^/]%s",host1, path1);
  10621. sprintf(ftppath,"%s", path1);
  10622. //DEBUG_INFO("protocol =%s\n",protocol);
  10623. //DEBUG_INFO("user =%s\n",user);
  10624. //DEBUG_INFO("password =%s\n",password);
  10625. //DEBUG_INFO("host1 =%s\n",host1);
  10626. //DEBUG_INFO("port =%d\n",port);
  10627. //DEBUG_INFO("path1 =%s\n",path1);
  10628. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10629. //ftpFile(host, user, password, port, ftppath, fname);
  10630. //download firmware pthred
  10631. if(port == 0)
  10632. {
  10633. port = 21;
  10634. }
  10635. do
  10636. {
  10637. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10638. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10639. sleep(1);
  10640. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10641. if(!isSuccess)
  10642. {
  10643. //BulldogUtil.sleepMs(interval*1000);
  10644. DEBUG_INFO("Update firmware request and download file fail.\n");
  10645. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10646. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10647. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10648. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10649. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10650. }
  10651. else
  10652. {
  10653. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10654. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10655. }
  10656. retriesInt--;
  10657. }while((!isSuccess)&&(retriesInt >= 0));
  10658. }
  10659. else
  10660. {
  10661. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10662. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10663. sleep(1);
  10664. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10665. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10666. }
  10667. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10668. pthread_exit(NULL);
  10669. }
  10670. int handleCertificateSignedRequest(char *uuid, char *payload)
  10671. {
  10672. mtrace();
  10673. int result = PASS;
  10674. json_object *CertificateSigned;
  10675. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10676. CertificateSigned = json_tokener_parse(payload);
  10677. if(!is_error(CertificateSigned))
  10678. {
  10679. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10680. }
  10681. json_object_put(CertificateSigned);
  10682. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10683. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10684. fclose(fp);
  10685. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10686. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10687. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10688. sendCertificateSignedConfirmation(uuid);
  10689. return result;
  10690. }
  10691. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10692. {
  10693. mtrace();
  10694. int result = PASS;
  10695. json_object *DeleteCertificate;
  10696. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10697. DeleteCertificate = json_tokener_parse(payload);
  10698. if(!is_error(DeleteCertificate))
  10699. {
  10700. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10701. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10702. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10703. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10704. }
  10705. json_object_put(DeleteCertificate);
  10706. /*
  10707. * TODO: Delete certificateSigned process
  10708. */
  10709. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10710. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10711. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10712. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10713. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10714. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10715. sendDeleteCertificateConfirmation(uuid);
  10716. return result;
  10717. }
  10718. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10719. {
  10720. mtrace();
  10721. int result = PASS;
  10722. json_object *ExtendedTriggerMessage;
  10723. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10724. ExtendedTriggerMessage = json_tokener_parse(payload);
  10725. if(!is_error(ExtendedTriggerMessage))
  10726. {
  10727. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10728. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10729. {
  10730. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10731. }
  10732. else
  10733. {
  10734. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10735. }
  10736. }
  10737. json_object_put(ExtendedTriggerMessage);
  10738. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10739. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10740. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10741. {
  10742. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10743. }
  10744. else
  10745. {
  10746. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10747. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10748. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10749. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10750. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10751. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10752. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10753. {
  10754. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10755. }
  10756. else
  10757. {
  10758. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10759. }
  10760. }
  10761. sendExtendedTriggerMessageConfirmation(uuid);
  10762. //==========================
  10763. // Trigger message
  10764. //==========================
  10765. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10766. {
  10767. //sendBootNotificationRequest();
  10768. server_sign = FALSE;
  10769. }
  10770. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10771. {
  10772. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10773. }
  10774. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10775. {
  10776. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10777. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10778. {
  10779. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10780. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10781. }
  10782. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10783. }
  10784. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10785. {
  10786. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10787. }
  10788. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10789. {
  10790. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10791. {
  10792. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10793. }
  10794. else
  10795. {
  10796. for(int idx=0;idx< gunTotalNumber;idx++)
  10797. {
  10798. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10799. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10800. }
  10801. }
  10802. }
  10803. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10804. {
  10805. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10806. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10807. {
  10808. 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\" &");
  10809. }
  10810. }
  10811. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10812. {
  10813. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10814. {
  10815. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10816. }
  10817. else
  10818. {
  10819. for(int idx=0;idx< gunTotalNumber;idx++)
  10820. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10821. }
  10822. }
  10823. return result;
  10824. }
  10825. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10826. {
  10827. mtrace();
  10828. int result = PASS;
  10829. json_object *GetInstalledCertificateIds;
  10830. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10831. GetInstalledCertificateIds = json_tokener_parse(payload);
  10832. if(!is_error(GetInstalledCertificateIds))
  10833. {
  10834. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10835. }
  10836. json_object_put(GetInstalledCertificateIds);
  10837. /*
  10838. * TODO: Return installed certificate process
  10839. */
  10840. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10841. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10842. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10843. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10844. sendGetInstalledCertificateIdsConfirmation(uuid);
  10845. return result;
  10846. }
  10847. int handleGetLogRequest(char *uuid, char *payload)
  10848. {
  10849. mtrace();
  10850. int result = PASS;
  10851. json_object *GetLog;
  10852. DEBUG_INFO("handleGetLogRequest...\n");
  10853. GetLog = json_tokener_parse(payload);
  10854. if(!is_error(GetLog))
  10855. {
  10856. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10857. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10858. if(json_object_object_get(GetLog, "retries") != NULL)
  10859. {
  10860. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10861. }
  10862. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10863. {
  10864. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10865. }
  10866. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10867. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10868. {
  10869. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10870. }
  10871. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10872. {
  10873. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10874. }
  10875. }
  10876. json_object_put(GetLog);
  10877. /*
  10878. * TODO: Upload log process
  10879. */
  10880. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10881. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10882. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10883. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10884. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10885. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10886. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10887. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10888. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10889. sendGetLogConfirmation(uuid);
  10890. return result;
  10891. }
  10892. int handleInstallCertificateRequest(char *uuid, char *payload)
  10893. {
  10894. mtrace();
  10895. int result = PASS;
  10896. json_object *InstallCertificate;
  10897. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10898. InstallCertificate = json_tokener_parse(payload);
  10899. if(!is_error(InstallCertificate))
  10900. {
  10901. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10902. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10903. /*
  10904. * TODO: Install certificate process
  10905. */
  10906. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10907. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10908. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10909. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10910. sendInstallCertificateConfirmation(uuid);
  10911. }
  10912. json_object_put(InstallCertificate);
  10913. return result;
  10914. }
  10915. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10916. {
  10917. mtrace();
  10918. int result = PASS;
  10919. json_object *SignedUpdateFirmware;
  10920. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10921. SignedUpdateFirmware = json_tokener_parse(payload);
  10922. if(!is_error(SignedUpdateFirmware))
  10923. {
  10924. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10925. {
  10926. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10927. }
  10928. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10929. {
  10930. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10931. }
  10932. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10933. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10934. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10935. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10936. {
  10937. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10938. }
  10939. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10940. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10941. }
  10942. json_object_put(SignedUpdateFirmware);
  10943. /*
  10944. * TODO: Upgrade firmware process
  10945. */
  10946. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10947. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10948. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10949. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10950. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10951. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10952. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10953. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10954. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10955. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10956. sendInstallCertificateConfirmation(uuid);
  10957. return result;
  10958. }
  10959. int handleUnknownRequest(char *uuid, char *payload)
  10960. {
  10961. mtrace();
  10962. int result = PASS;
  10963. DEBUG_INFO("handleUnknownRequest...\n");
  10964. sendUnknownConfirmation(uuid);
  10965. result = PASS;
  10966. return result;
  10967. }
  10968. //==========================================
  10969. // Handle server response routine
  10970. //==========================================
  10971. void handleAuthorizeResponse(char *payload, int gun_index)
  10972. {
  10973. mtrace();
  10974. char expiryDatestr[30]={0};
  10975. char parentIdTagstr[20]={0};
  10976. char statusstr[20]={0};
  10977. int expiryDateISNULL=FALSE;
  10978. int parentIdTagISNULL=FALSE;
  10979. DEBUG_INFO("handleAuthorizeResponse...\n");
  10980. json_object *Authorize;
  10981. Authorize = json_tokener_parse(payload);
  10982. if(!is_error(Authorize))
  10983. {
  10984. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10985. {
  10986. // Required data
  10987. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10988. // Optional data
  10989. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10990. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10991. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10992. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10993. }
  10994. }
  10995. json_object_put(Authorize);
  10996. if(expiryDateISNULL == FALSE)
  10997. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10998. if(parentIdTagISNULL == FALSE)
  10999. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11000. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11001. //Update idTag information to authorization cache if supproted
  11002. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11003. {
  11004. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11005. }
  11006. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11007. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11008. authorizeRetryTimes = 0;
  11009. }
  11010. void handleBootNotificationResponse(char *payload, int gun_index)
  11011. {
  11012. mtrace();
  11013. char statusStr[12]={0};
  11014. char currentTimeStr[30]={0};
  11015. int intervalInt = 0;
  11016. DEBUG_INFO("handleBootNotificationResponse...\n");
  11017. json_object *BootNotification;
  11018. BootNotification = json_tokener_parse(payload);
  11019. if(!is_error(BootNotification))
  11020. {
  11021. // Required data
  11022. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11023. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11024. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11025. }
  11026. json_object_put(BootNotification);
  11027. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11028. BootNotificationInterval = intervalInt;
  11029. HeartBeatWaitTime = intervalInt;
  11030. //write back to ShmOCPP16Data->BootNotification
  11031. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11032. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11033. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11034. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11035. {
  11036. server_sign = TRUE;
  11037. server_pending =FALSE;
  11038. }
  11039. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11040. {
  11041. server_pending = TRUE;
  11042. }
  11043. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11044. srand(time(NULL));
  11045. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11046. SetOcppConnStatus(TRUE);
  11047. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11048. }
  11049. void handleDataTransferResponse(char *payload, int gun_index)
  11050. {
  11051. char sstr[160]={0};//sstr[200]={ 0 };
  11052. int c = 0;
  11053. char *loc;
  11054. DEBUG_INFO("handleDataTransferResponse ...\n");
  11055. loc = strstr(payload, "status");
  11056. printf("loc=%s\n",loc);
  11057. c = 0;
  11058. while (loc[3+strlen("status")+c] != '\"')
  11059. {
  11060. sstr[c] = loc[3+strlen("status")+c];
  11061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11062. c++;
  11063. }
  11064. sstr[c] = '\0';
  11065. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11066. }
  11067. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11068. {
  11069. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11070. //struct json_object *obj;
  11071. // obj = json_tokener_parse(payload);
  11072. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11073. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11074. //No fields are defined.
  11075. }
  11076. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11077. {
  11078. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11079. //struct json_object *obj;
  11080. // obj = json_tokener_parse(payload);
  11081. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11082. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11083. //No fields are defined.
  11084. }
  11085. void handleHeartbeatResponse(char *payload, int gun_index)
  11086. {
  11087. mtrace();
  11088. DEBUG_INFO("handleHeartbeatResponse...\n");
  11089. json_object *Heartbeat;
  11090. Heartbeat = json_tokener_parse(payload);
  11091. if(!is_error(Heartbeat))
  11092. {
  11093. // Required data
  11094. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11095. }
  11096. json_object_put(Heartbeat);
  11097. if(FirstHeartBeat == 0)
  11098. {
  11099. FirstHeartBeat = 1;
  11100. DEBUG_INFO("FirstHeartBeat \n");
  11101. }
  11102. HeartBeatWithNOResponse = 0;
  11103. clientTime.Heartbeat=time((time_t*)NULL);
  11104. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11105. }
  11106. void handleMeterValuesResponse(char *payload, int gun_index)
  11107. {
  11108. mtrace();
  11109. DEBUG_INFO("handleMeterValuesResponse...\n");
  11110. }
  11111. void handleStartTransactionResponse(char *payload, int gun_index)
  11112. {
  11113. mtrace();
  11114. //int transactionIdInt = 0;
  11115. FILE *outfile;
  11116. char data[100]={0};
  11117. DEBUG_INFO("handleStartTransactionResponse...\n");
  11118. json_object *StartTransaction;
  11119. StartTransaction = json_tokener_parse(payload);
  11120. if(!is_error(StartTransaction))
  11121. {
  11122. // Required data
  11123. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11124. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11125. // Optional data
  11126. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11127. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11128. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11129. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11130. }
  11131. json_object_put(StartTransaction);
  11132. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11133. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11134. //-----------Start : write to the Queue TransactionId file -----------------//
  11135. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11136. {}
  11137. else
  11138. {
  11139. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11140. if(log == NULL)
  11141. {
  11142. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11143. return ;
  11144. }
  11145. else
  11146. {
  11147. fclose(log);
  11148. }
  11149. }
  11150. // open file for writing
  11151. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11152. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11153. {
  11154. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11155. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11156. fputs(data, outfile);
  11157. fclose (outfile);
  11158. }
  11159. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11160. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11161. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11162. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11163. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11164. }
  11165. void handleStatusNotificationResponse(char *payload, int gun_index)
  11166. {
  11167. mtrace();
  11168. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11169. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11170. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11171. }
  11172. void handleStopTransactionnResponse(char *payload, int gun_index)
  11173. {
  11174. mtrace();
  11175. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11176. json_object *StopTransaction;
  11177. StopTransaction = json_tokener_parse(payload);
  11178. if(!is_error(StopTransaction))
  11179. {
  11180. // Optional data
  11181. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11182. {
  11183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11184. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11186. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11188. }
  11189. }
  11190. json_object_put(StopTransaction);
  11191. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11192. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11193. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11194. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11195. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11196. }
  11197. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11198. {
  11199. mtrace();
  11200. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11201. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11202. }
  11203. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11204. {
  11205. mtrace();
  11206. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11207. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11208. }
  11209. void handleSignCertificateResponse(char *payload, int gun_index)
  11210. {
  11211. mtrace();
  11212. DEBUG_INFO("handleSignCertificateResponse...\n");
  11213. json_object *SignCertificate;
  11214. SignCertificate = json_tokener_parse(payload);
  11215. if(!is_error(SignCertificate))
  11216. {
  11217. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11218. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11219. }
  11220. json_object_put(SignCertificate);
  11221. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11222. }
  11223. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11224. {
  11225. mtrace();
  11226. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11227. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11228. }
  11229. //==========================================
  11230. // Handle Error routine
  11231. //==========================================
  11232. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11233. {
  11234. mtrace();
  11235. #ifdef SystemLogMessage
  11236. DEBUG_INFO("errorCode: %s\n", errorCode);
  11237. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11238. DEBUG_INFO("errorDetails: %s\n", payload);
  11239. #endif
  11240. }
  11241. //===============================================
  11242. // Common routine
  11243. //===============================================
  11244. int initialConfigurationTable(void)
  11245. {
  11246. //clock_t start_t, end_t, total_t;
  11247. FILE *fp;
  11248. FILE *outfile;
  11249. char str[512]={0};
  11250. char sstr[256]={0};
  11251. int c = 0;
  11252. char *loc;
  11253. int confVersion = 3;
  11254. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11255. //start_t = clock();
  11256. //printf("Starting of the program, start_t = %ld\n", start_t);
  11257. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11258. // Check configuration file size is correct
  11259. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11260. {
  11261. struct stat st;
  11262. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11263. if(st.st_size < 3100)
  11264. {
  11265. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11266. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11267. }
  11268. }
  11269. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11270. {
  11271. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11272. if(outfile == NULL)
  11273. {
  11274. DEBUG_INFO("Error opening file\n");
  11275. return FALSE;
  11276. }
  11277. /*Core Profile*/
  11278. //AllowOfflineTxForUnknownId
  11279. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11283. //AuthorizationCacheEnabled
  11284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11288. //AuthorizeRemoteTxRequests
  11289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11293. //BlinkRepeat
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11298. //ClockAlignedDataInterval
  11299. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11303. //ConnectionTimeOut
  11304. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11308. //GetConfigurationMaxKeys
  11309. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11313. // HeartbeatInterval
  11314. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11318. // LightIntensity
  11319. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11323. // LocalAuthorizeOffline
  11324. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11328. // LocalPreAuthorize
  11329. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11333. // MaxEnergyOnInvalidId
  11334. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11338. // MeterValuesAlignedData
  11339. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11343. else
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11346. // MeterValuesAlignedDataMaxLength
  11347. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11351. else
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11354. // MeterValuesSampledData
  11355. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11359. else
  11360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11362. // MeterValuesSampledDataMaxLength
  11363. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11367. else
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11370. // MeterValueSampleInterval
  11371. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11375. // MinimumStatusDuration
  11376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11379. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11381. // NumberOfConnectors
  11382. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11385. {
  11386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11387. }
  11388. else
  11389. {
  11390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11391. }
  11392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11393. // ResetRetries
  11394. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11398. // ConnectorPhaseRotation
  11399. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11403. // ConnectorPhaseRotationMaxLength
  11404. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11408. // StopTransactionOnEVSideDisconnect
  11409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11413. // StopTransactionOnInvalidId
  11414. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11418. // StopTxnAlignedData
  11419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11423. // StopTxnAlignedDataMaxLength
  11424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11428. // StopTxnSampledData
  11429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11433. else
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11436. // StopTxnSampledDataMaxLength
  11437. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11440. {
  11441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11442. }
  11443. else
  11444. {
  11445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11446. }
  11447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11448. // SupportedFeatureProfiles
  11449. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11453. // SupportedFeatureProfilesMaxLength
  11454. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11458. // TransactionMessageAttempts
  11459. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11462. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11464. // TransactionMessageRetryInterval
  11465. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11468. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11470. // UnlockConnectorOnEVSideDisconnect
  11471. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11475. // WebSocketPingInterval
  11476. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11480. // QueueOffLineStartTransactionMessage
  11481. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11485. // AuthorizationKey
  11486. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11490. // SecurityProfile
  11491. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11495. // DefaultPrice
  11496. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11500. // CustomDisplayCostAndPrice
  11501. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11505. // CustomIdleFeeAfterStop
  11506. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11510. // Configuration Version
  11511. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11515. //* Local Auth List Management Profile*/
  11516. #if 0
  11517. //For OCTT Test Case
  11518. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11521. #endif
  11522. #if 1
  11523. //LocalAuthListEnabled
  11524. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11528. #endif
  11529. //LocalAuthListMaxLength
  11530. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11534. //SendLocalListMaxLength
  11535. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11539. //ReserveConnectorZeroSupported
  11540. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11544. //* Smart Charging Profile */
  11545. //ChargeProfileMaxStackLevel
  11546. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11550. // ChargingScheduleAllowedChargingRateUnit
  11551. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11555. // ChargingScheduleMaxPeriods
  11556. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11560. // ConnectorSwitch3to1PhaseSupported
  11561. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11565. // MaxChargingProfilesInstalled
  11566. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11570. fclose(outfile);
  11571. }
  11572. else
  11573. {
  11574. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11575. char keystr[60]={0};
  11576. char readonlystr[10]={0};
  11577. char valuestr[256]={0};
  11578. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11579. if(fp == NULL) {
  11580. DEBUG_INFO("Error opening file");
  11581. return FALSE;
  11582. }
  11583. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11584. {
  11585. //DEBUG_INFO("Get Configuration \n");
  11586. if(strlen(str) > 0)
  11587. {
  11588. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11589. //*************************key*********************************/
  11590. if(strstr(str, "key") != NULL)
  11591. {
  11592. loc = strstr(str, "key");
  11593. c = 0;
  11594. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11595. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11596. {
  11597. sstr[c] = loc[strlen("key")+3+c];
  11598. c++;
  11599. }
  11600. sstr[c] = '\0';
  11601. strcpy(keystr,sstr);
  11602. }
  11603. //*************************readonly*********************************/
  11604. if(strstr(str, "readonly") != NULL)
  11605. {
  11606. loc = strstr(str, "readonly");
  11607. c = 0;
  11608. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11609. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11610. {
  11611. sstr[c] = loc[strlen("readonly")+2+c];
  11612. c++;
  11613. }
  11614. sstr[c] = '\0';
  11615. strcpy(readonlystr,sstr);
  11616. }
  11617. //*************************value*********************************/
  11618. if(strstr(str, "value") != NULL)
  11619. {
  11620. loc = strstr(str, "value");
  11621. c = 0;
  11622. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11623. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11624. {
  11625. sstr[c] = loc[strlen("value")+3+c];
  11626. c++;
  11627. }
  11628. sstr[c] = '\0';
  11629. strcpy(valuestr,sstr);
  11630. }
  11631. // DEBUG_INFO("keystr=%s\n",keystr);
  11632. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11633. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11634. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11635. {
  11636. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11637. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11639. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11640. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11641. }
  11642. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11643. {
  11644. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11645. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11647. }
  11648. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11649. {
  11650. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11652. }
  11653. if(strcmp(keystr, "BlinkRepeat") == 0)
  11654. {
  11655. //Charger.BlinkRepeat = Integer.parseInt(value);
  11656. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11658. }
  11659. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11660. {
  11661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11663. }
  11664. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11665. {
  11666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11668. }
  11669. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11670. {
  11671. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11673. }
  11674. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11675. {
  11676. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11678. HeartBeatWaitTime = atoi(valuestr);
  11679. }
  11680. if(strcmp(keystr, "LightIntensity") == 0)
  11681. {
  11682. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11684. }
  11685. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11686. {
  11687. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11689. }
  11690. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11691. {
  11692. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11694. }
  11695. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11696. {
  11697. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11699. }
  11700. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11701. {
  11702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11704. }
  11705. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11706. {
  11707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11709. }
  11710. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11711. {
  11712. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11714. }
  11715. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11716. {
  11717. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11719. }
  11720. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11721. {
  11722. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11724. }
  11725. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11726. {
  11727. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11729. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11730. }
  11731. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11732. {
  11733. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11735. }
  11736. if(strcmp(keystr, "ResetRetries") == 0)
  11737. {
  11738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11740. }
  11741. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11742. {
  11743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11745. }
  11746. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11747. {
  11748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11750. }
  11751. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11752. {
  11753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11755. }
  11756. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11757. {
  11758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11760. }
  11761. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11762. {
  11763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11765. }
  11766. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11767. {
  11768. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11770. }
  11771. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11772. {
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11775. }
  11776. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11777. {
  11778. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11780. }
  11781. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11782. {
  11783. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11785. }
  11786. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11787. {
  11788. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11790. }
  11791. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11792. {
  11793. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11795. TransactionMessageAttemptsValue = atoi(valuestr);
  11796. }
  11797. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11798. {
  11799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11801. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11802. }
  11803. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11804. {
  11805. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11807. }
  11808. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11809. {
  11810. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11812. }
  11813. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11814. {
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11817. }
  11818. if(strcmp(keystr, "AuthorizationKey") == 0)
  11819. {
  11820. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11821. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11823. }
  11824. if(strcmp(keystr, "SecurityProfile") == 0)
  11825. {
  11826. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11828. }
  11829. if(strcmp(keystr, "DefaultPrice") == 0)
  11830. {
  11831. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11833. }
  11834. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11835. {
  11836. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11838. }
  11839. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11840. {
  11841. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11843. }
  11844. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11845. {
  11846. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11848. }
  11849. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11850. {
  11851. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11853. }
  11854. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11855. {
  11856. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11858. }
  11859. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11860. {
  11861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11863. }
  11864. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11865. {
  11866. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11868. }
  11869. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11870. {
  11871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11873. }
  11874. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11875. {
  11876. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11878. }
  11879. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11880. {
  11881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11883. }
  11884. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11885. {
  11886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11888. }
  11889. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11890. {
  11891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11893. }
  11894. }
  11895. }
  11896. fclose(fp);
  11897. }
  11898. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11899. {
  11900. return PASS;
  11901. }
  11902. else
  11903. {
  11904. return FAIL;
  11905. }
  11906. }
  11907. void StoreConfigurationTable(void)
  11908. {
  11909. FILE *outfile;
  11910. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11911. if(outfile == NULL)
  11912. {
  11913. DEBUG_INFO("Error opening file");
  11914. return ;
  11915. }
  11916. /*Core Profile*/
  11917. //AllowOfflineTxForUnknownId
  11918. /*
  11919. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11920. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11923. */
  11924. //DEBUG_INFO("data=%s\n",data);
  11925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11926. //AuthorizationCacheEnabled
  11927. /*
  11928. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11931. */
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11933. //AuthorizeRemoteTxRequests
  11934. /*
  11935. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11940. //BlinkRepeat
  11941. /*
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11947. //ClockAlignedDataInterval
  11948. /*
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11954. //ConnectionTimeOut
  11955. /*
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11961. //GetConfigurationMaxKeys
  11962. /*
  11963. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11968. // HeartbeatInterval
  11969. /*
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11975. // LightIntensity
  11976. /*
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11982. // LocalAuthorizeOffline
  11983. /*
  11984. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11989. // LocalPreAuthorize
  11990. /*
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11996. // MaxEnergyOnInvalidId
  11997. /*
  11998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12001. */
  12002. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12004. // MeterValuesAlignedData
  12005. /*
  12006. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12009. */
  12010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12011. // MeterValuesAlignedDataMaxLength
  12012. /*
  12013. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12016. */
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12018. // MeterValuesSampledData
  12019. /*
  12020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12023. */
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12025. // MeterValuesSampledDataMaxLength
  12026. /*
  12027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12030. */
  12031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12032. // MeterValueSampleInterval
  12033. /*
  12034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12037. */
  12038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12039. // MinimumStatusDuration
  12040. /*
  12041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12044. */
  12045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12046. // NumberOfConnectors
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12051. {
  12052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12053. }
  12054. else
  12055. {
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12057. }
  12058. */
  12059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12060. // ResetRetries
  12061. /*
  12062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12065. */
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12067. // ConnectorPhaseRotation
  12068. /*
  12069. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12072. */
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12074. // ConnectorPhaseRotationMaxLength
  12075. /*
  12076. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12079. */
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12081. // StopTransactionOnEVSideDisconnect
  12082. /*
  12083. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12086. */
  12087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12088. // StopTransactionOnInvalidId
  12089. /*
  12090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12095. // StopTxnAlignedData
  12096. /*
  12097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12102. // StopTxnAlignedDataMaxLength
  12103. /*
  12104. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12109. // StopTxnSampledData
  12110. /*
  12111. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12116. // StopTxnSampledDataMaxLength
  12117. /*
  12118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12121. */
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12123. // SupportedFeatureProfiles
  12124. /*
  12125. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12128. */
  12129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12130. // SupportedFeatureProfilesMaxLength
  12131. /*
  12132. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12135. */
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12137. // TransactionMessageAttempts
  12138. /*
  12139. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12142. */
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12144. // TransactionMessageRetryInterval
  12145. /*
  12146. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12149. */
  12150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12151. // UnlockConnectorOnEVSideDisconnect
  12152. /*
  12153. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12156. */
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12158. // WebSocketPingInterval
  12159. /*
  12160. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12163. */
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12165. // QueueOffLineStartTransactionMessage
  12166. /*
  12167. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12170. */
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12172. // AuthorizationKey
  12173. /*
  12174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12177. */
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12179. // SecurityProfile
  12180. /*
  12181. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12184. */
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12186. // DefaultPrice
  12187. /*
  12188. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12191. */
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12193. // CustomDisplayCostAndPrice
  12194. /*
  12195. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12198. */
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12200. // CustomIdleFeeAfterStop
  12201. /*
  12202. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12205. */
  12206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12207. // ConfigurationVersion
  12208. /*
  12209. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12212. */
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12214. //* Local Auth List Management Profile*/
  12215. //LocalAuthListEnabled
  12216. /*
  12217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12220. */
  12221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12222. //LocalAuthListMaxLength
  12223. /*
  12224. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12227. */
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12229. //SendLocalListMaxLength
  12230. /*
  12231. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12234. */
  12235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12236. //ReserveConnectorZeroSupported
  12237. /*
  12238. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12241. */
  12242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12243. //* Smart Charging Profile */
  12244. //ChargeProfileMaxStackLevel
  12245. /*
  12246. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12249. */
  12250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12251. // ChargingScheduleAllowedChargingRateUnit
  12252. /*
  12253. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12256. */
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12258. // ChargingScheduleMaxPeriods
  12259. /*
  12260. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12263. */
  12264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12265. // ConnectorSwitch3to1PhaseSupported
  12266. /*
  12267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12270. */
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12272. // MaxChargingProfilesInstalled
  12273. /*
  12274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12277. */
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12279. fclose(outfile);
  12280. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12281. }
  12282. void getKeyValue(char *keyReq)
  12283. {
  12284. int isEmpty = FALSE;
  12285. int isKnowKey = FALSE;
  12286. DEBUG_INFO("keyReq = %s\n", keyReq);
  12287. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12288. isEmpty = TRUE;
  12289. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12290. {
  12291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12294. {
  12295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12296. }
  12297. else
  12298. {
  12299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12300. }
  12301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12302. isKnowKey = TRUE;
  12303. }
  12304. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12305. {
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12309. {
  12310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12311. }
  12312. else
  12313. {
  12314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12315. }
  12316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12317. isKnowKey = TRUE;
  12318. }
  12319. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12320. {
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12324. {
  12325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12326. }
  12327. else
  12328. {
  12329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12330. }
  12331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12332. isKnowKey = TRUE;
  12333. }
  12334. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12335. {
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12339. {
  12340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12341. }
  12342. else
  12343. {
  12344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12345. }
  12346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12347. isKnowKey = TRUE;
  12348. }
  12349. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12350. {
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12354. {
  12355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12356. }
  12357. else
  12358. {
  12359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12360. }
  12361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12362. isKnowKey = TRUE;
  12363. }
  12364. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12365. {
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12369. {
  12370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12371. }
  12372. else
  12373. {
  12374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12375. }
  12376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12377. isKnowKey = TRUE;
  12378. }
  12379. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12380. {
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12384. {
  12385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12386. }
  12387. else
  12388. {
  12389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12390. }
  12391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12392. isKnowKey = TRUE;
  12393. }
  12394. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12395. {
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12399. {
  12400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12401. }
  12402. else
  12403. {
  12404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12405. }
  12406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12407. isKnowKey = TRUE;
  12408. }
  12409. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12410. {
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12414. {
  12415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12416. }
  12417. else
  12418. {
  12419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12420. }
  12421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12422. isKnowKey = TRUE;
  12423. }
  12424. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12425. {
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12429. {
  12430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12431. }
  12432. else
  12433. {
  12434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12435. }
  12436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12437. isKnowKey = TRUE;
  12438. }
  12439. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12444. {
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12446. }
  12447. else
  12448. {
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12450. }
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12452. isKnowKey = TRUE;
  12453. }
  12454. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12459. {
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12461. }
  12462. else
  12463. {
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12465. }
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12467. isKnowKey = TRUE;
  12468. }
  12469. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12474. {
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12476. }
  12477. else
  12478. {
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12480. }
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12482. isKnowKey = TRUE;
  12483. }
  12484. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12489. {
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12491. }
  12492. else
  12493. {
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12495. }
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12497. isKnowKey = TRUE;
  12498. }
  12499. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12504. {
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12506. }
  12507. else
  12508. {
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12510. }
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12512. isKnowKey = TRUE;
  12513. }
  12514. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12519. {
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12521. }
  12522. else
  12523. {
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12525. }
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12527. isKnowKey = TRUE;
  12528. }
  12529. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12534. {
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12536. }
  12537. else
  12538. {
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12540. }
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12542. isKnowKey = TRUE;
  12543. }
  12544. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12549. {
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12551. }
  12552. else
  12553. {
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12555. }
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12557. isKnowKey = TRUE;
  12558. }
  12559. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12566. }
  12567. else
  12568. {
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12570. }
  12571. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12573. isKnowKey = TRUE;
  12574. }
  12575. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12576. {
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12580. {
  12581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12582. }
  12583. else
  12584. {
  12585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12586. }
  12587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12588. isKnowKey = TRUE;
  12589. }
  12590. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12591. {
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12595. {
  12596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12597. }
  12598. else
  12599. {
  12600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12601. }
  12602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12603. isKnowKey = TRUE;
  12604. }
  12605. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12606. {
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12610. {
  12611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12612. }
  12613. else
  12614. {
  12615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12616. }
  12617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12618. isKnowKey = TRUE;
  12619. }
  12620. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12621. {
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12625. {
  12626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12627. }
  12628. else
  12629. {
  12630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12631. }
  12632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12633. isKnowKey = TRUE;
  12634. }
  12635. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12642. }
  12643. else
  12644. {
  12645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12646. }
  12647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12648. isKnowKey = TRUE;
  12649. }
  12650. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12651. {
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12655. {
  12656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12657. }
  12658. else
  12659. {
  12660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12661. }
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12663. isKnowKey = TRUE;
  12664. }
  12665. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12666. {
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12670. {
  12671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12672. }
  12673. else
  12674. {
  12675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12676. }
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12678. isKnowKey = TRUE;
  12679. }
  12680. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12681. {
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12685. {
  12686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12687. }
  12688. else
  12689. {
  12690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12691. }
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12693. isKnowKey = TRUE;
  12694. }
  12695. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12700. {
  12701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12702. }
  12703. else
  12704. {
  12705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12706. }
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12708. isKnowKey = TRUE;
  12709. }
  12710. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12715. {
  12716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12717. }
  12718. else
  12719. {
  12720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12721. }
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12723. isKnowKey = TRUE;
  12724. }
  12725. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12730. {
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12732. }
  12733. else
  12734. {
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12736. }
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12738. isKnowKey = TRUE;
  12739. }
  12740. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12741. {
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12745. {
  12746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12747. }
  12748. else
  12749. {
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12751. }
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12753. isKnowKey = TRUE;
  12754. }
  12755. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12756. {
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12760. {
  12761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12762. }
  12763. else
  12764. {
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12766. }
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12768. isKnowKey = TRUE;
  12769. }
  12770. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12771. {
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12775. {
  12776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12777. }
  12778. else
  12779. {
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12781. }
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12783. isKnowKey = TRUE;
  12784. }
  12785. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12786. {
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12790. {
  12791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12792. }
  12793. else
  12794. {
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12796. }
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12798. isKnowKey = TRUE;
  12799. }
  12800. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12805. {
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12807. }
  12808. else
  12809. {
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12811. }
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12813. isKnowKey = TRUE;
  12814. }
  12815. /*
  12816. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12817. {
  12818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12821. {
  12822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12823. }
  12824. else
  12825. {
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12827. }
  12828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12829. isKnowKey = TRUE;
  12830. }*/
  12831. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12832. {
  12833. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12836. {
  12837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12838. }
  12839. else
  12840. {
  12841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12842. }
  12843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12844. isKnowKey = TRUE;
  12845. }
  12846. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12847. {
  12848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12851. {
  12852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12853. }
  12854. else
  12855. {
  12856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12857. }
  12858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12859. isKnowKey = TRUE;
  12860. }
  12861. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12862. {
  12863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12866. {
  12867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12868. }
  12869. else
  12870. {
  12871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12872. }
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12874. isKnowKey = TRUE;
  12875. }
  12876. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12877. {
  12878. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12881. {
  12882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12883. }
  12884. else
  12885. {
  12886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12887. }
  12888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12889. isKnowKey = TRUE;
  12890. }
  12891. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12892. {
  12893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12896. {
  12897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12898. }
  12899. else
  12900. {
  12901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12902. }
  12903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12904. isKnowKey = TRUE;
  12905. }
  12906. #if 1
  12907. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12908. {
  12909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12911. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12912. {
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12914. }
  12915. else
  12916. {
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12918. }
  12919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12920. isKnowKey = TRUE;
  12921. }
  12922. #endif
  12923. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12924. {
  12925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12927. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12928. {
  12929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12930. }
  12931. else
  12932. {
  12933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12934. }
  12935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12936. isKnowKey = TRUE;
  12937. }
  12938. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12939. {
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12942. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12943. {
  12944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12945. }
  12946. else
  12947. {
  12948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12949. }
  12950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12951. isKnowKey = TRUE;
  12952. }
  12953. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12954. {
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12957. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12958. {
  12959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12960. }
  12961. else
  12962. {
  12963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12964. }
  12965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12966. isKnowKey = TRUE;
  12967. }
  12968. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12969. {
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12972. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12973. {
  12974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12975. }
  12976. else
  12977. {
  12978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12979. }
  12980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12981. isKnowKey = TRUE;
  12982. }
  12983. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12984. {
  12985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12987. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12988. {
  12989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12990. }
  12991. else
  12992. {
  12993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12994. }
  12995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12996. isKnowKey = TRUE;
  12997. }
  12998. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12999. {
  13000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13002. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13003. {
  13004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13005. }
  13006. else
  13007. {
  13008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13009. }
  13010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13011. isKnowKey = TRUE;
  13012. }
  13013. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13014. {
  13015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13017. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13018. {
  13019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13020. }
  13021. else
  13022. {
  13023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13024. }
  13025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13026. isKnowKey = TRUE;
  13027. }
  13028. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13029. {
  13030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13032. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13033. {
  13034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13035. }
  13036. else
  13037. {
  13038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13039. }
  13040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13041. isKnowKey = TRUE;
  13042. }
  13043. //=========================================================
  13044. if(!isEmpty && !isKnowKey)
  13045. {
  13046. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13047. strcpy(unknownkey[UnknownKeynum], keyReq);
  13048. UnknownKeynum = UnknownKeynum + 1;
  13049. }
  13050. }
  13051. void processUnkownKey(void)
  13052. {
  13053. DEBUG_INFO("processUnkownKey...\n");
  13054. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13055. for(int index=0; index < UnknownKeynum; index++)
  13056. {
  13057. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13058. {
  13059. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13060. }
  13061. }
  13062. }
  13063. int setKeyValue(char *key, char *value)
  13064. {
  13065. int isSuccess = NotSupported;
  13066. int check_ascii=0;
  13067. char str[256]={0};
  13068. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13069. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13070. {
  13071. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13073. {
  13074. strcpy(str, (const char*)value);
  13075. for(int i = 0; str[i]; i++){
  13076. str[i] = tolower(str[i]);
  13077. }
  13078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13079. isSuccess = ConfigurationStatus_Accepted;
  13080. }
  13081. else
  13082. {
  13083. isSuccess = ConfigurationStatus_Rejected;
  13084. }
  13085. }
  13086. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13087. {
  13088. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13090. {
  13091. strcpy(str, (const char*)value);
  13092. for(int i = 0; str[i]; i++){
  13093. str[i] = tolower(str[i]);
  13094. }
  13095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13096. isSuccess = ConfigurationStatus_Accepted;
  13097. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13098. }
  13099. else
  13100. {
  13101. isSuccess = ConfigurationStatus_Rejected;
  13102. }
  13103. }
  13104. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13105. {
  13106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13107. {
  13108. strcpy(str, (const char*)value);
  13109. for(int i = 0; str[i]; i++)
  13110. {
  13111. str[i] = tolower(str[i]);
  13112. }
  13113. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13115. isSuccess = ConfigurationStatus_Accepted;
  13116. }
  13117. else
  13118. {
  13119. isSuccess = ConfigurationStatus_Rejected;
  13120. }
  13121. }
  13122. if(strcmp(key, "BlinkRepeat") == 0)
  13123. {
  13124. //Charger.BlinkRepeat = Integer.parseInt(value);
  13125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13135. isSuccess = ConfigurationStatus_Accepted;
  13136. }
  13137. }
  13138. else
  13139. {
  13140. isSuccess = ConfigurationStatus_Rejected;
  13141. }
  13142. }
  13143. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13144. {
  13145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13146. {
  13147. check_ascii = value[0];
  13148. if( (check_ascii < 48) || (check_ascii > 57) )
  13149. {
  13150. isSuccess = ConfigurationStatus_Rejected;
  13151. }
  13152. else
  13153. {
  13154. if((atoi(value) == 0) || (atoi(value) >= 10))
  13155. {
  13156. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13158. isSuccess = ConfigurationStatus_Accepted;
  13159. }
  13160. else
  13161. isSuccess = ConfigurationStatus_Rejected;
  13162. }
  13163. }
  13164. else
  13165. {
  13166. isSuccess = ConfigurationStatus_Rejected;
  13167. }
  13168. }
  13169. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13170. {
  13171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13172. {
  13173. check_ascii = value[0];
  13174. if( (check_ascii < 48) || (check_ascii > 57) )
  13175. {
  13176. isSuccess = ConfigurationStatus_Rejected;
  13177. }
  13178. else
  13179. {
  13180. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13182. isSuccess = ConfigurationStatus_Accepted;
  13183. }
  13184. }
  13185. else
  13186. {
  13187. isSuccess = ConfigurationStatus_Rejected;
  13188. }
  13189. }
  13190. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13191. {
  13192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13193. {
  13194. check_ascii = value[0];
  13195. if( (check_ascii < 48) || (check_ascii > 57) )
  13196. {
  13197. isSuccess = ConfigurationStatus_Rejected;
  13198. }
  13199. else
  13200. {
  13201. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13203. isSuccess = ConfigurationStatus_Accepted;
  13204. }
  13205. }
  13206. else
  13207. {
  13208. isSuccess = ConfigurationStatus_Rejected;
  13209. }
  13210. }
  13211. if(strcmp(key, "HeartbeatInterval") == 0)
  13212. {
  13213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13214. {
  13215. check_ascii = value[0];
  13216. if( (check_ascii < 48) || (check_ascii > 57) )
  13217. {
  13218. isSuccess = ConfigurationStatus_Rejected;
  13219. }
  13220. else
  13221. {
  13222. if((atoi(value) == 0) || (atoi(value) >= 10))
  13223. {
  13224. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13226. HeartBeatWaitTime = atoi(value);
  13227. isSuccess = ConfigurationStatus_Accepted;
  13228. }
  13229. else
  13230. {
  13231. isSuccess = ConfigurationStatus_Rejected;
  13232. }
  13233. }
  13234. }
  13235. else
  13236. {
  13237. isSuccess = ConfigurationStatus_Rejected;
  13238. }
  13239. }
  13240. if(strcmp(key, "LightIntensity") == 0)
  13241. {
  13242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13243. {
  13244. check_ascii = value[0];
  13245. if( (check_ascii < 48) || (check_ascii > 57) )
  13246. {
  13247. isSuccess = ConfigurationStatus_Rejected;
  13248. }
  13249. else
  13250. {
  13251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13252. isSuccess = ConfigurationStatus_Accepted;
  13253. }
  13254. }
  13255. else
  13256. {
  13257. isSuccess = ConfigurationStatus_Rejected;
  13258. }
  13259. }
  13260. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13261. {
  13262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13263. {
  13264. strcpy(str, (const char*)value);
  13265. for(int i = 0; str[i]; i++)
  13266. {
  13267. str[i] = tolower(str[i]);
  13268. }
  13269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13270. isSuccess = ConfigurationStatus_Accepted;
  13271. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13272. }
  13273. else
  13274. {
  13275. isSuccess = ConfigurationStatus_Rejected;
  13276. }
  13277. }
  13278. if(strcmp(key, "LocalPreAuthorize") == 0)
  13279. {
  13280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13281. {
  13282. strcpy(str, (const char*)value);
  13283. for(int i = 0; str[i]; i++)
  13284. {
  13285. str[i] = tolower(str[i]);
  13286. }
  13287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13288. isSuccess = ConfigurationStatus_Accepted;
  13289. }
  13290. else
  13291. {
  13292. isSuccess = ConfigurationStatus_Rejected;
  13293. }
  13294. }
  13295. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13296. {
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13298. {
  13299. check_ascii = value[0];
  13300. if( (check_ascii < 48) || (check_ascii > 57) )
  13301. {
  13302. isSuccess = ConfigurationStatus_Rejected;
  13303. }
  13304. else
  13305. {
  13306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13307. isSuccess = ConfigurationStatus_Accepted;
  13308. }
  13309. }
  13310. else
  13311. {
  13312. isSuccess = ConfigurationStatus_Rejected;
  13313. }
  13314. }
  13315. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13316. {
  13317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13318. {
  13319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13320. isSuccess = ConfigurationStatus_Accepted;
  13321. }
  13322. else
  13323. {
  13324. isSuccess = ConfigurationStatus_Rejected;
  13325. }
  13326. }
  13327. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13328. {
  13329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13330. {
  13331. check_ascii = value[0];
  13332. if( (check_ascii < 48) || (check_ascii > 57) )
  13333. {
  13334. isSuccess = ConfigurationStatus_Rejected;
  13335. }
  13336. else
  13337. {
  13338. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13340. isSuccess = ConfigurationStatus_Accepted;
  13341. }
  13342. }
  13343. else
  13344. {
  13345. isSuccess = ConfigurationStatus_Rejected;
  13346. }
  13347. }
  13348. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13349. {
  13350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13351. {
  13352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13353. isSuccess = ConfigurationStatus_Accepted;
  13354. }
  13355. else
  13356. {
  13357. isSuccess = ConfigurationStatus_Rejected;
  13358. }
  13359. }
  13360. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13361. {
  13362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13363. {
  13364. check_ascii = value[0];
  13365. if( (check_ascii < 48) || (check_ascii > 57) )
  13366. {
  13367. isSuccess = ConfigurationStatus_Rejected;
  13368. }
  13369. else
  13370. {
  13371. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13373. isSuccess = ConfigurationStatus_Accepted;
  13374. }
  13375. }
  13376. else
  13377. {
  13378. isSuccess = ConfigurationStatus_Rejected;
  13379. }
  13380. }
  13381. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13382. {
  13383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13384. {
  13385. check_ascii = value[0];
  13386. if( (check_ascii < 48) || (check_ascii > 57) )
  13387. {
  13388. isSuccess = ConfigurationStatus_Rejected;
  13389. }
  13390. else
  13391. {
  13392. if((atoi(value) == 0) || (atoi(value) >= 10))
  13393. {
  13394. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13396. isSuccess = ConfigurationStatus_Accepted;
  13397. }
  13398. else
  13399. {
  13400. isSuccess = ConfigurationStatus_Rejected;
  13401. }
  13402. }
  13403. }
  13404. else
  13405. {
  13406. isSuccess = ConfigurationStatus_Rejected;
  13407. }
  13408. }
  13409. if(strcmp(key, "MinimumStatusDuration") == 0)
  13410. {
  13411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13412. {
  13413. check_ascii = value[0];
  13414. if( (check_ascii < 48) || (check_ascii > 57) )
  13415. {
  13416. isSuccess = ConfigurationStatus_Rejected;
  13417. }
  13418. else
  13419. {
  13420. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13421. {
  13422. isSuccess = ConfigurationStatus_Rejected;
  13423. }
  13424. else
  13425. {
  13426. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13428. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13429. isSuccess = ConfigurationStatus_Accepted;
  13430. }
  13431. }
  13432. }
  13433. else
  13434. {
  13435. isSuccess = ConfigurationStatus_Rejected;
  13436. }
  13437. }
  13438. if(strcmp(key, "NumberOfConnectors") == 0)
  13439. {
  13440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13441. {
  13442. check_ascii = value[0];
  13443. if( (check_ascii < 48) || (check_ascii > 57) )
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. else
  13448. {
  13449. //Charger.ResetRetries = Integer.parseInt(value);
  13450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13451. isSuccess = ConfigurationStatus_Accepted;
  13452. }
  13453. }
  13454. else
  13455. {
  13456. isSuccess = ConfigurationStatus_Rejected;
  13457. }
  13458. }
  13459. if(strcmp(key, "ResetRetries") == 0)
  13460. {
  13461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13462. {
  13463. check_ascii = value[0];
  13464. if( (check_ascii < 48) || (check_ascii > 57) )
  13465. {
  13466. isSuccess = ConfigurationStatus_Rejected;
  13467. }
  13468. else
  13469. {
  13470. //Charger.ResetRetries = Integer.parseInt(value);
  13471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13472. isSuccess = ConfigurationStatus_Accepted;
  13473. }
  13474. }
  13475. else
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. }
  13480. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13481. {
  13482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13483. {
  13484. strcpy(str, (const char*)value);
  13485. for(int i = 0; str[i]; i++)
  13486. {
  13487. str[i] = tolower(str[i]);
  13488. }
  13489. if(strcmp(str, "notapplicable")== 0)
  13490. {
  13491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13492. isSuccess = ConfigurationStatus_Accepted;
  13493. }
  13494. else if(strcmp(str, "unknown")== 0)
  13495. {
  13496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13497. isSuccess = ConfigurationStatus_Accepted;
  13498. }
  13499. else if(strcmp(str, "rst")== 0)
  13500. {
  13501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13502. isSuccess = ConfigurationStatus_Accepted;
  13503. }
  13504. else if(strcmp(str, "rts")== 0)
  13505. {
  13506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13507. isSuccess = ConfigurationStatus_Accepted;
  13508. }
  13509. else if(strcmp(str, "srt")== 0)
  13510. {
  13511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13512. isSuccess = ConfigurationStatus_Accepted;
  13513. }
  13514. else if(strcmp(str, "str")== 0)
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13517. isSuccess = ConfigurationStatus_Accepted;
  13518. }
  13519. else if(strcmp(str, "trs")== 0)
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13522. isSuccess = ConfigurationStatus_Accepted;
  13523. }
  13524. else if(strcmp(str, "tsr")== 0)
  13525. {
  13526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13527. isSuccess = ConfigurationStatus_Accepted;
  13528. }
  13529. else
  13530. {
  13531. isSuccess = ConfigurationStatus_Rejected;
  13532. }
  13533. }
  13534. else
  13535. {
  13536. isSuccess = ConfigurationStatus_Rejected;
  13537. }
  13538. }
  13539. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13540. {
  13541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13542. {
  13543. check_ascii = value[0];
  13544. if( (check_ascii < 48) || (check_ascii > 57) )
  13545. {
  13546. isSuccess = ConfigurationStatus_Rejected;
  13547. }
  13548. else
  13549. {
  13550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13551. isSuccess = ConfigurationStatus_Accepted;
  13552. }
  13553. }
  13554. else
  13555. {
  13556. isSuccess = ConfigurationStatus_Rejected;
  13557. }
  13558. }
  13559. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13560. {
  13561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13562. {
  13563. strcpy(str, (const char*)value);
  13564. for(int i = 0; str[i]; i++)
  13565. {
  13566. str[i] = tolower(str[i]);
  13567. }
  13568. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13570. isSuccess = ConfigurationStatus_Accepted;
  13571. }
  13572. else
  13573. {
  13574. isSuccess = ConfigurationStatus_Rejected;
  13575. }
  13576. }
  13577. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13578. {
  13579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13580. {
  13581. strcpy(str, (const char*)value);
  13582. for(int i = 0; str[i]; i++)
  13583. {
  13584. str[i] = tolower(str[i]);
  13585. }
  13586. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13588. isSuccess = ConfigurationStatus_Accepted;
  13589. }
  13590. else
  13591. {
  13592. isSuccess = ConfigurationStatus_Rejected;
  13593. }
  13594. }
  13595. if(strcmp(key, "StopTxnAlignedData") == 0)
  13596. {
  13597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13598. {
  13599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13600. isSuccess = ConfigurationStatus_Accepted;
  13601. }
  13602. else
  13603. {
  13604. isSuccess = ConfigurationStatus_Rejected;
  13605. }
  13606. }
  13607. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13608. {
  13609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13610. {
  13611. check_ascii = value[0];
  13612. if( (check_ascii < 48) || (check_ascii > 57) )
  13613. {
  13614. isSuccess = ConfigurationStatus_Rejected;
  13615. }
  13616. else
  13617. {
  13618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13619. isSuccess = ConfigurationStatus_Accepted;
  13620. }
  13621. }
  13622. else
  13623. {
  13624. isSuccess = ConfigurationStatus_Rejected;
  13625. }
  13626. }
  13627. if(strcmp(key, "StopTxnSampledData") == 0)
  13628. {
  13629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13630. {
  13631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13632. isSuccess = ConfigurationStatus_Accepted;
  13633. }
  13634. else
  13635. {
  13636. isSuccess = ConfigurationStatus_Rejected;
  13637. }
  13638. }
  13639. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13640. {
  13641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13642. {
  13643. check_ascii = value[0];
  13644. if( (check_ascii < 48) || (check_ascii > 57) )
  13645. {
  13646. isSuccess = ConfigurationStatus_Rejected;
  13647. }
  13648. else
  13649. {
  13650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13651. isSuccess = ConfigurationStatus_Accepted;
  13652. }
  13653. }
  13654. else
  13655. {
  13656. isSuccess = ConfigurationStatus_Rejected;
  13657. }
  13658. }
  13659. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13660. {
  13661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13662. {
  13663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13664. isSuccess = ConfigurationStatus_Accepted;
  13665. }
  13666. else
  13667. {
  13668. isSuccess = ConfigurationStatus_Rejected;
  13669. }
  13670. }
  13671. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13672. {
  13673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13683. isSuccess = ConfigurationStatus_Accepted;
  13684. }
  13685. }
  13686. else
  13687. {
  13688. isSuccess = ConfigurationStatus_Rejected;
  13689. }
  13690. }
  13691. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13692. {
  13693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13694. {
  13695. check_ascii = value[0];
  13696. if( (check_ascii < 48) || (check_ascii > 57) )
  13697. {
  13698. isSuccess = ConfigurationStatus_Rejected;
  13699. }
  13700. else
  13701. {
  13702. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13704. TransactionMessageAttemptsValue = atoi(value);
  13705. isSuccess = ConfigurationStatus_Accepted;
  13706. }
  13707. }
  13708. else
  13709. {
  13710. isSuccess = ConfigurationStatus_Rejected;
  13711. }
  13712. }
  13713. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13714. {
  13715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13716. {
  13717. check_ascii = value[0];
  13718. if( (check_ascii < 48) || (check_ascii > 57) )
  13719. {
  13720. isSuccess = ConfigurationStatus_Rejected;
  13721. }
  13722. else
  13723. {
  13724. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13726. TransactionMessageRetryIntervalValue = atoi(value);
  13727. isSuccess = ConfigurationStatus_Accepted;
  13728. }
  13729. }
  13730. else
  13731. {
  13732. isSuccess = ConfigurationStatus_Rejected;
  13733. }
  13734. }
  13735. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13736. {
  13737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13738. {
  13739. strcpy(str, (const char*)value);
  13740. for(int i = 0; str[i]; i++)
  13741. {
  13742. str[i] = tolower(str[i]);
  13743. }
  13744. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13746. isSuccess = ConfigurationStatus_Accepted;
  13747. }
  13748. else
  13749. {
  13750. isSuccess = ConfigurationStatus_Rejected;
  13751. }
  13752. }
  13753. if(strcmp(key, "WebSocketPingInterval") == 0)
  13754. {
  13755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13756. {
  13757. check_ascii = value[0];
  13758. if( (check_ascii < 48) || (check_ascii > 57) )
  13759. {
  13760. isSuccess = ConfigurationStatus_Rejected;
  13761. }
  13762. else
  13763. {
  13764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13765. isSuccess = ConfigurationStatus_Accepted;
  13766. }
  13767. }
  13768. else
  13769. {
  13770. isSuccess = ConfigurationStatus_Rejected;
  13771. }
  13772. }
  13773. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13774. {
  13775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13776. {
  13777. strcpy(str, (const char*)value);
  13778. for(int i = 0; str[i]; i++)
  13779. {
  13780. str[i] = tolower(str[i]);
  13781. }
  13782. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13784. isSuccess = ConfigurationStatus_Accepted;
  13785. }
  13786. else
  13787. {
  13788. isSuccess = ConfigurationStatus_Rejected;
  13789. }
  13790. }
  13791. if(strcmp(key, "AuthorizationKey") == 0)
  13792. {
  13793. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13794. {
  13795. strcpy(str, (const char*)value);
  13796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13797. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13798. isSuccess = ConfigurationStatus_Accepted;
  13799. }
  13800. else
  13801. {
  13802. isSuccess = ConfigurationStatus_Rejected;
  13803. }
  13804. }
  13805. if(strcmp(key, "SecurityProfile") == 0)
  13806. {
  13807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13808. {
  13809. check_ascii = value[0];
  13810. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13811. {
  13812. isSuccess = ConfigurationStatus_Rejected;
  13813. }
  13814. else if(check_ascii == 0x33)
  13815. {
  13816. isSuccess = NotSupported;
  13817. }
  13818. else
  13819. {
  13820. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13821. {
  13822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13823. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13824. isSuccess = ConfigurationStatus_Accepted;
  13825. }
  13826. else
  13827. isSuccess = ConfigurationStatus_Rejected;
  13828. }
  13829. }
  13830. else
  13831. {
  13832. isSuccess = ConfigurationStatus_Rejected;
  13833. }
  13834. }
  13835. if(strcmp(key, "DefaultPrice") == 0)
  13836. {
  13837. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13838. {
  13839. strcpy(str, (const char*)value);
  13840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13841. isSuccess = ConfigurationStatus_Accepted;
  13842. }
  13843. else
  13844. {
  13845. isSuccess = ConfigurationStatus_Rejected;
  13846. }
  13847. }
  13848. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13849. {
  13850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13851. {
  13852. strcpy(str, (const char*)value);
  13853. for(int i = 0; str[i]; i++)
  13854. {
  13855. str[i] = tolower(str[i]);
  13856. }
  13857. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13859. isSuccess = ConfigurationStatus_Accepted;
  13860. }
  13861. else
  13862. {
  13863. isSuccess = ConfigurationStatus_Rejected;
  13864. }
  13865. }
  13866. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13867. {
  13868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13869. {
  13870. strcpy(str, (const char*)value);
  13871. for(int i = 0; str[i]; i++)
  13872. {
  13873. str[i] = tolower(str[i]);
  13874. }
  13875. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13877. isSuccess = ConfigurationStatus_Accepted;
  13878. }
  13879. else
  13880. {
  13881. isSuccess = ConfigurationStatus_Rejected;
  13882. }
  13883. }
  13884. #if 0
  13885. //For OCPP Test Case
  13886. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13887. {
  13888. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13889. {
  13890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13891. isSuccess = ConfigurationStatus_Accepted;
  13892. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13893. }
  13894. else
  13895. {
  13896. isSuccess = ConfigurationStatus_Rejected;
  13897. }
  13898. }
  13899. #endif
  13900. #if 1
  13901. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13902. {
  13903. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13904. {
  13905. strcpy(str, (const char*)value);
  13906. for(int i = 0; str[i]; i++)
  13907. {
  13908. str[i] = tolower(str[i]);
  13909. }
  13910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13911. isSuccess = ConfigurationStatus_Accepted;
  13912. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13913. }
  13914. else
  13915. {
  13916. isSuccess = ConfigurationStatus_Rejected;
  13917. }
  13918. }
  13919. #endif
  13920. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13921. {
  13922. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].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[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13932. isSuccess = ConfigurationStatus_Accepted;
  13933. }
  13934. }
  13935. else
  13936. {
  13937. isSuccess = ConfigurationStatus_Rejected;
  13938. }
  13939. }
  13940. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13941. {
  13942. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13943. {
  13944. check_ascii = value[0];
  13945. if( (check_ascii < 48) || (check_ascii > 57) )
  13946. {
  13947. isSuccess = ConfigurationStatus_Rejected;
  13948. }
  13949. else
  13950. {
  13951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13952. isSuccess = ConfigurationStatus_Accepted;
  13953. }
  13954. }
  13955. else
  13956. {
  13957. isSuccess = ConfigurationStatus_Rejected;
  13958. }
  13959. }
  13960. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13961. {
  13962. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13963. {
  13964. strcpy(str, (const char*)value);
  13965. for(int i = 0; str[i]; i++)
  13966. {
  13967. str[i] = tolower(str[i]);
  13968. }
  13969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13970. isSuccess = ConfigurationStatus_Accepted;
  13971. }
  13972. else
  13973. {
  13974. isSuccess = ConfigurationStatus_Rejected;
  13975. }
  13976. }
  13977. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13978. {
  13979. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13980. {
  13981. check_ascii = value[0];
  13982. if( (check_ascii < 48) || (check_ascii > 57) )
  13983. {
  13984. isSuccess = ConfigurationStatus_Rejected;
  13985. }
  13986. else
  13987. {
  13988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13989. isSuccess = ConfigurationStatus_Accepted;
  13990. }
  13991. }
  13992. else
  13993. {
  13994. isSuccess = ConfigurationStatus_Rejected;
  13995. }
  13996. }
  13997. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13998. {
  13999. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14000. {
  14001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14002. isSuccess = ConfigurationStatus_Accepted;
  14003. }
  14004. else
  14005. {
  14006. isSuccess = ConfigurationStatus_Rejected;
  14007. }
  14008. }
  14009. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14010. {
  14011. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14012. {
  14013. check_ascii = value[0];
  14014. if( (check_ascii < 48) || (check_ascii > 57) )
  14015. {
  14016. isSuccess = ConfigurationStatus_Rejected;
  14017. }
  14018. else
  14019. {
  14020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14021. isSuccess = ConfigurationStatus_Accepted;
  14022. }
  14023. }
  14024. else
  14025. {
  14026. isSuccess = ConfigurationStatus_Rejected;
  14027. }
  14028. }
  14029. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14030. {
  14031. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14032. {
  14033. strcpy(str, (const char*)value);
  14034. for(int i = 0; str[i]; i++)
  14035. {
  14036. str[i] = tolower(str[i]);
  14037. }
  14038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14039. isSuccess = ConfigurationStatus_Accepted;
  14040. }
  14041. else
  14042. {
  14043. isSuccess = ConfigurationStatus_Rejected;
  14044. }
  14045. }
  14046. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14047. {
  14048. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14049. {
  14050. check_ascii = value[0];
  14051. if( (check_ascii < 48) || (check_ascii > 57) )
  14052. {
  14053. isSuccess = ConfigurationStatus_Rejected;
  14054. }
  14055. else
  14056. {
  14057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14058. isSuccess = ConfigurationStatus_Accepted;
  14059. }
  14060. }
  14061. else
  14062. {
  14063. isSuccess = ConfigurationStatus_Rejected;
  14064. }
  14065. }
  14066. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14067. return isSuccess;
  14068. }
  14069. int TransactionMessageAttemptsGet(void)
  14070. {
  14071. return TransactionMessageAttemptsValue;
  14072. }
  14073. int FirstHeartBeatResponse(void)
  14074. {
  14075. return FirstHeartBeat;
  14076. }
  14077. int TransactionMessageRetryIntervalGet(void)
  14078. {
  14079. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14080. }
  14081. int ReadHttpStatus(int sock)
  14082. {
  14083. //char c;
  14084. char buff[1024]="",*ptr=buff+1;
  14085. int bytes_received, status;
  14086. DEBUG_INFO("Begin Response ..\n");
  14087. while((bytes_received = recv(sock, ptr, 1, 0))){
  14088. if(bytes_received==-1){
  14089. perror("ReadHttpStatus");
  14090. exit(1);
  14091. }
  14092. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14093. ptr++;
  14094. }
  14095. *ptr=0;
  14096. ptr=buff+1;
  14097. sscanf(ptr,"%*s %d ", &status);
  14098. DEBUG_INFO("%s\n",ptr);
  14099. DEBUG_INFO("status=%d\n",status);
  14100. DEBUG_INFO("End Response ..\n");
  14101. return (bytes_received>0)?status:0;
  14102. }
  14103. //the only filed that it parsed is 'Content-Length'
  14104. int ParseHeader(int sock)
  14105. {
  14106. //char c;
  14107. char buff[1024]="",*ptr=buff+4;
  14108. int bytes_received;
  14109. DEBUG_INFO("Begin HEADER ..\n");
  14110. while((bytes_received = recv(sock, ptr, 1, 0))){
  14111. if(bytes_received==-1){
  14112. perror("Parse Header");
  14113. exit(1);
  14114. }
  14115. if(
  14116. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14117. (ptr[-1]=='\r') && (*ptr=='\n' )
  14118. ) break;
  14119. ptr++;
  14120. }
  14121. *ptr=0;
  14122. ptr=buff+4;
  14123. //printf("%s",ptr);
  14124. if(bytes_received){
  14125. ptr=strstr(ptr,"Content-Length:");
  14126. if(ptr){
  14127. sscanf(ptr,"%*s %d",&bytes_received);
  14128. }else
  14129. bytes_received=-1; //unknown size
  14130. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14131. }
  14132. DEBUG_INFO("End HEADER ..\n");
  14133. return bytes_received ;
  14134. }
  14135. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14136. {
  14137. int result = TRUE;
  14138. char rmFileCmd[100]={0};
  14139. char FilePath[100]={0};
  14140. char ftpbuf[200];
  14141. int systemresult;
  14142. //DEBUG_INFO("filename=%s\n",filename);
  14143. //DEBUG_INFO("url=%s\n",url);
  14144. sprintf(FilePath,"/mnt/%s",filename);
  14145. system("ping 8.8.8.8 &");
  14146. if((access(FilePath,F_OK))!=-1)
  14147. {
  14148. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14149. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14150. system(rmFileCmd);
  14151. }
  14152. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14153. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14154. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14155. systemresult = system(ftpbuf);
  14156. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14157. if(systemresult != 0)
  14158. {
  14159. DEBUG_INFO("http DownLoad error!\n");
  14160. result = FALSE;
  14161. }
  14162. system("pkill ping");
  14163. return result;
  14164. }
  14165. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14166. {
  14167. int result = TRUE;
  14168. char rmFileCmd[100]={0};
  14169. char FilePath[100]={0};
  14170. char ftpbuf[200];
  14171. int systemresult;
  14172. //char temp[100];
  14173. sprintf(FilePath,"/mnt/%s",filename);
  14174. system("ping 8.8.8.8 &");
  14175. if((access(FilePath,F_OK))!=-1)
  14176. {
  14177. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14178. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14179. system(rmFileCmd);
  14180. }
  14181. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14182. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14183. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14184. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14185. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14186. systemresult = system(ftpbuf);
  14187. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14188. if(systemresult != 0)
  14189. {
  14190. printf("wget error!\n");
  14191. result = FALSE;
  14192. }
  14193. system("pkill ping");
  14194. return result;
  14195. }
  14196. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14197. {
  14198. char rmFileCmd[100]={0};
  14199. char FilePath[100]={0};
  14200. char buf[512];
  14201. int systemresult = 0;
  14202. //DEBUG_INFO("filename=%s\n",filename);
  14203. //DEBUG_INFO("url=%s\n",url);
  14204. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14205. if((access(FilePath,F_OK))!=-1)
  14206. {
  14207. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14208. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14209. system(rmFileCmd);
  14210. }
  14211. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14212. if(fp == NULL)
  14213. {
  14214. DEBUG_INFO("log is NULL\n");
  14215. return FALSE;
  14216. }
  14217. else
  14218. {
  14219. fprintf(fp, "%s\n", url);
  14220. fprintf(fp, "%s\n", filename);
  14221. fclose(fp);
  14222. }
  14223. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14224. if(phpFP == NULL)
  14225. {
  14226. DEBUG_INFO("PHP upload fail.\n");
  14227. return FALSE;
  14228. }
  14229. else
  14230. {
  14231. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14232. {
  14233. if(strstr(buf, "result") != NULL)
  14234. {
  14235. sscanf(buf, "result: %d", &systemresult);
  14236. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14237. }
  14238. }
  14239. pclose(phpFP);
  14240. }
  14241. if(systemresult != 1)
  14242. {
  14243. DEBUG_INFO("HTTP upload error!\n");
  14244. return FALSE;
  14245. }
  14246. return TRUE;
  14247. }
  14248. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14249. {
  14250. struct hostent* server;
  14251. char *IPbuffer;
  14252. char ftpbuf[200];
  14253. int systemresult;
  14254. // To retrieve host information
  14255. server = gethostbyname(location);
  14256. // To convert an Internet network
  14257. // address into ASCII string
  14258. IPbuffer = inet_ntoa(*((struct in_addr*)
  14259. server->h_addr_list[0]));
  14260. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14261. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14262. /* format : ftpput -u username -p passwd IP target source*/
  14263. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14264. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14265. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14266. systemresult = system(ftpbuf);
  14267. DEBUG_INFO("systemresult=%d\n",systemresult);
  14268. if(systemresult != 0)
  14269. {
  14270. DEBUG_INFO("ftpput error!\n");
  14271. return FALSE;
  14272. }
  14273. return TRUE;
  14274. }
  14275. int GetOcppServerURL()
  14276. {
  14277. int result = FALSE;
  14278. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14279. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14280. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14281. struct yuarel url;
  14282. char urlStr[512];
  14283. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14284. {
  14285. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14286. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14287. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14288. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14289. if(yuarel_parse(&url, urlStr) != -1)
  14290. {
  14291. sprintf(OcppProtocol, "%s", url.scheme);
  14292. sprintf(OcppHost, "%s", url.host);
  14293. if(url.path == NULL)
  14294. OcppTempPath[0] = '\0';
  14295. else
  14296. {
  14297. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14298. {
  14299. sprintf(OcppTempPath, "%s/", url.path);
  14300. }
  14301. else
  14302. {
  14303. sprintf(OcppTempPath, "%s", url.path);
  14304. }
  14305. }
  14306. if(url.port == 0)
  14307. {
  14308. if(strcmp(OcppProtocol, "wss") == 0)
  14309. OcppPort = 443;
  14310. else
  14311. OcppPort = 80;
  14312. }
  14313. else
  14314. OcppPort = url.port;
  14315. result = TRUE;
  14316. }
  14317. }
  14318. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14319. {
  14320. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14321. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14322. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14323. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14324. if(yuarel_parse(&url, urlStr) != -1)
  14325. {
  14326. sprintf(OcppProtocol, "%s", url.scheme);
  14327. sprintf(OcppHost, "%s", url.host);
  14328. if(url.path == NULL)
  14329. OcppTempPath[0] = '\0';
  14330. else
  14331. sprintf(OcppTempPath, "%s", url.path);
  14332. if(url.port == 0)
  14333. {
  14334. if(strcmp(OcppProtocol, "wss") == 0)
  14335. OcppPort = 443;
  14336. else
  14337. OcppPort = 80;
  14338. }
  14339. else
  14340. OcppPort = url.port;
  14341. result = TRUE;
  14342. }
  14343. }
  14344. else
  14345. {
  14346. strcpy(OcppHost,"");
  14347. }
  14348. return result;
  14349. }
  14350. int GetOcppPath()
  14351. {
  14352. int result = FALSE;
  14353. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14354. {
  14355. if(OcppTempPath == NULL)
  14356. {
  14357. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14358. }
  14359. else
  14360. {
  14361. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14362. }
  14363. result = TRUE;
  14364. goto End;
  14365. }
  14366. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14367. {
  14368. if(OcppTempPath == NULL)
  14369. {
  14370. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14371. }
  14372. else
  14373. {
  14374. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14375. }
  14376. result = TRUE;
  14377. goto End;
  14378. }
  14379. else
  14380. {
  14381. strcpy(OcppPath,"");
  14382. }
  14383. End:
  14384. return result;
  14385. }
  14386. int GetOcppPort()
  14387. {
  14388. return OcppPort;
  14389. }
  14390. int GetOcppConnStatus(void)
  14391. {
  14392. return ShmOCPP16Data->OcppConnStatus;
  14393. }
  14394. void SetOcppConnStatus(uint8_t status)
  14395. {
  14396. ShmOCPP16Data->OcppConnStatus = status;
  14397. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14398. }
  14399. int GetHeartBeatWithNOResponse(void)
  14400. {
  14401. return HeartBeatWithNOResponse;
  14402. }
  14403. void SetHeartBeatWithNOResponse(void)
  14404. {
  14405. HeartBeatWithNOResponse = 0;
  14406. }
  14407. void GetStartTransactionIdTag(int gun_index)
  14408. {
  14409. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14410. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14411. }
  14412. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14413. {
  14414. char ch;
  14415. FILE *fptr1;
  14416. int temptransactionId;
  14417. char str[100]={0};
  14418. temptransactionId = 0;
  14419. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14420. {
  14421. DEBUG_INFO("IdTag is empty.\n");
  14422. return temptransactionId;
  14423. }
  14424. /*------ Read the file ----------------*/
  14425. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14426. if (!fptr1)
  14427. {
  14428. DEBUG_INFO("QueueTransactionId file open error.\n");
  14429. //printf(" File not found or unable to open the input file!!\n");
  14430. return temptransactionId;
  14431. }
  14432. ch=fgetc(fptr1);
  14433. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14434. rewind(fptr1);
  14435. if(ch!=EOF)
  14436. {
  14437. // printf("%c",ch);
  14438. while (fgets(str, 100, fptr1) != NULL)
  14439. {
  14440. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14441. if(str[0]=='\0')
  14442. {
  14443. break;
  14444. }
  14445. char *revbuf[8] = {0}; // Variable store string split
  14446. int num = 0;// Quantity after string split
  14447. DEBUG_INFO("Transaction queue data= %s\n", str);
  14448. splitstring(str,",",revbuf,&num); // String split
  14449. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14450. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14451. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14452. DEBUG_INFO("------------------------------\n");
  14453. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14454. {
  14455. if(isStopTransaction)
  14456. {
  14457. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14458. {
  14459. temptransactionId = atoi(revbuf[2]);
  14460. //break;
  14461. }
  14462. }
  14463. else
  14464. {
  14465. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14466. {
  14467. temptransactionId = atoi(revbuf[2]);
  14468. //break;
  14469. }
  14470. }
  14471. }
  14472. }
  14473. }
  14474. else
  14475. DEBUG_INFO("EOF\n");
  14476. fclose(fptr1);
  14477. /*------- End of reading ---------------*/
  14478. return temptransactionId;
  14479. }
  14480. void SetTransactionIdZero(int transactionId)
  14481. {
  14482. char ch;
  14483. FILE *fptr1, *fptr2;
  14484. int temptransactionId = 0;
  14485. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14486. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14487. if (!fptr1)
  14488. {
  14489. //printf(" File not found or unable to open the input file!!\n");
  14490. return ;
  14491. }
  14492. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14493. if (!fptr2)
  14494. {
  14495. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14496. fclose(fptr1);
  14497. return ;
  14498. }
  14499. ch=fgetc(fptr1);
  14500. rewind(fptr1);
  14501. if(ch!=EOF)
  14502. {
  14503. // copy all contents to the temporary file except the specific line
  14504. while (fgets(str, 100, fptr1) != NULL)
  14505. {
  14506. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14507. if(str[0]=='\0')
  14508. {
  14509. break;
  14510. }
  14511. char *revbuf[8] = {0};
  14512. int num = 0;
  14513. strcpy(strtemp, str);
  14514. splitstring(str,",",revbuf,&num);
  14515. if(revbuf[2][0] != '\0')
  14516. {
  14517. temptransactionId = atoi(revbuf[2]);
  14518. if(transactionId != temptransactionId)
  14519. {
  14520. fprintf(fptr2, "%s\n", strtemp);
  14521. }
  14522. }
  14523. }
  14524. }
  14525. fclose(fptr1);
  14526. fclose(fptr2);
  14527. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14528. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14529. /*------ Read the file ----------------*/
  14530. }
  14531. int InternetDisconnect(void)
  14532. {
  14533. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14534. }
  14535. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14536. void storeTempStopTransaction(int gun_index)
  14537. {
  14538. char guid[37]={0};
  14539. int tempIndex = 0;
  14540. char TempStopTransaction[256];
  14541. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14542. DEBUG_INFO("storeTempStopTransaction...\n");
  14543. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14544. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14545. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14546. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14547. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14548. {
  14549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14550. {
  14551. tempIndex = ((gun_index==2) ? 1: 0);
  14552. }
  14553. else
  14554. {
  14555. tempIndex = gun_index;
  14556. }
  14557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14558. {
  14559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14560. {
  14561. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14562. }
  14563. }// END OF CHAdeMO_QUANTITY
  14564. }
  14565. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14566. {
  14567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14568. {
  14569. tempIndex = ((gun_index==2) ? 1: 0);
  14570. }
  14571. else
  14572. {
  14573. tempIndex = gun_index;
  14574. }
  14575. for (int index = 0; index < CCS_QUANTITY; index++)
  14576. {
  14577. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14578. {
  14579. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14580. }
  14581. }// END OF CCS_QUANTITY
  14582. }
  14583. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14584. {
  14585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14586. {
  14587. tempIndex = ((gun_index==2) ? 1: 0);
  14588. }
  14589. else
  14590. {
  14591. tempIndex = gun_index;
  14592. }
  14593. for (int index = 0; index < GB_QUANTITY; index++)
  14594. {
  14595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14596. {
  14597. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14598. }
  14599. }// END OF GB_QUANTITY
  14600. }
  14601. else if(gunType[gun_index] == GUN_TYPE_DO)
  14602. {
  14603. tempIndex = gun_index;
  14604. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14605. {
  14606. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14607. {
  14608. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14609. }
  14610. }
  14611. }
  14612. else
  14613. {
  14614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14615. {
  14616. tempIndex = 2;
  14617. }
  14618. else
  14619. {
  14620. tempIndex = gun_index;
  14621. }
  14622. for (int index = 0; index < AC_QUANTITY; index++)
  14623. {
  14624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14625. {
  14626. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14627. }
  14628. }// END OF AC_QUANTITY
  14629. }
  14630. //Stop Transaction Time
  14631. struct timeval tmnow;
  14632. struct tm *tm;
  14633. char buf[28];//, usec_buf[6];
  14634. gettimeofday(&tmnow, NULL);
  14635. time_t t;
  14636. t = time(NULL);
  14637. /*UTC time and date*/
  14638. tm = gmtime(&t);
  14639. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14641. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14643. random_uuid(guid);
  14644. /***********************************transactionData******************************************************/
  14645. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14647. //=================================
  14648. //1. Transaction_Begin
  14649. //=================================
  14650. //============================== Energy.Active.Import.Interval ===========================================
  14651. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14652. {
  14653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14656. 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*/]);
  14657. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14658. 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))
  14659. {
  14660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14661. }
  14662. else
  14663. {
  14664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14665. }
  14666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14668. }
  14669. //=================================
  14670. //2. Transaction_End
  14671. //=================================
  14672. //2.1====================================== Current.Import L1 ==============================================
  14673. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14674. {
  14675. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14676. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14677. {
  14678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14679. {
  14680. tempIndex = ((gun_index==2) ? 1: 0);
  14681. }
  14682. else
  14683. {
  14684. tempIndex = gun_index;
  14685. }
  14686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14687. {
  14688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14689. {
  14690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14691. }
  14692. }// End of for CHAdeMO_QUANTITY
  14693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14694. }
  14695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14696. {
  14697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14698. {
  14699. tempIndex = ((gun_index==2) ? 1: 0);
  14700. }
  14701. else
  14702. {
  14703. tempIndex = gun_index;
  14704. }
  14705. for (int index = 0; index < CCS_QUANTITY; index++)
  14706. {
  14707. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14708. {
  14709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14710. }
  14711. }// End of for CCS_QUANTITY
  14712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14713. }
  14714. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14715. {
  14716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14717. {
  14718. tempIndex = ((gun_index==2) ? 1: 0);
  14719. }
  14720. else
  14721. {
  14722. tempIndex = gun_index;
  14723. }
  14724. for (int index = 0; index < GB_QUANTITY; index++)
  14725. {
  14726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14727. {
  14728. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14729. }
  14730. }// End of for GB_QUANTITY
  14731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14732. }
  14733. else if(gunType[gun_index] == GUN_TYPE_DO)
  14734. {
  14735. tempIndex = gun_index;
  14736. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14737. {
  14738. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14739. {
  14740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14741. }
  14742. }
  14743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14744. }
  14745. else
  14746. {
  14747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14748. {
  14749. tempIndex = 2;
  14750. }
  14751. else
  14752. {
  14753. tempIndex = gun_index;
  14754. }
  14755. for (int index = 0; index < AC_QUANTITY; index++)
  14756. {
  14757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14758. {
  14759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14760. }
  14761. }// End of for AC_QUANTITY
  14762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14763. }
  14764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14767. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14770. }
  14771. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14772. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14773. {
  14774. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14775. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14776. {
  14777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14778. {
  14779. tempIndex = ((gun_index==2) ? 1: 0);
  14780. }
  14781. else
  14782. {
  14783. tempIndex = gun_index;
  14784. }
  14785. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14786. {
  14787. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14788. {
  14789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14790. }
  14791. }// END OF CHAdeMO_QUANTITY
  14792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14793. }
  14794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14795. {
  14796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14797. {
  14798. tempIndex = ((gun_index==2) ? 1: 0);
  14799. }
  14800. else
  14801. {
  14802. tempIndex = gun_index;
  14803. }
  14804. for (int index = 0; index < CCS_QUANTITY; index++)
  14805. {
  14806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14807. {
  14808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14809. }
  14810. }// END OF CCS_QUANTITY
  14811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14812. }
  14813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14814. {
  14815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14816. {
  14817. tempIndex = ((gun_index==2) ? 1: 0);
  14818. }
  14819. else
  14820. {
  14821. tempIndex = gun_index;
  14822. }
  14823. for (int index = 0; index < GB_QUANTITY; index++)
  14824. {
  14825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14826. {
  14827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14828. }
  14829. }// END OF GB_QUANTITY
  14830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14831. }
  14832. else if(gunType[gun_index] == GUN_TYPE_DO)
  14833. {
  14834. tempIndex = gun_index;
  14835. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14836. {
  14837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14838. {
  14839. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14840. }
  14841. }
  14842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14843. }
  14844. else
  14845. {
  14846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14847. {
  14848. tempIndex = 2;
  14849. }
  14850. else
  14851. {
  14852. tempIndex = gun_index;
  14853. }
  14854. for (int index = 0; index < AC_QUANTITY; index++)
  14855. {
  14856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14857. {
  14858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14859. }
  14860. }// END OF AC_QUANTITY
  14861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14862. }
  14863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14866. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14869. }
  14870. //2.3====================================== Power.Active.Import =========================================
  14871. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14872. {
  14873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14875. {
  14876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14877. {
  14878. tempIndex = ((gun_index==2) ? 1: 0);
  14879. }
  14880. else
  14881. {
  14882. tempIndex = gun_index;
  14883. }
  14884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14885. {
  14886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14887. {
  14888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14889. }
  14890. } // End for CHAdeMO_QUANTITY
  14891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14892. }
  14893. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14894. {
  14895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14896. {
  14897. tempIndex = ((gun_index==2) ? 1: 0);
  14898. }
  14899. else
  14900. {
  14901. tempIndex = gun_index;
  14902. }
  14903. for (int index = 0; index < CCS_QUANTITY; index++)
  14904. {
  14905. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14906. {
  14907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14908. }
  14909. } // END for CCS_QUANTITY
  14910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14911. }
  14912. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14913. {
  14914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14915. {
  14916. tempIndex = ((gun_index==2) ? 1: 0);
  14917. }
  14918. else
  14919. {
  14920. tempIndex = gun_index;
  14921. }
  14922. for (int index = 0; index < GB_QUANTITY; index++)
  14923. {
  14924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14925. {
  14926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14927. }
  14928. }// END for GB_QUANTITY
  14929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14930. }
  14931. else if(gunType[gun_index] == GUN_TYPE_DO)
  14932. {
  14933. tempIndex = gun_index;
  14934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14935. {
  14936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14937. {
  14938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14939. }
  14940. }
  14941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14942. }
  14943. else
  14944. {
  14945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14946. {
  14947. tempIndex = 2;
  14948. }
  14949. else
  14950. {
  14951. tempIndex = gun_index;
  14952. }
  14953. for (int index = 0; index < AC_QUANTITY; index++)
  14954. {
  14955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14956. {
  14957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14958. }
  14959. } // END for AC_QUANTITY
  14960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14961. }
  14962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14965. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14968. }
  14969. //2.4====================================== Voltage L1 ====================================================
  14970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14971. {
  14972. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14974. {
  14975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14976. {
  14977. tempIndex = ((gun_index==2) ? 1: 0);
  14978. }
  14979. else
  14980. {
  14981. tempIndex = gun_index;
  14982. }
  14983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14984. {
  14985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14986. {
  14987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14988. }
  14989. } // END OF FOR CHAdeMO_QUANTITY
  14990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14991. }
  14992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14993. {
  14994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14995. {
  14996. tempIndex = ((gun_index==2) ? 1: 0);
  14997. }
  14998. else
  14999. {
  15000. tempIndex = gun_index;
  15001. }
  15002. for (int index = 0; index < CCS_QUANTITY; index++)
  15003. {
  15004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15005. {
  15006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15007. }
  15008. } // END OF FOR CCS_QUANTITY
  15009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15010. }
  15011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15012. {
  15013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15014. {
  15015. tempIndex = ((gun_index==2) ? 1: 0);
  15016. }
  15017. else
  15018. {
  15019. tempIndex = gun_index;
  15020. }
  15021. for (int index = 0; index < GB_QUANTITY; index++)
  15022. {
  15023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15024. {
  15025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15026. }
  15027. } // END OF FOR GB_QUANTITY
  15028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15029. }
  15030. else if(gunType[gun_index] == GUN_TYPE_DO)
  15031. {
  15032. tempIndex = gun_index;
  15033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15034. {
  15035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15036. {
  15037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15038. }
  15039. }
  15040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15041. }
  15042. else
  15043. {
  15044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15045. {
  15046. tempIndex = 2;
  15047. }
  15048. else
  15049. {
  15050. tempIndex = gun_index;
  15051. }
  15052. for (int index = 0; index < AC_QUANTITY; index++)
  15053. {
  15054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15055. {
  15056. 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
  15057. }
  15058. } // END OF FOR AC_QUANTITY
  15059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15060. }
  15061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15064. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15067. }
  15068. //2.5============================================== End SoC =========================================================
  15069. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15070. {
  15071. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15072. 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))
  15073. {
  15074. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15075. {
  15076. tempIndex = ((gun_index==2) ? 1: 0);
  15077. }
  15078. else
  15079. {
  15080. tempIndex = gun_index;
  15081. }
  15082. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15083. {
  15084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15085. {
  15086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15087. {
  15088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15089. }
  15090. }
  15091. }
  15092. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15093. {
  15094. for (int index = 0; index < CCS_QUANTITY; index++)
  15095. {
  15096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15097. {
  15098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15099. }
  15100. }
  15101. }
  15102. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15103. {
  15104. for (int index = 0; index < GB_QUANTITY; index++)
  15105. {
  15106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15107. {
  15108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15109. }
  15110. }
  15111. }
  15112. else if(gunType[gun_index] == GUN_TYPE_DO)
  15113. {
  15114. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15115. {
  15116. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15117. {
  15118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15119. }
  15120. }
  15121. }
  15122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15128. } // END FOR DC CASE
  15129. }
  15130. //2.6====================================== Current.Import L2 ==============================================
  15131. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15132. {
  15133. // AC 3 phase L2 current
  15134. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15135. {
  15136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15137. {
  15138. tempIndex = 2;
  15139. }
  15140. else
  15141. {
  15142. tempIndex = gun_index;
  15143. }
  15144. for (int index = 0; index < AC_QUANTITY; index++)
  15145. {
  15146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15147. {
  15148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15149. }
  15150. }// End of for AC_QUANTITY
  15151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15152. }
  15153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15158. }
  15159. //2.7====================================== Current.Import L3 ==============================================
  15160. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15161. {
  15162. // AC 3 phase L3 current
  15163. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15164. {
  15165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15166. {
  15167. tempIndex = 2;
  15168. }
  15169. else
  15170. {
  15171. tempIndex = gun_index;
  15172. }
  15173. for (int index = 0; index < AC_QUANTITY; index++)
  15174. {
  15175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15176. {
  15177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15178. }
  15179. }// End of for AC_QUANTITY
  15180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15181. }
  15182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15187. }
  15188. //2.9====================================== Voltage L2 ====================================================
  15189. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15190. {
  15191. // AC 3 phase L2 volatge
  15192. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15193. {
  15194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15195. {
  15196. tempIndex = 2;
  15197. }
  15198. else
  15199. {
  15200. tempIndex = gun_index;
  15201. }
  15202. for (int index = 0; index < AC_QUANTITY; index++)
  15203. {
  15204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15205. {
  15206. 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
  15207. }
  15208. } // END OF FOR AC_QUANTITY
  15209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15210. }
  15211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15216. }
  15217. //2.10====================================== Voltage L3 ====================================================
  15218. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15219. {
  15220. // AC 3 phase L3 volatge
  15221. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15222. {
  15223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15224. {
  15225. tempIndex = 2;
  15226. }
  15227. else
  15228. {
  15229. tempIndex = gun_index;
  15230. }
  15231. for (int index = 0; index < AC_QUANTITY; index++)
  15232. {
  15233. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15234. {
  15235. 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
  15236. }
  15237. } // END OF FOR AC_QUANTITY
  15238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15239. }
  15240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15245. }
  15246. //====================== Start SoC ================================
  15247. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15248. {
  15249. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15250. 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))
  15251. {
  15252. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15253. {
  15254. tempIndex = ((gun_index==2) ? 1: 0);
  15255. }
  15256. else
  15257. {
  15258. tempIndex = gun_index;
  15259. }
  15260. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15261. {
  15262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15263. {
  15264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15265. {
  15266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15267. }
  15268. }
  15269. }
  15270. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15271. {
  15272. for (int index = 0; index < CCS_QUANTITY; index++)
  15273. {
  15274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15275. {
  15276. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15277. }
  15278. }
  15279. }
  15280. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15281. {
  15282. for (int index = 0; index < GB_QUANTITY; index++)
  15283. {
  15284. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15285. {
  15286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15287. }
  15288. }
  15289. }
  15290. else if(gunType[gun_index] == GUN_TYPE_DO)
  15291. {
  15292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15293. {
  15294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15295. {
  15296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15297. }
  15298. }
  15299. }
  15300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15306. } // END FOR DC CASE
  15307. }
  15308. //======================================== Message create ==============================================
  15309. json_object *StopTransaction = json_object_new_object();
  15310. json_object *transactionDatas = json_object_new_array();
  15311. json_object *sampledValues = json_object_new_array();
  15312. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15313. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15314. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15315. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15316. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15317. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15318. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15319. {
  15320. json_object *transactionData = json_object_new_object();
  15321. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15322. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15323. {
  15324. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15325. {
  15326. json_object *sampledValue = json_object_new_object();
  15327. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15328. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15329. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15330. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15331. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15332. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15333. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15334. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15335. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15336. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15337. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15338. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15339. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15340. json_object_array_add(sampledValues, sampledValue);
  15341. }
  15342. }
  15343. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15344. json_object_array_add(transactionDatas, transactionData);
  15345. }
  15346. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15347. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15348. ,MESSAGE_TYPE_CALL
  15349. ,guid
  15350. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15351. json_object_put(StopTransaction);
  15352. // Check File "TempStopTransaction" Exist
  15353. if((access(TempStopTransaction,F_OK))!=-1)
  15354. {
  15355. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15356. fclose(fopen(TempStopTransaction, "w"));
  15357. }
  15358. else
  15359. {
  15360. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15361. FILE *log = fopen(TempStopTransaction, "w+");
  15362. if(log == NULL)
  15363. {
  15364. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15365. return ;
  15366. }
  15367. else
  15368. {
  15369. fclose(log);
  15370. }
  15371. }
  15372. //Add TempStopTransaction | Update TempStopTransaction
  15373. // open file for writing
  15374. FILE *outfile;
  15375. outfile = fopen (TempStopTransaction, "a");
  15376. //DEBUG_INFO("data = %s\n", queuedata);
  15377. fputs(queuedata, outfile);
  15378. fputs("\n", outfile);
  15379. fclose (outfile);
  15380. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15381. }
  15382. void checkTempStopTransaction(int gun_index)
  15383. {
  15384. FILE *fptr1;
  15385. char ch;
  15386. char str[QUEUE_MESSAGE_LENGTH]={0};
  15387. char guid[37]={0};
  15388. char tempdata[65]={0};
  15389. char connectorStr[2]={0};
  15390. char TempStopTransaction[256];
  15391. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15392. fptr1 = fopen(TempStopTransaction, "r");
  15393. //TempStopTransaction格式: 槍號,StopTransaction封包
  15394. if (!fptr1)
  15395. {
  15396. //printf(" File not found or unable to open the input file!!\n");
  15397. return ;
  15398. }
  15399. ch=fgetc(fptr1);
  15400. //printf(" Now the content of the file %s is : \n",fname);
  15401. rewind(fptr1);
  15402. if(ch!=EOF)
  15403. {
  15404. // copy all contents to the temporary file except the specific line
  15405. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15406. {
  15407. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15408. if(str[0]=='\0')
  15409. {
  15410. break;
  15411. }
  15412. //TempStopTransaction格式: 槍號,StopTransaction封包
  15413. strncpy(connectorStr, str, 1);
  15414. if(atoi(connectorStr) != (gun_index+1))
  15415. {
  15416. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15417. fclose(fptr1);
  15418. return ;
  15419. }
  15420. //random_uuid(guid);
  15421. strncpy(guid, str+6, 36); //copy guid
  15422. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15423. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15424. {
  15425. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15426. }
  15427. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15428. OCPP_insert_transaction_msg(NO, str);
  15429. memset(str,0,ARRAY_SIZE(str));
  15430. }
  15431. }
  15432. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15433. fclose(fptr1);
  15434. remove(TempStopTransaction); // remove the original file
  15435. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15436. }
  15437. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15438. {
  15439. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15440. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15441. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15442. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15443. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15444. }
  15445. int GetWebSocketPingInterval(void)
  15446. {
  15447. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15448. }
  15449. int GetServerSign(void)
  15450. {
  15451. return server_sign;
  15452. }
  15453. uint8_t GetOcppSecurityProfile()
  15454. {
  15455. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15456. }
  15457. void GetOcppChargerBoxId(uint8_t *data)
  15458. {
  15459. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15460. }
  15461. void GetOcppSecurityPassword(uint8_t *data)
  15462. {
  15463. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15464. }
  15465. void SetOcppVersion(uint8_t *version)
  15466. {
  15467. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15468. DEBUG_INFO("ocpp version: %s\n", version);
  15469. if(strstr((char*)version, "ocpp1.6") != NULL)
  15470. {
  15471. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15472. }
  15473. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15474. {
  15475. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15476. system("pkill OcppBackend");
  15477. }
  15478. }
  15479. void SetServerSign(int value)
  15480. {
  15481. server_sign = value;
  15482. }
  15483. int GetBootNotificationInterval(void)
  15484. {
  15485. return BootNotificationInterval;
  15486. }
  15487. int GetInternetConn(void)
  15488. {
  15489. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15490. }
  15491. int GetBackendConnectionTimeout(void)
  15492. {
  15493. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15494. }
  15495. int isConnectorInitMode(int gun_index)
  15496. {
  15497. int tempIndex = 0;
  15498. int result = TRUE;
  15499. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15500. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15501. {
  15502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15503. {
  15504. tempIndex = ((gun_index==2) ? 1: 0);
  15505. }
  15506. else
  15507. {
  15508. tempIndex = gun_index;
  15509. }
  15510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15511. {
  15512. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15513. {
  15514. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15515. } //end of the same index
  15516. }//end of for CHAdeMO_QUANTITY
  15517. }
  15518. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15519. {
  15520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15521. {
  15522. tempIndex = ((gun_index==2) ? 1: 0);
  15523. }
  15524. else
  15525. {
  15526. tempIndex = gun_index;
  15527. }
  15528. for (int index = 0; index < CCS_QUANTITY; index++)
  15529. {
  15530. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15531. {
  15532. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15533. } //end of the same index
  15534. } // end of for CCS_QUANTITY
  15535. }
  15536. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15537. {
  15538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15539. {
  15540. tempIndex = ((gun_index==2) ? 1: 0);
  15541. }
  15542. else
  15543. {
  15544. tempIndex = gun_index;
  15545. }
  15546. for (int index = 0; index < GB_QUANTITY; index++)
  15547. {
  15548. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15549. {
  15550. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15551. } //end of the same index
  15552. } // end of for GB_QUANTITY
  15553. }
  15554. else if(gunType[gun_index] == GUN_TYPE_DO)
  15555. {
  15556. tempIndex = gun_index;
  15557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15558. {
  15559. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15560. {
  15561. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15562. } //end of the same index
  15563. }
  15564. }
  15565. else
  15566. {
  15567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15568. {
  15569. tempIndex = 2;
  15570. }
  15571. else
  15572. {
  15573. tempIndex = gun_index;
  15574. }
  15575. for (int index = 0; index < AC_QUANTITY; index++)
  15576. {
  15577. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15578. {
  15579. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15580. }//end of the same index
  15581. }//end of for AC_QUANTITY
  15582. }
  15583. return result;
  15584. }
  15585. void refreshProcDogTimer()
  15586. {
  15587. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15588. }
  15589. void InitialSystemValue(void)
  15590. {
  15591. int connectorIndex = 0;
  15592. //int valueASCII = 0;
  15593. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15594. gunTotalNumber=0;
  15595. SystemInitial = 0;
  15596. localversion=0;
  15597. BootNotificationInterval = 0;
  15598. authorizeRetryTimes = 0;
  15599. GunStatusInterval = 10;
  15600. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15601. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15602. //Hear Beat
  15603. HeartBeatWithNOResponse = 0;
  15604. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15605. FirstHeartBeat = 0;
  15606. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15607. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15608. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15609. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15610. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15611. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15612. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15613. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15614. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15615. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15616. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15617. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15618. memset(gunType, 0, ARRAY_SIZE(gunType));
  15619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15620. {
  15621. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15622. {
  15623. // DO series
  15624. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15625. {
  15626. SystemInitial = SystemInitial + 1;
  15627. gunTotalNumber = gunTotalNumber + 1;
  15628. gunType[connectorIndex] = GUN_TYPE_DO;
  15629. connectorIndex = connectorIndex + 1;
  15630. }
  15631. }
  15632. else
  15633. {
  15634. // DM, DW, DS series
  15635. //check connector / socket type (index: 8, 9, 10)
  15636. for(int index=7; index <10 ; index++)
  15637. {
  15638. if(index != 8)
  15639. {
  15640. // DC Connector
  15641. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15642. {
  15643. SystemInitial = SystemInitial + 1;
  15644. gunTotalNumber = gunTotalNumber + 1;
  15645. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15646. connectorIndex = connectorIndex + 1;
  15647. }
  15648. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15649. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15650. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15651. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15652. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15653. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15654. {
  15655. SystemInitial = SystemInitial + 1;
  15656. gunTotalNumber = gunTotalNumber + 1;
  15657. gunType[connectorIndex] = GUN_TYPE_CCS;
  15658. connectorIndex = connectorIndex + 1;
  15659. }
  15660. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15661. {
  15662. SystemInitial = SystemInitial + 1;
  15663. gunTotalNumber = gunTotalNumber + 1;
  15664. gunType[connectorIndex] = GUN_TYPE_GBT;
  15665. connectorIndex = connectorIndex + 1;
  15666. }
  15667. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15668. {
  15669. SystemInitial = SystemInitial + 1;
  15670. gunTotalNumber = gunTotalNumber + 1;
  15671. gunType[connectorIndex] = GUN_TYPE_DO;
  15672. connectorIndex = connectorIndex + 1;
  15673. }
  15674. }
  15675. else
  15676. {
  15677. // AC Connector
  15678. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15679. {
  15680. SystemInitial = SystemInitial + 1;
  15681. gunTotalNumber = gunTotalNumber + 1;
  15682. gunType[connectorIndex] = GUN_TYPE_AC;
  15683. connectorIndex = connectorIndex + 1;
  15684. }
  15685. }
  15686. }
  15687. }
  15688. //DEBUG_INFO("DC ...\n");
  15689. }
  15690. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15691. {
  15692. //check connector / socket type (index: 8, 9, 10)
  15693. for(int index=7; index <10 ; index++)
  15694. {
  15695. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15696. {
  15697. SystemInitial = SystemInitial + 1;
  15698. gunTotalNumber = gunTotalNumber + 1;
  15699. gunType[connectorIndex] = GUN_TYPE_AC;
  15700. connectorIndex = connectorIndex + 1;
  15701. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15702. }
  15703. }
  15704. }
  15705. //Status && ConnectorPlugIn Setting
  15706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15707. {
  15708. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15709. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15710. }
  15711. for (int index = 0; index < CCS_QUANTITY; index++)
  15712. {
  15713. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15714. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15715. }
  15716. for (int index = 0; index < GB_QUANTITY; index++)
  15717. {
  15718. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15719. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15720. }
  15721. for (int index = 0; index < AC_QUANTITY; index++)
  15722. {
  15723. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15724. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15725. }
  15726. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15727. {
  15728. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15729. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15730. }
  15731. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15732. {
  15733. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15734. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15735. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15736. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15737. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15738. }
  15739. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15740. clientTime.Heartbeat=time((time_t*)NULL);
  15741. sleep(1);
  15742. }
  15743. void LWS_Send(char *str)
  15744. {
  15745. //=====================================================
  15746. // Check InternetConn 0: disconnected, 1: connected
  15747. //====================================================
  15748. if(GetOcppConnStatus() == 0)
  15749. {
  15750. DEBUG_INFO("offline now !!!\n");
  15751. return;
  15752. }
  15753. // Only disable isWebsocketSendable operation initiated by charger
  15754. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15755. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15756. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15757. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15758. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15759. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15760. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15761. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15762. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15763. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15764. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15765. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15766. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15767. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15768. {
  15769. isWebsocketSendable = 0;
  15770. }
  15771. pthread_mutex_lock(&lock_send);
  15772. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15773. sprintf((char *)SendBuffer, "%s", str);
  15774. SendBufLen = strlen(str);
  15775. pthread_mutex_unlock(&lock_send);
  15776. lws_callback_on_writable(wsi_client);
  15777. //lws_service(context, 0);
  15778. //sleep(1);
  15779. }
  15780. void LWS_SendNow(char *str)
  15781. {
  15782. //=====================================================
  15783. // Check InternetConn 0: disconnected, 1: connected
  15784. //====================================================
  15785. if(GetOcppConnStatus() == 0)
  15786. {
  15787. DEBUG_INFO("offline now !!!\n");
  15788. return;
  15789. }
  15790. // Only disable isWebsocketSendable operation initiated by charger
  15791. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15792. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15793. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15794. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15795. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15796. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15797. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15798. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15799. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15800. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15801. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15802. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15803. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15804. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15805. {
  15806. isWebsocketSendable = 0;
  15807. }
  15808. pthread_mutex_lock(&lock_send);
  15809. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15810. sprintf((char *)SendBuffer, "%s", str);
  15811. SendBufLen = strlen(str);
  15812. pthread_mutex_unlock(&lock_send);
  15813. lws_callback_on_writable(wsi_client);
  15814. lws_service(context, 0);
  15815. //sleep(1);
  15816. }